Introduction To Java
Java was developed by Sun Microsystems Inc in the year 1991, later acquired by Oracle Corporation. It is a general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java.
It has a wide range of usability like Mobile Applications, Web Applications, Client-Server Applications, Enterprise Applications, Application Servers, Desktop Applications, Unit tests, etc.
- It is a class-based, object-oriented programming language(Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior).
- Java codes are compiled into byte code which acts as an instruction set for java virtual machine. As soon as a java program is compiled, java bytecode is generated.
- Java codes are written in the form of classes and objects.
- The programs written in Java typically run faster than corresponding Python programs and slower than C++.
- Like C++, Java does static type checking(it checks the type of variable before running).
Some important terms about Java
JDK(Java development Kit) JDK is a complete Java development kit containing the JRE, compiler, Java debuggers, Java documents, etc.We need JDK on our machines to program compile and run Java programs.
JRE(Java Runtime Enviroment) JRE is required for programs to run. JRE includes a browser, JVM, applet supports and plugins.
JVM(Java Virtual Machine) There are three execution phases of a program. They are written, compiled, and run the program.Java Programmers write a program.The compilation is done by the JAVAC compiler which is a primary Java compiler included in the Java development kit (JDK) that converts programs to bytecode.JVM executes the bytecode produced by the compiler.There is a different JVM for every OS but they all result in the same output.
Bytecode bytecode is saved as .class file by javac after converting it from source code.
Garbage Collector Java garbage collection is the process by which Java programs perform automatic memory management. When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory.The garbage collection implementation lives in the JVM. Each JVM can implement garbage collection however it pleases; the only requirement is that it meets the JVM specification.
ClassPath JRE and javac look for .class files in a particular location. The path they follow to reach that location is called ClassPath. By default, JDK provides many libraries. If you want to include external libraries they should be added to the classpath.
Advantages of Java
Platform Independent There are many JVM's for different OS' but each gives the same output to the bytecode which makes Java platform-independent.
OOP Language As discussed above Java is Object Oriented which is beneficial for long complex codes, increases reusability, and good for programmers working in teams for a product. The main concepts of Object-Oriented programming are:
- Object
- Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Portable Java platform-independent bytecodes written in one machine can be run on another.
Multithreading when programs are executed, a thread of execution is followed.Java allows multiple threads to be followed for maximum utilization of CPU.
Simple Java is one of the simplest languages and one of the first that I started coding in. It does not have complex features like pointers, operator overloading, multiple inheritances, Explicit memory allocation.
Robust Java language is robust that means reliable. It is developed in such a way that it puts a lot of effort into checking errors as early as possible, that is why the java compiler is able to detect even those errors that are not easy to detect by other programming languages. The main features of java that make it robust are garbage collection, Exception Handling, and memory allocation.
Secure In java, we don’t have pointers, and so we cannot access out of bound arrays i.e it shows ArrayIndexOutOfBoundsException if we try to do so. That’s why several security flaws like stack corruption or buffer overflow are impossible to exploit in Java.
Distributed We can create distributed applications using the java programming language. Remote Method Invocation and Enterprise Java Beans are used for creating distributed applications in java. The java programs can be easily distributed on one or more systems that are connected to each other through an internet connection.
A simple Hello World program:
import java.io.*
public class hello_world
{
public static void main (String args[])
{
System.out.println("Hey There ! This is my First Blog ");
}
}