Skip to main content

Posts

Showing posts with the label JAVA

What is version checking in Hibernate ?

Version checking used in hibernate when more then one thread trying to access same data. For example : User A edit the row of the TABLE for update ( In the User Interface changing data This is user thinking time) and in the same time User B edit the same record for update and click the update. Then User A click the Update and update done. Change made by user B is gone. In hibernate you can prevent slate object updation using version checking. Check the version of the row when you are updating the row. Get the version of the row when you are fetching the row of the TABLE for update. On the time of updation just fetch the version number and match with your version number (on the time of fetching).

JDK 11 have nasty surprise? It has fast, scalable and easy to tune new garbage collector i.e. ZGC?

Java 11 is ready with new exciting features and it have nasty surprises as well, It have a newly designed Garbage Collector which is fast, scalable and easy to tune. Let's find out what is it. It is one of the most exciting feature in JDK 11. This brand new Garbage Collector, ZGC, which is being developed by Oracle that promises very low pause times on multi-terabyte heaps. JVM tuning will not be a tedious job because it is easy to tune as well. It is an experimental feature in JDK 11 later on it will available as full feature. It is scalable low latency Garbage Collector which means  it will have pause time less than 10ms no matter how big your heap is.  it is scalable, it can handle multi-terabyte heaps without affecting the performance.  Key features of ZGC are : 1. Concurrent  Marking Relocation/compaction Relocation set selection reference processing  StringTable cleaning 2. Single Generation 3. Load barriers 4. Colored pointers 5. Region based : heap ...

Why LinkedList (Java) sucks? Performance comparison with ArrayList? When to use ArrayList over LinkedList?

Collection is the most used concept in Java after String, in collection framework we are mostly rely on ArrayList and LinkedList for keeping the objects in sequential form. these two are most used implementations of List interface but LinkedList always sucks in performance although LinkedList have some advantages as well. ArrayList is what you want. LinkedList is almost always a (performance) bug. Why LinkedList sucks: It uses lots of small memory objects internally to keep connecting the objects, and therefore impacts performance across the process. Lots of small objects are bad for cache-locality. Any indexed operation requires a traversal, i.e. has O(n) performance. This is not obvious in the source code, leading to algorithms O(n) slower than if ArrayList was used. Getting good performance is tricky. Even when big-O performance is the same as ArrayList, it is probably going to be significantly slower anyway. It's jarring to see LinkedList in source because it is probably the wr...

What is cooking at Oracle for Java 11? Java 11 will include more than just features LTS and more?

Oracle’s move towards a faster release cycle means that more features and abilities are coming our way, faster than ever before.The Java 11 launch date is scheduled for September 2018, and the repository is currently open for bug fixes, as well as propositions for more JDK Enhancement Proposals (JEP) to be added to the upcoming version.  Local-Variable Syntax for Lambda Parameters (JEP 323) Epsilon: An Arbitrarily Low-Overhead Garbage Collector (JEP 318) Dynamic Class-File Constants (JEP 309) Remove the Java EE and CORBA Modules (JEP 320) Java 11 will include more than just features While this feature list is still not final and we’re expecting more JEPs to be added in the following months, Java 11 will have a little something extra. One of the main highlights that will come with Java 11, is long-term support of the platform. To understand what it means, let’s take a trip back to September 2017, when According to Oracle Java SE Support Roadmap Oracle is moving to long-term support...

Java 10 Unique Features and What's new Java 10?

Java 10 was released in March 2018, It comes just six months after its predecessor i.e. Java 9 and brings an enhanced Local Variable Type Inference, garbage collection and compilation and other exciting features. It was an enhancement to the Java 9 and its a new polished version of Java 9 as It was not a major update but still it include the important features and modifications such as Native-Header Generation Tool (aka javah) is removed. Java 8 to Java 9 it took 3 years and after 6 months of Java 9 Oracle released the Java 10. Java community announced its shift to a new 6 month cadence for Java. It moved to a Long Term Support (LTS) model for Oracle Java SE products. What does LTS mean? LTS version of the products will offer premier and sustained support from Oracle and it will be targeted every 3 years. Java 10 features 1. Local-Variable Type Inference :  Local-Variable Type Inference is the biggest new feature in Java 10. It adds type inference to declarations of local variables...

Why we use String as key in Hashmap? or Is it good to have String as key in Hashmap?

String is one of the most used classes in any programming language. We know that String is immutable and final in java and java runtime maintains a String pool that makes it a special class. String is immutable, its hashcode is cached at the time of creation and it doesn’t need to be calculated again. This makes it a great candidate for key in a Map and it’s processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys. Note : HashMap uses hashCode() and equals() methods on keys for get and put operations. So HashMap key object should provide good implementation of these methods. This is the reason immutable classes are better suitable for keys, Let's say, We have some data of the students and we need to keep that data for further processing in a Hashmap. HashMap<String, String> students = new HashMap<>(); students.put("S1", "Student1"); students.put("S2", "Student2"); students.p...

Java Versions and their release dates

Java Versions and release dates: James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time. The language was initially called Oak as an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from a Java coffee beans Java is also an island. It was designed based C/C++-style syntax for easy understanding as C/C++ was very much popular at that time. Sun Microsystems released the first public implementation as Java 1.0 in 1996. They called as "Write Once, Run Anywhere" (WORA), providing no-cost run-times on popular platforms. JDK 1.0 (January 23, 1996) JDK 1.1 (February 19, 1997) J2SE 1.2 (December 8, 1998) J2SE 1.3 (May 8, 2000) J2SE 1.4 (February 6, 2002) J2SE 5.0 (September 30, 2004) Java SE 6 (December 11, 2006) Java SE 7 (July 28, 201...

Java : ClassNotFoundException vs NoClassDefFoundError

ClassNotFoundException is an exception that occurs when you try to load a class at run time using Class.forName() or loadClass() methods and mentioned classes are not found in the classpath. NoClassDefFoundError is an error that occurs when a particular class is present at compile time, but was missing at run time. The difference from the Java API Specifications is as follows. For ClassNotFoundException : Thrown when an application tries to load in a class through its string name using: The forName method in class Class. The findSystemClass method in class ClassLoader. The loadClass method in class ClassLoader. but no definition for the class with the specified name could be found. For NoClassDefFoundError : Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found. The searched-fo...