Posts

Showing posts with the label CoreJava

Cloning in java with example

Cloning: Cloning is a technology to obtain exact copy of a plant, a bird an animal or a human being. This cloning technology available now. Cloning in java: Obtaining the exact copy of an existing object is called as cloning. There are two types of cloning           · Shallow Cloning: In this type of cloning any modifications to the original object will also modify the cloned object.           · Deep Cloning: In this type of cloning any modifications in the original object will not modify the cloned object.                     Deep cloning or copy can be achieved through serialization. This may be fast to code but will have performance implications. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 package com . javatbrains . cloning ; class Employee implements Cloneable { int id ; String name ; Employee ( int id , String name ) { this . id = id ;

How to generate excel sheet by using java

To generate an excel sheet by using java, we need to download the jxl.jar. This will help us to generate xls file by using predefined classes. For downloading jxl jar click here . This link will point to Maven repository from there you need to click on download button for downloading jar file. When jxl jar downloading will get complete, add the jar to project class path by following these steps. Right click on project --> goto properties --> select java build path --> select libraries --> click on add external jars button to browse downloaded jar path --> select jar and click on open button --> Ok. This jar file will provide few classes to design the excel sheet.  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 packag

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

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 declared in properties file. package com.javatbrains.