Posts

Showing posts from 2017

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:-               ...

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:...

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 ...

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...

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 locati...

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 Prin...

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 bo...

Input/Output Stream in java

Image
input/output are the two major processes in any application development. java follows the stream based input/output. A stream is a channel through which data will be transmitted. example:- Advantages of stream based I/O over Normal I/O:- Abstraction:-  Streams hides the internal complexity of I/O. Flexibility:- Streams provides a flexibility to be used in the program according to the requirement. Efficiency:-  Streams also performs the additional operations onto the data so stream based I/O always be effective over the normal I/O.                   Their are two types of streams in java- 1:- Byte Stream:- it follows the 8 bit sequence. 2:- Character Stream:- it follows the 16 bit sequence.        java.io package provides classes known as Stream classes whose objects are considered as the stream in the java applications.         InputStream & OutputStr...