Java Arrays Example

java-thumbnail

An Array is a data structure which represents a group of elements of same data type. It can store a group of elements either it may be variable or objects. We can define the length of the array, when the array is created. We cannot store some integer values and some string values together in […]

Java Serializable Interface

java-thumbnail

Serialization is a process by which data structures or objects are translated into a format or a sequence of bytes (often called marshaling), which can later be unpacked (often called unmarshalling) in the same/different environment. Since the two environments might be completely different, a common method of serialization and then later deserialization is required. Questions: […]

Continue Statement in Java

java-thumbnail

This example shows how to use the continue statement in Java programming. In my previous example I have explained about the break statement which is useful for termination the look and come out of it. However, in certain cases one might want to terminate only the current iteration and skip to the next iteration. In that […]

Break Statement in Java

java-thumbnail

This example shows how to use the break statement in Java programming. Break itself a keyword that can be used within a block like for, while, do-while or switch statements. The significance of the break statement is to terminate the current loop and exit the block. It is mostly useful in the loops while we […]

How To Get Classpath in Java

java-thumbnail

This example demonstrates how to get the classpath string using the Java program. It is simple that you just need to use the System.getProperty() method with the classpath variable name which will return the classpath string. Lets look at the example. Output This is the simple example to get the classpath configuration in your system […]

How To Find A File In Classpath

java-thumbnail

This example program demonstrates how to find a file in the classpath. The simple approach is to get the classpath string using the System.getProperty() method which returns the complete string value of the classpath. Then you can split the values using the stringtokenizer and search eacy token against the file name. Lets look at the […]

How To Check Where The Class Loaded From

java-thumbnail

This example shows to check the path of the class loaded from. This utility would be helpful in certain cases if you want to check the class loading path when there is confusion over multiple libraries exist in the different path. To do that, the below example use the following steps: Get the Class for […]

Get Methods Return Type using Reflection

java-thumbnail

In this example we shall explain with a simple example to get the methods of a class using the reflection and get the return type. 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 […]

Get Constructors using Reflection

java-thumbnail

This example shows how to get the constructors in a class and invoke it. Note that java.lang.reflect.Constructor defines a method newInstance() which is used for creating instance for an object. Before that you have to get the list of constructors in a class. We have two methods defined in the Class class. If we use […]

Get Super Class Name using Reflection

java-thumbnail

With this example, we shall show you how to get the super class of an object and use it using the reflection technique. Lets look at the following example and the steps provided below to understand the program. I have created Employee super class and its sub class Manager Created instance of Manager and assigned […]