Posts

Reflection in java

Reflection:-         Reflection is the way to recognize any class at the runtime even if their name is found at runtime. If at the development time the class name is not known by the developer then we cann't use that class without reflection.        The use of class can be load that class, to create the object of that class, invocation of the methods. By Reflection the details of the class can also be obtained such as list of their methods, list of constructors, list of the fields, name of parent class and list of implemented interfaces. Note:- Reflection is meta data of class.         According to the Reflection each and every class and members of that class represented by the objects these objects are known as the reflected object or meta object.         Through the reflection in any java program we can obtained the meta data. java.lang.Class:-                 This is a class, In the heap area a  separate object of Class class always be created for the each loaded cla

constructor and constructor myths

Constructor :-               In java programming language all the no static variables that are defined in the class are known as instance variable of the class and in java every thing is represented as an object so that when a user creates a class want to use the functions and properties of that class then that person should have to creates a object of that class. Now the constructor must be used to create the object of the class. The main functioning of the constructor is to provide the Reference ID of the constructor generated by JVM. Some Basic Rules to declare the constructor:- 1. constructor name should be same as the class name. 2. constructor return type does not specified by the programmer. Syntax with example:-     class ABC      {             ABC()             {             }      } constructor type:- 1. default 2. parameterized 1. default:-            constructor with the empty parameter list is called a default constructor. 2. parameterized:-          

Inter-Thread communication

Inter-Thread communication :-                            -synchronized method/block will provides an unordered mutual exclusivity b/w the thread to access the objects. Thats means if one thread start the execution of synchronized method then their is no certain time for the completion of method, upto that time the other thread have to wait. To overcome this problem we use the concept of inter Thread communication.                                     In case of inter Thread communication the threads are capable to access the synchronized objects in the mutually exclusive manner in the ordered way that means any thread can release the lock during the execution of the synchronized method or block and moved into the waiting state.         "java.lang.Object class" this class provides the following methods for inter thread communication- 1. wait()                                        2. notify()                                           3.notifyAll() (1) wait()- always be

serialization

Image
Serialization :-               -This is the process to write the objects into the stream in such a way that further the objects can be reconstructed.                 Object serialization can be used in the networking where the one object will be passed across the network onto the different JVM. Through the serialization object can also be written into any file.   During the serialization along with the data the meta data also will be stored in the stream such as class name,field name,field type etc.                    Note:- if after the serialization the .class file of the class is changed than process of deserialization will not work.                   Note:- During the serialization the cloning of any singleton object is possible. java.io.Serializable Interface :-  By default the objects of the java classes are not serializable that means we cann't write those objects onto the stream.                             Only the objects of the serializable classes tha

define public static void main(String[] args)?

The entry point for the execution in all programming language is the main(). so the question is that why we prefix out "main()" by "public" and "static"?                                 -Answer is that firstly it is the prototype and jvm only search for the main() which is public and static and have the String[] argument.                                  -Another reason of it is that when we create our programs in any package (if we don't declare any package in our program then it should be consider as in the default package by jvm) then the only public methods can only be accessed by the caller (in the case of main() caller is jvm) if the caller is at the another package then the program (program and caller are in the different locations), jvm is not a single unit it comprises of many classes of jdk so its location is not in a package so that we have to set our main() as public so that jvm can access it, if our program in any package in our

define System.out.println()?

In the System.out.println()           -System is a class that is define in the java.lang package which is by default imported in our program.          -out, is the object of PrintStream class and it is declared as static in the System class.          -println(), is the function of PrintStream class.       Code to demonstrate how the "out" object associate with System class :- class System1 {              static PrintStream1 out;              //starting of static block              static                                                           {                       out=new PrintSream1();              } } class PrintStream1 {          public void printline()          {                      //code of the printline() by java developers........          }  } class <userdefine> {         public static void main(String[] args)         {                   System1.out1.printline();         } } This is called class level association, we assoc

JVM architechture

Image
Architecture of the JVM (java virtual machine) ​  JVM is made up of following modules:-               1:- class loader               2:- byte code verifier               3:- memory area               4:- execution engine 1:- class loader the class loader loads the byte code(.class file) from the hard disk to the RAM and it is accomplish its task by three ways that are following:-              1:- Bootstrap loader              2:- Extended class loader              3:- System class loader/class path                                 1:- Bootstrap loader *I am use linux mint so the below path is for linux mint only.  the bootstrap loader loads the file from,                                 /usr/lib/jvm/java-ibm-x86_64-80   /jre/lib/rt.jar (for execution of the java program the jvm use the public jre if it is exiest. if is not present the jvm use the private jre which is in the JDK package.) the path of the private jre is:- /usr/lib/jvm/java-8-o