This example shows when the java.lang.IllegalAccessException is thrown in your application. When an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, if that method is not accessible to your application (probably the modifier is private or not accessible one), then your application will …
Java Lang
NullPointerException in Java
One of the most common and nightmare for the Java programmers are getting the NullPointerException while running the Java application. This exception is defined at the “java.lang” package and the purpose of the exception is to detect if an object is used without any content. Here you must understand the difference between Reference and Object. …
How To Get JVM Start Time And Date
This example shows how to get the start time and date for the current execution environment of Java Virtual Machine (JVM). RuntimeMXBean in the Java lang package helps in getting the details of the JVM start time. By invoking the method getStartTime() in RuntimeMXBean class, it returns the time in long number which can be …
java.lang.ArrayIndexOutOfBoundsException
One of the feature in the Java programming language is usage of arrays. The advantage of using arrays is to store the large number of values and retrieve them using the index values. Each array is treated as an object itself. Each array has the fixed number of elements and it will not be changed …
java.lang.NoSuchMethodError
NoSuchMethodError is thrown when a Java class trying to invoke a method from another class which is not exist. Typically, this error has to be caught at the compile time. However, this error also thrown at run time when class has incompatibly changed. This error is sub class of java.lang.IncompatibleClassChangeError. This class inherited from the …
Java equals() and hashcode()
This tutorial explains the equals() and hashcode() method in simple terms. It is one of the confusing questions on the Java developer’s mind. The common questions asked about these methods are: What is equals() method and why should I override that in our classes? What is hashcode() method? Why should I always override hashcode() when …
Java Math.random() Example
In Java, there is a method random() in the Math class, which returns a double value between 0.0 and 1.0. Note that the default random numbers are always generated in between 0 and 1. If you want to get the specific range of values, the you have to multiple the retruned value with the magnitue …
Comparable vs Comparator Interface in Java
This is an interesting topic in Java and can be confusing to many Java developers. So I plan to give some common examples to illustrate the differences. Going by the topic name, these things are obvious to us: Both comparator and comparable are Java interfaces. Any class, which needs to use these interfaces, has to …