Wednesday 19 June 2013

Instance Variables

Leave a Comment Follow us on twitter

  • If the value of a variable is varied from object to object such
type of variables are called instance variables

  • For every object a seperate copy of instance variable will be created

  • The scope of instance variables is exactly same as the scope of 
the objects. Because instance variables will be created at the time of 

objects  creation & destroy at the time of objects destruction

  • Instance variables will be stored  as the part of objects

  • Instance variables should be declare with  in the class directly, But outside of any
method or block or constructor

  • Instance variables cannot be accessed from static area directly we can
access by using object reference. But from instance area we can access instance members directly

Ex:-

    class Test{

int x=10;

public static void main(String args[]){

Syste.out.println(x); -----------> compile time error

Test t=new Test();

System.out.println(t.x);------->10

}

public void m1(){

System.out.println(x);---------->10

}
}
  • For the instance variables it is not required to perform initialization explicitly
JVM will provide default values


For Example:-

class Test{

String s;

int x;

boolean b;

public static void main (String args[]){

Test t=new Test();

System.out.println(t.s);   ---------> null

System.out.println(t.x); -----------> 0

System.out.println(t.b); --------------> false

}

}

  • Instance variables also known as " Object level variables" or "attributes".
READ MORE...

Local variables

Leave a Comment Follow us on twitter

  • To meet temparary requirements of the programer some times we have to
 create variables inside method or block or constructor such type of variables 

are called as local variables

  •  Local variables also known as stack variables or automatic variables or temparary
   variables

  •  Local variables will be stored inside a stack

  • The local variables will be created while executing the block in which we 
 declared it & destroyed once the block completed .Hence, The scope of local variable is

exactly same as the block in which we declared it.

Ex:-

               class Test
               {

              public static void main(String[] args)
              {
              int i=0;
              for(int j=0;j<3;j++)
              {
              i=i+j;
              }
             System.out.println(i+"-------------"+j);
              }
              }
Here we will get compile time error 

like this: Can't find symbol , Symbol:varible J, Location: class Test

  • For the local variables JVM won't provide any default values 
compulsary we should perform initialization explicitly , before using that varible


Ex:- Class Test{

         public static void main(String args[])
         {
      int x;
     System.out.println("Hello");
        }
 }

O/P: Hello


Let's see another example

class Test2{

public static void main(String args[])

{

int x;

System.out.println(x);

}

}

In this class Test2 example we will get compile time error why because we are not initialized variable x

we should initialize before we using it.

Note:-

  • It is not recommended to perform initialization of local variables
inside logical blocks because there is no garantee execution of 

these blocks at run time

  • It's Highly recommended to perform initialization for the local variables at the 
time of declaration, at least with default values

  • The only applicable modifier for the local variables is "final" if we are
using any other modifier we will get compile time error
       
READ MORE...

Features of Java?

Leave a Comment Follow us on twitter
1) Simple

2) System independent

3) Object oriented

4) Distributed

5) Robust

6) Secure

7) Architecture Neutral

8) Portable

9) Interpreated

10) High performance


READ MORE...

Java Applications?

Leave a Comment Follow us on twitter
  According to Sun Microsystems 3 billion devices run Java, currently  

so many devices are using Java.Those are:

1) Desktop Applications-- Media player, Anti virus e.t.c..

2) Enterprise Applications--Banking, marketing applications

3) Embedded Systems

4) Mobile Applications

5) Robotics

6) Web applications

7) Smart cards

8) Games e.t.c....
READ MORE...

Why the name Java?

Leave a Comment Follow us on twitter
       James gosling and his team members were consuming a lot of

coffee while developing the language. They felt that they were able to develop a

better language because of the good quality of coffee they consumed. So the coffee 

had it's own role in developing this language and good quality exported to the entire 

world from a place called "Java island" .Hence they fixed the name of the place

for the language as Java. And the symbol for the Java language is coffee cup and saucer.



         
READ MORE...

History of Java?

Leave a Comment Follow us on twitter
        Before starting to learn java, Let us plunge into it's history and

 see how the language orginated. In  1990, Sun Microsystems inc, has conceived 

a project to develop software for consumer electronic devices  that could be

 controlled by a remote. This project was called "Stealth Project"  but later it name was 

changed to Green project. In January of 1991, Bill joy, James gosling, Mike sheradin,

 Patrick Naughton,  and several others met in aspen, Colorado to discuss this project.

Mike sheradin was to focus on business  development, Patrick naughton was to begin work

 on  the graphics system : and James Gosling was to  identify the proper programming language

 for the project. Gosling thought  C and C++ could be used to  developed the project.

 But the problem he faced with them is that they were system dependent languages and hence

 could not be used on various processors, Which the electronic devices might use. so he started 

developing a new language was initiallly called oak. Since this name was registered 

by some other company, later it was changed to java.


READ MORE...