January 2015
Java Notes For Java Beginner

Array : A homogeous set of finit elements which is stored in a continues memory location under certain name, is called array.

Example:
int a[]=new int[5];
a[0] =4;
a[1] =6;
a[2] =8;
a[3] =10;
a[4] =15;

or

int a[]={4,6,8,10,15};


length: This field is used to return the number of elements of a given array.

Write a program to sort given array in ascending order using selection sort technique.

class sort
{
 public static void main(String args[])
 {
  int a[]={55,33,11,22,44}
  int n=a.length;
  int i,j,temp;
  System.out.println("Before swapping array elemts");
  
  for(i=0;i<=n-1;i++)
   System.out.println(a[i]);
   
   for(i=0;i<=n-2;i++)
   {
    for(j=i+1;j<=n-1;j++)
    {
     if(a[i]>a[j])
     {
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
     }
    }
   }
  System.out.println("Sorted array elements are :");
  System.out.println(a[i]);
 }
}
Java Notes For Java Beginner

Static keyword is used to load the class data into primary memory first to the object. As it is directly loaded into memory, it can be accessible directly.

Note : Static data is shareable to all the objects of same class.

Write a program to access static & non-static data of class.
class class

{
    int x; //non-static
    static int y; //static
    public static void main (String args[])
    {
        c c1=new c();               //New object created [1st]
        system.out.println(c1.x);   //called using c1 object
        system.out.println(c1.y);   //called using c1 object
        system.out.println(c.y);    //called using class
        system.out.println(x);      //directly called
 
        c1.x++;                     //Operation performed using c1 object [Value becomes x=1]
        c1.y++;                     //Operation performed using c1 object [Value becomes y=1]
       
        c c2=new c();               //New object created [2nd]
        system.out.println(c2.x);   //called using c2 object
        system.out.println(c2.y);   //called using c2 object
    }
}


Output:
           0
           0
           0
           0
           0
           1

Static data can be accessible by three ways.

  1. Using class object.
  2. Using class name.
  3. Directly.

Note : Non-static data can be accessible only through it's class object.

System.out.println() //Statement

System is a built in class and out is static field of it. The combination of this two will send the data from editor to keyboard memory. This memory is the space reserved on primary memory for every java application. The println() method of print stream class sends the data from keyboard memory to console.

PrintStream class have two methods

1> println(): This method send the corsor to the next line after printing the data.

Example:
class D
{
    public static void main(String args[])
    {
        System.out.println("\t\t Hello\t\t\t");
        System.out.println("How Are You?");
        System.out.println("Bye...");
    }
}

Output:
         Hello
    How Are You?
    Bye...

2> print(): It remains cursor on the same line after printing.


Example:
class add
{
    public static void main(String args[])
    {
        int a,b,c;
        a=10;
        b=20;
        c=a+b;
       
        System.out.println(C);
        System.out.println("Addition is "+c);
        System.out.println("Addition of "+a" and "+b" is "+c);
        System.out.println(a+" + "+b+" = "+c);
    }
}

Output:
    30
    Addition is 30
    Addition of 10 and 20 is 30
    10 + 20 = 30
   
Note : + sign is used as separator in system.out.println statement...



Java Notes For Java Beginner

Structure oriented language 'C' when implemented with new object oriented concepts, it becomes 'C++'.
These new language doesn't support/follow the concepts so C++ is also known as partial object oriented language. Both above languages are 16 bits (DOS-Base) application (Window based), implements all oops (object oriented programming) concept by removing the structural orientation from it. This new language is called 'OAK' It is Designed & Developed by the team whose leader is 'JAMES GOSLING' at 'SUN MicroSystems' USA in 1991.

Preliminary, this language is used for repairing & manufacturing of electronic equipment's like radio, transistor, press, etc... As this language follows better network, so the development team uses this application for chatting in Intranet process. This team creates a web browser for mailing of large data & named as 'Hot-JAVA'.

Later on, it comes into consideration, that this language is also applicable for academic purpose, So it again lunch at 1995 for the same purpose & Just renamed it as 'JAVA'. Java is famous for its slogan "Write Once, Run Anywhere."

There were five primary goals in the creation of the Java language:
  • It must be "simple, object-oriented, and familiar".
  • It must be "robust and secure".
  • It must be "architecture-neutral and portable".
  • It must execute with "high performance".
  • It must be "interpreted, threaded, and dynamic".

Java Versions:

  • JDK 1.0
  • JDK 1.1
  • J2SE 1.2
  • J2SE 1.3
  • J2SE 1.4
  • J2SE 5.0
  • Java SE 6
  • Java SE 7
  • Java SE 8 
Read More About Java version history here.

Features of JAVA

  • Java is secured language.
  • Java is complied and interpreted language.
  • Java is platform independent language [It means we can compile sthe java application on one machine and run it on other machine with same or other platform (operating system).
  • Java is famous for its slogan "WORA" means "Write Ones, Run Anywhere".
  • Java is Simple, Robust & Dynamic language.
  • Java is multi-threaded & distributed language.
  • 'javac' command is used to invoke the .java file to it. compiler converts it into it's equivalent .class file (Byte code).
  • 'Java' command is used to call the java interpreter (JVM-JAVA Virtual Machine), assign th .class file without extension to this command. It converts it into it's .exe file, print's the output & delete the .exe file from memory.
  • Program should be save with the class name in which main() method is defined.
  • Example: File Name: A.java
    class A
    {
    public static void main(String args[])
    {
    System.out.println("Hello");
    System.out.println("How Are You ? ");
    System.out.println("Bye... ");
    }
    }
    
  • Context Creation : Context means the memory created by object for the class elements.
  • Example: File Name: B.java
    class B
    {
    int x=10;
    int y;
    void fun1()
    {
    System.out.println("Hello Fun1");
    }
    public static void main(String args[])
    {
    B b1=new B();
    b1.fun1();
    b1.fun1();
    System.out.println(b1.x);
    System.out.println(b1.y);
    b1.y=50;
    System.out.println(b1.y);
    B b2=new B();
    System.out.println(b2.x);
    System.out.println(b2.y);
    b2.fun1();
    }
    }