Java Basics Notes 1.
Introduction to Java Java is a high-level, object-oriented, and
platform-independent programming language developed by Sun Microsystems (now owned by
Oracle). It is widely used for web, desktop, and mobile applications. Key Features: Simple and
easy to learn Object-Oriented Programming (OOP) Platform independent (Write Once, Run
Anywhere) Robust and secure Automatic memory management (Garbage Collection) 2. Java
Program Structure A simple Java program looks like this: class HelloWorld { public static void
main(String[] args) { System.out.println("Hello, World!"); } } Explanation: class: Defines a class
named HelloWorld. main: Starting point of every Java program. System.out.println: Prints text to
the console. 3. Java Data Types Primitive Types: byte, short, int, long, float, double, char, boolean
Non-Primitive Types: String, Arrays, Classes, Objects Example: int age = 20; double salary =
45000.50; char grade = 'A'; boolean isPass = true; 4. Variables and Operators Variables store data
values. Operators perform operations on variables. int a = 10, b = 5; System.out.println(a + b); //
Arithmetic operator Types of Operators: Arithmetic: +, -, *, /, % Relational: ==, !=, >, <, >=, <=
Logical: &&, ||, ! Assignment: =, +=, -=, *=, /= 5. Control Statements Used for decision making. if
(age >= 18) { System.out.println("Adult"); } else { System.out.println("Minor"); } 6. Loops Used to
repeat code. for (int i = 1; i <= 5; i++) { System.out.println(i); } 7. Arrays Arrays store multiple values
of the same type. int[] numbers = {10, 20, 30, 40}; System.out.println(numbers[2]); // Output: 30 8.
Methods A method is a block of code that performs a specific task. void greet() {
System.out.println("Welcome to Java!"); } 9. Object-Oriented Programming (OOP) Java is based on
four OOP principles: Encapsulation: Wrapping data and code together. Inheritance: Reusing
code from another class. Polymorphism: Same function behaving differently. Abstraction: Hiding
details and showing essential features. Example: class Animal { void sound() {
System.out.println("Animal sound"); } } class Dog extends Animal { void sound() {
System.out.println("Bark"); } } 10. Input and Output import java.util.Scanner; class InputExample {
public static void main(String[] args) { Scanner sc = new Scanner(System.in);
System.out.print("Enter name: "); String name = sc.nextLine(); System.out.println("Hello, " + name);
} } 11. Exception Handling Used to handle runtime errors. try { int x = 10 / 0; } catch (Exception e) {
System.out.println("Error: " + e.getMessage()); } 12. Summary Java is a powerful and versatile
programming language that forms the foundation for many modern technologies like Android apps,
enterprise software, and web servers. End of Java Basics Notes