Skip to main content

Java Tutorial

Java is a high level, general-purpose, object oriented, classes based programing language. That is initially developed by James Gosling of Sun Microsystems in 1995.

Feature of Java programming

Object Oriented Language

Object oriented means That means object and class are manage your data. And provide a mechanism that is based on class and programmer are defining the logic how to operator this data in a different scenarios. The Feature of classes is based of set of rules and programmer logic are implement new solution of real life situation by using class rules. There are many feature of object-oriented such as inheritance, encapsulation and abstraction etc. Those are implemented by class. The main advantage of Object oriented programming like ease to debugging, eliminate redundant code and ease of replacement etc.

Platform independent

Java provide platform independent environment, When we compile java source file java compiler are convert this program to bytecode (Binary code). And we can run this program to another operating system by using installation of Java Virtual Machine (JVM) to that system. That reason we can run compile java program to another operating system, Without recompile actual source code. In other word bytecode are communicate of with operating system. And this byte code are executed line by line within the JVM.

Compatibility security

Java compiler are created one variant which is capable to execute all other operating system. In other programming language are create separate version which are work of particular environment (operating System). That reason java code is much secure and compatible for operating system.

Secure and Robust

Java are portable for many operating system, That is provide strong type checking mechanism. Java compiler are capable to trace all possible syntactic error in programming code. And if found any compile time error then they are provide information to that error. And also provides a technique to control runtime exceptions.

Standard Library

Java programming are provided various predefined packages and classes which are reliable to reduced programming efforts

Garbage collection

Java is one of the programming language which are supports automatic garbage collection. Garbage Collection actually memory space which are occupied by the program execution and objects instances. When execution process are over and objects are out of scope, In this situation that occupied memory are release automatically. Let see an example.

public class Employee{
  private String name;
  private double salary; 

  public Employee(String name,double salary){
    this.name=name;
    this.salary=salary;
  }
  public void details(){
    System.out.println("Name : "+name);
    System.out.println("Salary : "+salary);
  }
  public static void main(String[] args) {
    
    //Create memory of instance variable of objects
    //make objects
    Employee partTime = new Employee("Johnny",50000.61);
    Employee fullTime = new Employee("Robert",90000.11);

    //display details
    partTime.details();
    fullTime.details();

    //Free memory of instance variables
    partTime=null;
    //This is a referencing variable in this time that are not hold any reference.
    //So that is not capable to access class properties and method.

  }
}
Name : Johnny
Salary : 50000.61
Name : Robert
Salary : 90000.11

In this example Employee class are two objects partTime and fullTime. This object are holds the reference of instance variables which are created by in class constructor. Interesting that, when partTime object are assign null value then this holding reference are modified to null (not point any reference address).

Garbage Collection Example

When set null to partTime object there holding reference are not store by other object. In this situation this memory is freed by Garbage collector.

null are use to set object value that which are not hold any instance reference address. Suppose initially Object are storing the value of instance reference. When in case that is assign null reference value then there are two possibility. Instance reference memory are freed by java or not free. Above example are based on first case. That are frees the memory memory of partTime instance.

Let's see the example of second case.

public class Employee{
  private String name;
  private double salary; 

  public Employee(String name,double salary){
    this.name=name;
    this.salary=salary;
  }
  public void details(){
    System.out.println("Name : "+name);
    System.out.println("Salary : "+salary);
  }
  public void addAmount(double amount){
    this.salary+=amount;
  }
  public static void main(String[] args) {
    
    //Create memory of instance variable of objects
    //make objects
    Employee fullTime = new Employee("Johnny",50000.61);
    
    Employee extraTime =fullTime;
    extraTime.addAmount(10000);
    //display details
    fullTime.details();
    extraTime.details();

    //set object reference is to null
    extraTime=null;
  }
}
Name : Johnny
Salary : 60000.61
Name : Johnny
Salary : 60000.61
Setting null value to reference variable

I hope you'll are understand null is not responsible to free memory. That is depends scopes and un-referencing.

Multithreading

Multithreading is a way to work concurrence executes of multiple process using same resources. That is mainly used to long-running tasks which are running on background internally. The main goal of multithreading are use maximum power of system resources.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment