Java Iterable and Iterator Interface

java-thumbnail

One of the most widely used and most common API in Java is iterator for the collections. If we have the list of objects in an array or list objects, the iterator is very useful for iterating the  objects without much extra coding. Here we discuss about the comparison of two key interfaces, Iterable and […]

Get Modifiers of an Object using Reflection

java-thumbnail

This example demonstrates how to get the modifiers used in a class using the reflection API. One can use the getModifiers() method in the Class object to know about each modifier used in that specific class. Call isAbstract(int mod), isFinal(int mod), isInterface(int mod), isNative(int mod), isPrivate(int mod), isProtected(int mod), isPublic(int mod) and isStatic(int mod) methods to […]

Get Package Name using Reflection

java-thumbnail

This example demonstrates how to get the package name using the Reflection API. With reflection we can get the details of any class or object and its methods, fields, etc. This is useful when we are doing the dynamic creation of the classes and invoking at run time. Lets look at the example program to […]

Get Methods using Reflection

java-thumbnail

In this example we shall explain with a simple example to get the methods of a class using the reflection. You can list the public and private methods of an object using the following steps: Get the Class instance of the class which you want to list the methods. In this example get the Class […]

Get Fields using Reflection

java-thumbnail

In this example we shall explain with a simple example to get the fields of a class using the reflection. You can list the public and private fields of an object using the following steps: Get the Class instance of the class which you want to list the fields. In this example get the Class […]

Invoke Method using Reflection API

java-thumbnail

This example highlights the way how to invoke a method using the reflection API. As we are aware that we can dynamically invoke a method in another class by using the reflection classes. Note that using reflection is more expensive in terms of performance. This programming practice is used only in the certain requirements where […]

Fibonacci Number Generation in Java

java-thumbnail

This simple example explains how to write a Java program to print the fibonacci numbers. Fibonacci numbers are sequence of numbers where one number is the sum of preceding two numbers. An example for the fibonacci is “0, 1, 1, 2, 3, 5, 8, 13, 21, 34, …”. If you look at the series, every […]

Prime Number Generation in Java

java-thumbnail

This simple example demonstrates how to get the prime numbers using Java program for the given range. What is prime number?. A number which is divided only by 1 and itself is known as the prime number. If you take an example, 7 is a prime number, because it can be divided by only itself(7) […]

java.lang.ArrayIndexOutOfBoundsException

java-thumbnail

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

java-thumbnail

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 […]