Search

Java Important Points

What is Java ?

Java is an object-oriented, class-based, concurrent, secured and general-purpose computer programming language. It is a widely used robust technology.

Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure programming language.

Platform: Any hardware or software environment in which a program runs is known as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform.

Java Example
   Let's have a quick look at the Java programming example. A detailed description of the Hello World! example is available on the next page.

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

Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java.

Installation Guidance
Before diving into coding, we will need to set up your development environment. Java development typically requires the Java Development Kit (JDK), which includes the Java compiler and other essential tools. You can download the JDK from the official Oracle website and follow the installation instructions for your operating system

Once we have the JDK installed, you can use a text editor or an Integrated Development Environment (IDE) like IntelliJ IDEA, Eclipse, or NetBeans to write and run your Java code. IDEs provide features such as code completion, debugging, and project management, making them invaluable tools for developers.

Platform : Any hardware or software environment in which a program runs, is known as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform.

Java Program Example:

Simple.java

  1. class Simple{  
  2.     public static void main(String args[]){  
  3.      System.out.println("Hello Java");  
  4.     }  
  5. }  

 Features of Java
  • Simple
  • Object Oriented
  • Portable
  • Platform Independent
  • Secured
  • Robust
  • Architectural Neutral
  • Interpreted
  • High Performance
  • Multithreaded
  • Distributed
  • Dynamic

Simple:

Java is easy to learn, with a syntax that is simple, clean, and easy to understand. According to Sun Microsystems, Java is a simple programming language because:

  • Java syntax is based on C++, making it easier for programmers to learn after C++
  • Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc.
  • No need to remove unreferenced objects because there is an Automatic Garbage Collection in Java.


Object-Oriented :

Java is an object-oriented programming language where everything is an object. Object-oriented programming means that we organize our software as a combination of various types of objects that incorporate both data and behavior.

Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules.

Basic concepts of OOPs are:

  1. Object
  2. Class
  3. Inheritance
  4. Polymorphism
  5. Abstraction
  6. Encapsulation
Portability:

Java's portability allows programs to run on various platforms without modification. This is achievable because Java code is compiled into bytecode, which is independent of the underlying hardware and operating system. The JVM on each system interprets this bytecode, ensuring platform compatibility.


This portability makes Java ideal for cross-platform applications, allowing developers to write code once and run it anywhere with a compatible JVM. This key reason contributes to Java's widespread use in enterprise applications, web development, and mobile platforms.

Platform Independent

Java is platform-independent because it differs from other languages like C, C++, etc., which are compiled into platform-specific machines. In contrast, Java is a "write once, run anywhere" language. A platform refers to the hardware or software environment in which a program runs.



 There are two types of platforms software-based and hardware-based. Java provides a software-based platform.

The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on top of other hardware-based platforms. It has two components:

  1. Runtime Environment
  2. API(Application Programming Interface)
Java code can be executed on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, etc. Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent code because it can be run on multiple platforms, i.e., Write Once and Run Anywhere (WORA).

Secured

Java is renowned for its security. With Java, we can create virus-free systems. Java is secured because:
  • No explicit pointer
  • Java Programs run inside a virtual machine sandbox

Classloader: Classloader in Java is a component of the Java Runtime Environment (JRE) that dynamically loads Java classes into the Java Virtual Machine. It enhances security by differentiating the package for classes from the local file system and those imported from network sources.

Bytecode Verifier: It checks code fragments for illegal code that can violate access rights to objects.

Security Manager: It specifies which resources a class can access, such as reading from and writing to the local disk.

The Java language provides these securities by default. Additionally, some security features can also be explicitly implemented by an application developer through SSL, JAAS, cryptography, and so on.

Variables

Variable is a name of memory location. There are three types of variables in java: local, instance and static.

Types of Variables

There are three types of variables in Java:

  • local variable
  • instance variable
  • static variable

1) Local Variable

A variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class aren't even aware that the variable exists.

A local variable cannot be defined with "static" keyword.

2) Instance Variable

A variable declared inside the class but outside the body of the method, is called an instance variable. It is not declared as static.

It is called an instance variable because its value is instance-specific and is not shared among instances.

3) Static variable

A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variables happens only once when the class is loaded in the memory.