Features of Java:-
Following are the some very important characteristics or features of java which have made java so popular or no. 1 choice for programmers.
1) Platform Independence
2) Automatic Memory Management
3) Secure
4) Robust
5) Simple
6) Object oriented
7) Multi threaded
8) Distributed
1. Platform Independence:- Before we can understand what is platform independent, we will have to understand the meaning of the word platform.
Platform:- A platform or machine is an environment in which a program runs.
In simple terms, it is the combination of Operating System and processor(CPU).
Example:- windows+core i7 is a one platform while Linux+core i5 is a different platform.
Now being platform independent means that an application(program) developed and compiled over one platform like windows can be executed over any other platform like Linux, Mac OS without any change in the code (rewriting or recompiling).
Java has this features or ability and so it is called platform independent language or technology.
When we install JAVA (jdk), we have got two things:-
1) Java Compiler
2) JVM (Java virtual machine)
Whenever we compile a java program, the java compiler never generates machine code. Rather it converts our source code into intermediate code called as the byte-code.
This byte-code is not directly understandable by the underline platform or machine(OS & CPU).
So another special layer of software is required to convert these byte-code instructions to machine dependent form.
This special layer of the software is called as the JVM, that converts the byte-code to underlying machine instruction set and runs it.
Whenever, JVM is present there we can execute a java program without rewriting and recompiling it.
Thus any such platform for which a JVM is available can be used to execute a Java application irrespective of where it has been compiled.
This makes Java truly “Platform Independent” and it also justifies java’s slogan(punch line) called as “WORA” (Write Once Run Anywhere).
2. Automatic Memory Management:- In Java, just like c c++ languages, we have the concept of dynamic memory allocation using malloc( ) or new has to be deallocated by himself using free( ) or delete. But in Java, it is not a programmers responsibility to deallocate the dynamic memory his program has been using. The deallocation of memory is exclusively handled by Java virtual machine (JVM) and thus, we say that Java has automatic memory management.
Due to this run time errors like- memory leaks do not happen in Java.
3. Secure:- Java is one of the most secure programming language present on the planet today.
In other words, we can say that java has some very strong features which makes it much more safe and secure as compared to other language like c and c++. Java has no support for pointers i.e. as a java programmer we are not allow to access any address directly in our program.
Another security feature of java is that a java program can never directly talk to the operating system. It always communicates with JVM and due to this it is considered high secure.
Moreover all the programs in java are run under an area known as the sand-box.
The Sandbox uses a byte-code verification process to ensure that code loaded does not violate Java security constraints.
4. Robust (fault tolerant):- Java has very strict rules which every program must compulsorily follow and if these rules are violated then JVM kills or terminates the code by generating “Exception”.
To understand java’s robustness, guess the output of the following code C/C++ code:-
Ex:-
int arr[5];
int i;
for(i=0;i<=9;i++)
{
arr[i]=i+1; // Unpredictable after i is 5
}
The previous code might show uncertain behavior in c/c++ that is if memory is available after arr[4], then the code will run, otherwise it will generate error at runtime.
On the other hand if in java this code is executed, the JVM will kill the application as soon as it finds the statement arr[5]=...
Reason is that in java we are not allowed to access any array beyond it’s upper/lower index.
5. Simple:- Java has inherited it's maximum syntax from two popular languages called c and c++.
for example:- Decision control statements like- if, switch loops while, for , do....while, arrays etc have same syntax in java like they have in c and c++.
Like it has removed pointers, multiple inheritance etc as developers of java language found these features to be security threat and confusing.
Thus, if we have basic understanding of C/C++ languages it is very easy to learn Java.
6. Object Oriented:- Java strongly follows principles of Object Oriented Programming(OOP's).
For example:- It is compulsory for us to always create a class in every java program, we write and this is called Encapsulation, which is very important principle of OOP’s.
Similarly, Java supports all other principles of OOP's like- Polymorphism, Inheritance, Abstraction, Composition etc.
7. MultiThreading:- Multithreading means concurrent execution. The word multi-threading means parallel execution.
In simple words, we can say that if we are able to execute more than one function of the same program together than it is called Multi Threading.
For example:- In a music player there are lot of activities which are executed parallely like-
1) playing of the song.
2) Running of a times to show how much song has been played.
3) Running of a slider to show song progress.
4) Allowing the user to increase or decrease volume level during song play.
All these activities takes place together and this is the effect of Multi-Threading.
Java has very good built-in support for developing multi threaded program and show games, music-players, chatting application like WhatsApp are mainly designed in Java.
To understand this feature consider the code given below:-
Ex:-
main( )
{
clrscr();
factorial( );
prime(8);
evenOdd(4);
}
In the previous sample code all 4 functions clrscr() , factorial(), prime() and evenOdd() are independent of each other but still they will run sequentially i.e. one after the other.
This can be improved in java by using multi threading feature so that each one of these functions can run together.
Benefits of Multi Threading:- Reduce execution time, full utilization of CPU
8. Distributed:- Distributed programming uses more than one computer that is different parts of the same program run on different computers and communicate over a network.
In Java, this is made possible by a technique called RMI (Remote method invocation).
RMI allows a method that is running on one computer to call a method in an object that is on another computer.
Benefits:- Programmers working on same project may be required to be physically present at the same location.
Following are the some very important characteristics or features of java which have made java so popular or no. 1 choice for programmers.
1) Platform Independence
2) Automatic Memory Management
3) Secure
4) Robust
5) Simple
6) Object oriented
7) Multi threaded
8) Distributed
1. Platform Independence:- Before we can understand what is platform independent, we will have to understand the meaning of the word platform.
Platform:- A platform or machine is an environment in which a program runs.
In simple terms, it is the combination of Operating System and processor(CPU).
Example:- windows+core i7 is a one platform while Linux+core i5 is a different platform.
Now being platform independent means that an application(program) developed and compiled over one platform like windows can be executed over any other platform like Linux, Mac OS without any change in the code (rewriting or recompiling).
Java has this features or ability and so it is called platform independent language or technology.
When we install JAVA (jdk), we have got two things:-
1) Java Compiler
2) JVM (Java virtual machine)
Whenever we compile a java program, the java compiler never generates machine code. Rather it converts our source code into intermediate code called as the byte-code.
This byte-code is not directly understandable by the underline platform or machine(OS & CPU).
So another special layer of software is required to convert these byte-code instructions to machine dependent form.
This special layer of the software is called as the JVM, that converts the byte-code to underlying machine instruction set and runs it.
Whenever, JVM is present there we can execute a java program without rewriting and recompiling it.
Thus any such platform for which a JVM is available can be used to execute a Java application irrespective of where it has been compiled.
This makes Java truly “Platform Independent” and it also justifies java’s slogan(punch line) called as “WORA” (Write Once Run Anywhere).
2. Automatic Memory Management:- In Java, just like c c++ languages, we have the concept of dynamic memory allocation using malloc( ) or new has to be deallocated by himself using free( ) or delete. But in Java, it is not a programmers responsibility to deallocate the dynamic memory his program has been using. The deallocation of memory is exclusively handled by Java virtual machine (JVM) and thus, we say that Java has automatic memory management.
Due to this run time errors like- memory leaks do not happen in Java.
3. Secure:- Java is one of the most secure programming language present on the planet today.
In other words, we can say that java has some very strong features which makes it much more safe and secure as compared to other language like c and c++. Java has no support for pointers i.e. as a java programmer we are not allow to access any address directly in our program.
Another security feature of java is that a java program can never directly talk to the operating system. It always communicates with JVM and due to this it is considered high secure.
Moreover all the programs in java are run under an area known as the sand-box.
The Sandbox uses a byte-code verification process to ensure that code loaded does not violate Java security constraints.
To understand java’s robustness, guess the output of the following code C/C++ code:-
Ex:-
int arr[5];
int i;
for(i=0;i<=9;i++)
{
arr[i]=i+1; // Unpredictable after i is 5
}
The previous code might show uncertain behavior in c/c++ that is if memory is available after arr[4], then the code will run, otherwise it will generate error at runtime.
On the other hand if in java this code is executed, the JVM will kill the application as soon as it finds the statement arr[5]=...
Reason is that in java we are not allowed to access any array beyond it’s upper/lower index.
5. Simple:- Java has inherited it's maximum syntax from two popular languages called c and c++.
for example:- Decision control statements like- if, switch loops while, for , do....while, arrays etc have same syntax in java like they have in c and c++.
Like it has removed pointers, multiple inheritance etc as developers of java language found these features to be security threat and confusing.
Thus, if we have basic understanding of C/C++ languages it is very easy to learn Java.
6. Object Oriented:- Java strongly follows principles of Object Oriented Programming(OOP's).
For example:- It is compulsory for us to always create a class in every java program, we write and this is called Encapsulation, which is very important principle of OOP’s.
Similarly, Java supports all other principles of OOP's like- Polymorphism, Inheritance, Abstraction, Composition etc.
7. MultiThreading:- Multithreading means concurrent execution. The word multi-threading means parallel execution.
In simple words, we can say that if we are able to execute more than one function of the same program together than it is called Multi Threading.
For example:- In a music player there are lot of activities which are executed parallely like-
1) playing of the song.
2) Running of a times to show how much song has been played.
3) Running of a slider to show song progress.
4) Allowing the user to increase or decrease volume level during song play.
All these activities takes place together and this is the effect of Multi-Threading.
Java has very good built-in support for developing multi threaded program and show games, music-players, chatting application like WhatsApp are mainly designed in Java.
To understand this feature consider the code given below:-
Ex:-
main( )
{
clrscr();
factorial( );
prime(8);
evenOdd(4);
}
In the previous sample code all 4 functions clrscr() , factorial(), prime() and evenOdd() are independent of each other but still they will run sequentially i.e. one after the other.
This can be improved in java by using multi threading feature so that each one of these functions can run together.
Benefits of Multi Threading:- Reduce execution time, full utilization of CPU
8. Distributed:- Distributed programming uses more than one computer that is different parts of the same program run on different computers and communicate over a network.
In Java, this is made possible by a technique called RMI (Remote method invocation).
RMI allows a method that is running on one computer to call a method in an object that is on another computer.
Benefits:- Programmers working on same project may be required to be physically present at the same location.
0 Comments