Posts

Showing posts from July, 2014

Serialization and deserialization in java with examples

Serialization and Deserialization is one of the commonly used concept in java to store object in any other location like, File, DB, Cloud,...etc and vice versa is called as Deserialization. In other words, Java provides a mechanism called Serialization to persist Java object into a file, database, network, process or any other system. Serialization makes object into an ordered or Serialized stream of bytes. That includes the object data as well as object type of data stored. Before moving further in Serialization and Deserialization in java, have a look at Input and Output streams. If you need to make your object as Serialized, the object class should be implemented from Serializable interface. Serializable is one of the interface called as marker interface in java. Marker interface is nothing but an interface which has no methods or fields to implement but it will do some functionality. Serializable interface is part of java.io package in java. ObjectOutputStream and ObjectInputS...

arrays in java with example

The main definition of an array is, an array represents the group of elements.  In Java, array plays a key role. The main purpose of the array is to hold a fixed set of elements. Why I said fixed set is, while creating array we have to define the size of the array. So, that array can hold only that no of elements in it. For example, when we have created main() method in our program, you can observe there is a String[] array. Otherwise, JVM can't understand and it will not consider that main method as starting point of the application. How to create an array in Java? The below are two different ways of creating an array in java. In the first way, you have to pass the elements between the braces {}.  int [] ar = {}; or int [] ar = new int [ 10 ]; As I have already mentioned, array represents the group of elements. Those elements should be of same type. Otherwise compiler will not allow to add. But, there is a possibility of casting. For example, I hav...

Reading properties from a file with example

Reading properties from file, find list of files in a directory and find a year is leap year or not. These all example present in this post. Read properties from file:           Reading properties from properties(.properties) file is the major requirement in real-time applications. Here, we will come to know, how to read properties from file with an example explanation.           We will create one .properties file with the name of javaex.properties under src package and we will declare roleId's as key-value pairs. Like below, application.id.roleIds = ' 53 ',' 121 ',' 63 ',' 46 ',' 43 ',' 71 ',' 45 ',' 36 ',' 64 '           Here, application.id.roleIds is the Key to get the values, which  we will use in java class. The below program explains you how to read data from the properties file by using the key which you have d...