Posts

Showing posts with the label JAVA SE

Java 8

https://howtodoinjava.com/java-8-tutorial/

Java Collections

https://howtodoinjava.com/java-collections/ https://howtodoinjava.com/interview-questions/useful-java-collection-interview-questions/

extends Thread vs implements Runnable

Thread   Class T1 extends Thread {     public void run(){...}   } Run with:   new T1().start(); Runnable   Class R2 implements Runnable{     public void run(){...}   } Run with:   Thread t2 = new Thread(R2);   t2.start(); R1 still allows you to extend a class (and thus, the behaviour), which is not possible with T1. Further, multiple threads of T2 shares the same runnable instance, where multiple T1 creating unique instances. If you don't need extention behaviour, use rather Runnable implementation.

CountDownLatch

The main thread initializes a CountDownLatch, e.g.:     CountDownLatch countDownLatch = new CountDownLatch(3); It passes countDownLatch to n (in this example 3) sub-threads, for instance via constructor. Finally, the main thread waits for the execution of the sub threads:     countDownLatch.await(); Once ready, every thread finally calls     countDownLatch.countDown(); Every countDown() call decrements the initial number, and the main thread finally will resume with the operations defined after the wait() statement. See more here: https://howtodoinjava.com/java/multi-threading/when-to-use-countdownlatch-java-concurrency-example-tutorial/

Back to basics: Creating Custom Annotations

How to create custom annotations, and how to take advantage of them by using Java's Reflection API: https://www.baeldung.com/java-custom-annotation

Volatile explained with Singleton example

"Volatile keyword in Java is used as an indicator to Java compiler and Thread that do not cache value of this variable and always read it from main memory ... A volatile variable can be used as an alternative way of achieving synchronization in Java in some cases, like Visibility. with volatile variable, it's guaranteed that all reader thread will see updated value of the volatile variable once write operation completed, without volatile keyword different reader thread may see different values ..." Moreo on Violate keyword & how to use it here:  https://javarevisited.blogspot.com/2011/06/volatile-keyword-java-example-tutorial.html

Java 9 - What is new

PID / Process Information Private Methods in Interfaces JShell  & more: https://dzone.com/articles/java-9-besides-modules

Summary of Interface Enhancements

Summary of Interface Enhancements Constants (until Java 1.7) Method signatures (until Java 1.7) Nested types (until Java 1.7) Default methods (since 1.8) Static methods (since 1.8) Private methods (since 1.9) Private static methods (since 1.9)

Java Type Inference

"Type inference is a Java compiler's ability to look at each method invocation and corresponding declaration to determine the type argument (or arguments) that make the invocation applicable. The inference algorithm determines the types of the arguments and ..." http://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html

Did you know that "int i = 1_000;" is a valid statement?

10 JDK 7 Features to Revisit, Before You Welcome Java 8 Read more:  http://javarevisited.blogspot.de/2014/04/10-jdk-7-features-to-revisit-before-you.html

5 Features In Java 8 That WILL Change How You Code

"Java 8 is packed full of some really exciting features at both the JVM and language level. While some of the features initially envisioned for this release got scoped out or pushed out to release 9, there are literally dozens of new features. Many of the new additions are under-the-hood improvements either at the compiler, JVM or help-system level. As such ..." http://www.takipiblog.com/2014/03/18/5-features-in-java-8-that-will-change-how-you-code/

Interfaces in Java 8!

"Before Java 8, interfaces could only contain abstract methods and constants. However, starting with Java 8, interfaces will be permitted to contain defensive methods. "We finally bit the bullet and addressed the problem of interface evolution,"Geotz said. "We added a concept called default methods. This allows you to add a method to an interface in a compatible way, as long as you provide a default implementation." This is, without a doubt, the big language change that makes Java aficionados the most uncomfortable. While everyone understands the motivation behind Lambda, such a drastic change to a fundamental language feature makes it seem as though these new Java 8 features are being shoehorned in, forced to fit in a way that isn't natural or elegant." See the entire article at http://www.theserverside.com/news/2240206156/Lambda-Java-8-interface-evolution-and-laws-of-unintended-consequences

Java Generics

... Despite the wealth of information out there, sometimes it seems to me that many developers still don't understand the meaning and the implications of Java generics ... http://www.javacodegeeks.com/2011/04/java-generics-quick-tutorial.html

Low-level conversion of e.g. "ISO-8859-1" to "UTF-8"

String utf8Title = new String(getTitle().getBytes("ISO-8859-1"), "UTF-8");

Mail API - SEND MAIL‏

package demo.util; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import org.apache.log4j.Logger; import demo.CRM; public class Mail {     static Logger logger = Logger.getLogger(Mail.class);     /**      *      * @param smtpHost      * @param smtpPort      * @param from      * @param to      * @param subject      * @param content      * @throws AddressException      * @throws MessagingException      */     public static void send(String smtpHost, String smtpPort, String from, String to, String subject,   ...