Introduction to Java
Java is a high-level, class-based, object-oriented programming language that is widely used
for building applications. It is platform-independent, meaning that Java code can run on any device
that
has the Java Virtual Machine (JVM).
Key Features of Java:
1. Simple and easy to learn
2. Platform-independent (Write Once, Run Anywhere - WORA)
3. Object-oriented programming (OOP) based
4. Secure and robust
5. Multi-threaded support
Now, let's start with a simple Java program.
Simple Java Program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation of the Program
Breakdown of the Hello World program:
1. public class HelloWorld - Defines a class named 'HelloWorld'.
2. public static void main(String[] args) - The main method where execution begins.
3. System.out.println("Hello, World!"); - Prints 'Hello, World!' to the console.
- 'public' means the method can be accessed from anywhere.
- 'static' allows execution without creating an object.
- 'void' means the method does not return a value.
- 'String[] args' allows command-line arguments to be passed.
This is the basic structure of a Java program.