Sunday, February 22, 2015

                                                                    Java Basics

Java is programming language like C,C++. It is used used to develop standalone, web, enterprise, mobile application .

Feature of Java:

1)Simple:
      Java is simple programming language as the concept of pointers, operator overloading has been removed from the java.

2)Object oriented programming.
      Java follow the oops concepts. This is the most important feature of java.

 Following are the oops  concept:
                1)Object.
                2)Classes.
                3)Encaspulation
                4)Abstration
                5)Inheritance
                6)Polymorphism.

3) Multithreaded:
        This is also one of the main feature in java. Java provide API with which we can develop with the multithreaded application

4)Distrubuted.
       Using RMI and EJB we can develop distributed application.

5)Platform independent:
     Code written in java is able to run on any platform. This is the magic of JVM (java virtual machine) which tranform the byte code which is compiled java code into platform specific code.

6)Portable.
     Java program is portable means,java program can run on any hardware where the JVM runs.


Hello World Java Program:


class HelloWorld{
             public static void main(String args[]){
                      System.out.Println("Hello World!");
             }
}

This is the simple program in java. This program is used to print the "Hello World!" on console.
We need  create the class to write any class in java and one main method we need to write JVM will call this method when we run this program.

Steps to execute the program:
1)Save this program with HelloWorld.java.
2)Compile this program using JAVAC utility.
3)Run the compiled byte code using JAVA  interpreter.

>javac HelloWorld.java
>java HelloWorld
>Hello World!
========================================================================

Tuesday, January 27, 2015


 Thread in java

Before understanding the threads in java lets understand the basics first.
 
Instruction:Instruction are the command given to computer/processor/central processing unit.Instructions are like copying the data from main memory to register, performing addition, subtraction, division,multiplication.

Instructions are the input to the central processing unit or processor. Processor takes the action depends upon the type of instruction.Set of instruction that processor understand is nothing but the Instruction set of that processor.


example: mov a ,1234;


Program:Set of instruction is nothing but the program.

example: mov a,10
              mov b,20
              add a,b

Process: Program in execution is nothing but the process.

Suppose you are preparing tea then the recipe of tea is nothing but the program and actually preparing tea by reading the steps one by one is nothing but the process.

Each process will have the separate address space in memory where he stores the local variable value.Each process is having program counter variable to store the value for the the number of instruction executed.

Multitasking:Executing the multiple task at a time is multitasking.

example:While listening music you are writing something in a notebook. You are doing two task at a time is nothing but the multitasking. 

Multitasking is achieved by multiprocessing executing more than one process at a time.


One of the drawback/disadvantage is that if there is a requirement of executing two same process at a time then each process will have its saparate address space in a main memory. This problem is addressed by thread we execute same process we called it ad thread of that process and all thread will have the common address space in this way space optimization is achieved.

    
                                      Fig:Multiprocessing

                                   Fig:Multithreading

Multithreading: Executing the more than thread at a time is Multithreading.

Thread: Thread is basically a lightweight sub-process, a smallest unit of processing.Threads of the same process executes in the common address space of that process.