What is Java?
- Java is a high-level, object-oriented, and platform-independent programming language.
- It was originally developed by James Gosling at Sun Microsystems and released in 1995.
- Today, Java is maintained by Oracle Corporation.
Key Features of Java:
- Simple: Easy to learn if you know basic programming concepts.
- Object-Oriented: Everything is an object (data + behavior).
- Platform-Independent: Write code once and run it anywhere (thanks to the Java Virtual Machine – JVM).
- Secure: Provides a secure environment for developing applications.
- Robust: Strong memory management, exception handling.
- Multithreaded: Supports multithreaded programming (running multiple tasks at the same time).
- Portable: Java programs can move easily from one system to another.
- High Performance: Though not as fast as C/C++, Java performance is quite high due to Just-In-Time compilers.
How Java Works:
- Write the Java code (
.java
file). - Compile the code using the Java compiler (
javac
), which creates a bytecode file (.class
). - The JVM (Java Virtual Machine) reads and runs the bytecode.
Simple Java Program:
javaCopyEditpublic class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation:
public class HelloWorld
: Defines a class calledHelloWorld
.public static void main(String[] args)
: This is the main method where the program starts running.System.out.println("Hello, World!");
: Prints “Hello, World!” to the console.