What is Java?
Java is a high-level, object-oriented programming language. It’s platform-independent — you write your code once and it runs anywhere (with a Java Virtual Machine, or JVM). Java is widely used for developing web applications, enterprise software, games, and Android apps.
Why Java?
- Platform-Independent (Write Once, Run Anywhere).
- Robust and Reliable — automatic garbage collection, strong memory management.
- Scalable — used by large enterprises for heavy workloads.
- Security — a strong API for developing secured applications.
- Large ecosystem of libraries and community support.
Java Introduction with Examples:
Let's see a simple example:
// This is a simple Java program
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Explanation:
- public class HelloWorld — We define a class with the name
HelloWorld
. - public static void main(String[] args) — This is the main method, which is the entry point for the Java application.
- System.out.println("Hello, World!"); — Prints the text to console.
Another Example (Addition of two numbers)
public class AddNumbers {
public static void main(String[] args) {
int num1 = 10;
int num2 = 20;
int sum = num1 + num2;
System.out.println("The sum is: " + sum);
}
}
Explanation:
- We declare two integer variables,
num1
andnum2
. - We compute their sum and store it in a new variable
sum
. - We then print the sum to console.
Summary:
Java is:
- Platform-independent
- Robust, Reliable, and Scalable
- Object-oriented and Security-centric
Hello World and Addition demonstrate:
- The structure of a Java application
- How we perform simple operations and print results to console
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.