Posts

Showing posts from September, 2013

Job of new operator in java

What does new operator do? new operator in java is used for creating the object of the class. new operator instantiates the class and allocates memory to the object . As an object is instantiated all non-static member of the class are activated and ready to be used. It is the well known working of new operator, I want to tell you what happens in the memory when an object is created in the memory i.e. job of new operator or responsibilities of new operator in java programming. We will discuss step by step jobs of new operator. First i want to tell you how we create an object? class_name <reference variable> = new class_name(); Here,  <reference variable> is the variable of specified class and it stores the hashcode(address of object where it has been created) returned by the new operator. hashcode is in the form of hexadecimal code. Now we will discuss job of new operator. If .class file is not loaded  then to load the .class file from hard disk...

Internal Mechanism of public static void main(String args[])

Internal Mechanism of public static void main(String args[]) in java programming: Java: public static void main(String args[]): Let us explaining public static void main(String args[]). Java is a platform independent language in which main() method is declared as public as well as static and its return type is void. In main method a String type array parameter is passed. Let us take a look why do we write main() method as public static void main(String args[]). We will explain each term step by step as below- Why do we use public keyword: public is an access specifier in java programming i.e. it defines the scope and visibility of class members. main() is also a class member when we declare main() method as public it can be called by JVM . main() is a method which is called by JVM automatically. There are two environment in java programming one is JDK environment and another is JVM environment. If JVM calls a method written in JDK environment then that method need to be declared ...

How to create an Object in Java

How to create an Object in Java : Creating Object is very important step to execute our java program successfully. As we know we can call all non-static members only after creating object of the class so must need to create an object. We can execute non-static block without creating object below java5 version. In this post we will know how to create an object in java. Object is an instance variable of the class and it can be created by using "new" keyword. "new" keyword is responsible for allocating memory to the object. Code to create an object is as follows- Example- new Java_program(); new Java_example(); new Test(); In above example we are creating an object by using new keyword. "new" kyword is allocating memory to the object anf returning reference of the object. This reference is needed to access the non-static members of the class so we have to store in a variable called a reference variable. Example- Java_program ob= new Java_progra...

Internals Of Logical AND Logical OR in Java

Image
Logical AND(1st condition && 2nd condition)- Internals of Logical AND and Logical OR:Lets describe What is the internal mechanism of Logical AND and Logical OR.Logical AND is a Logical operator in java which returns a boolean value. If first condition false then in Logical AND, pointer does not check second condition. For second condition we use Bitwise AND.   Logical OR(First condition || 2nd condition)- Logical OR is also a Logical Opeartor which returns a boolean value. In Logical OR If first condition is true then pointer does not check 2nd condition . For check 2nd condition we use Bitwise OR. For example-           int x= 10 && 20;  int y= 10 & 20; Both operator Bitwise AND and Logical AND use with condition  but Logical AND does not use without condition. Bitwise AND use with and Without condition.

Internals Of Java Compiler

Internal mechanism of Compiler in java:Let us describe internals of java compiler.A Java Compiler is the collection of programs which is used to compile the java programs . Java Compiler checks java source code if syntactically correct then generates .class file (bytecode) and save into current working directory else java compiler generates compile time error. for example-   javac.exe testprogram.java  Here javac is used to invoke java compiler and to load the source code from Hard Disk to Ram. references: http://javabyvikas.blogspot.com/2013/08/compilation-java-program.html   http://en.wikipedia.org/wiki/Java_compiler

this reference in Java

Image
this reference- this keyword in java programming is used to refer the current class object. this keyword is used when we want to call methods without creating object . this reference stores in the memory when an object of the current class is instantiated. We can say "this" is a special keyword in java programming which is used to refer current class object or instance of any class. By using this keyword we can call methods of current class as well as constructor. Let us see use of this reference in java and its interesting example. this is the keyword of java. this reference holds the address of current class's object. this reference can not be used inside any static context. this reference can be used inside any non-static context. this reference refers to the current class object. this reference stores in the memory how many times object of the class is instantiated. this  reference is used to call a non-static method of the current class without using the ...