Fullstack > Java > 🚀 Introduction
What is Java?
Java is a popular programming language known for its simplicity, platform independence, and security. It is widely used for building applications in web development, mobile development, and enterprise software.
Why Learn Java?
- Easy to Learn – Java has a simple syntax similar to English.
- Platform Independent – Java programs run on any device with a Java Virtual Machine (JVM).
- Object-Oriented – Java follows the OOP principles, making code reusable and modular.
- Used Everywhere – From Android apps to enterprise solutions, Java is in demand.
How Java Works
Java follows the Write Once, Run Anywhere (WORA) principle. This means you write the code once, and it can run on different devices without modification.
- Write Code – Developers write Java code in
.javafiles. - Compile Code – The Java compiler (
javac) converts the code into bytecode (.classfiles). - Run Code – The Java Virtual Machine (JVM) executes the bytecode on different platforms.
Basic Structure of a Java Program
Every Java program has a main method, which is the starting point of execution.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Explanation:
public class HelloWorld– Defines a class namedHelloWorld.public static void main(String[] args)– This is the main method where execution begins.System.out.println("Hello, Java!");– Prints text to the console.
Java Features
Java has several powerful features:
- Simple – Easy-to-understand syntax.
- Object-Oriented – Everything in Java is based on objects.
- Portable – Java programs can run on any OS.
- Secure – Java has built-in security mechanisms.
- Multithreading – Supports multiple tasks running simultaneously.
Java Data Types
Java has two main types of data:
- Primitive Data Types –
int,char,boolean,float, etc. - Non-Primitive Data Types –
String,Arrays,Classes, etc.
Example of using different data types:
int number = 10;
String message = "Java is awesome!";
boolean isFun = true;
System.out.println(message);
Java Control Statements
Control statements help in decision-making and looping:
- Conditional Statements:
if,if-else,switch - Loops:
for,while,do-while
Example of an if statement:
int age = 18;
if (age >= 18) {
System.out.println("You are an adult.");
} else {
System.out.println("You are a minor.");
}
Java OOP Concepts
Java follows Object-Oriented Programming (OOP), which includes:
- Classes and Objects – Blueprints for creating real-world entities.
- Inheritance – Allows one class to inherit from another.
- Polymorphism – Enables multiple methods with the same name.
- Encapsulation – Restricts access to data using access modifiers.
- Abstraction – Hides implementation details.
Java is a powerful language that is beginner-friendly and widely used in the industry. Understanding the basics of Java is the first step toward mastering programming.
| ← Java | History and Evolution → |
🔗 Related Topics: