Posts

Showing posts from August, 2025

Understanding OOP -Inheritance, Polymorphism, Encapsulation

  1. Quick Recap: What is OOP? OOP (Object-Oriented Programming) is about designing programs around objects that have data (attributes) and behaviors (methods) . Main OOP principles: Inheritance – Reuse code from one class in another Polymorphism – One method, many forms Encapsulation – Protect data by controlling access Abstraction – Hide implementation details (covered later) 2. Access Modifiers in Java Access modifiers control visibility of classes, methods, and variables. Modifier Access Level public Accessible from anywhere protected Accessible in same package and subclasses default (no keyword) Accessible in same package only private Accessible only inside the same class 3. Inheritance – Reusing Code Inheritance allows one class ( child/subclass ) to get properties and methods from another class ( parent/superclass ). Example: class Vehicle { public void start () { System.out.println( "Vehicle is starting..." ); } } ...

Java for Beginners – Functions & Object-Oriented Basics

  1. What are Functions (Methods) in Java? A function (in Java we call it a method ) is a block of code that performs a specific task. Instead of repeating code, you write it once inside a method and call it whenever you need it. Example: public static void greet () { System.out.println( "Hello! Welcome to Java." ); } 2. Why Use Methods? ✅ Reusability – Write once, use many times ✅ Cleaner code – Easier to read & maintain ✅ Better structure – Breaks big programs into smaller parts 3. Syntax of a Method accessModifier returnType methodName (parameters) { // method body return value; // only if returnType is not void } Example: public static int add ( int a, int b) { return a + b; } 4. Calling a Method public class Example { public static void greet () { System.out.println( "Hello!" ); } public static void main (String[] args) { greet(); // method call } } 5. Methods wit...

Java for Beginners – Control Flow in Java Decisions & Loops

  1. What is Control Flow? Control flow decides which part of your code runs and how many times it runs. It’s like giving your program the ability to make choices and repeat tasks. There are two main types : Decision-making statements (if-else, switch) Looping statements (for, while, do-while) 2. Decision-Making Statements A) if Statement Runs code only if the condition is true. int age = 20 ; if (age >= 18 ) { System.out.println( "You are an adult." ); } B) if-else Statement Chooses between two options. if (age >= 18 ) { System.out.println( "Adult" ); } else { System.out.println( "Minor" ); } C) if-else-if Ladder Chooses between multiple options. int marks = 85 ; if (marks >= 90 ) { System.out.println( "Grade A" ); } else if (marks >= 75 ) { System.out.println( "Grade B" ); } else if (marks >= 50 ) { System.out.println( "Grade C" ); } else { ...

Getting Started with Java – Setup & Your First Program

  1. Introduction – Why Java? Java is one of the most popular programming languages in the world. It’s used to create: Mobile Apps (especially Android) Web Applications Desktop Software Games Enterprise-level applications Why beginners love Java: Platform Independent – Code runs anywhere ( Write Once, Run Anywhere ). Easy to Learn – Syntax is simple and close to English. Huge Community – Tons of tutorials, forums, and help available. 2. How Java Works (In Simple Words) When you write Java code: You write source code → HelloWorld.java Compiler converts it into Bytecode → HelloWorld.class Java Virtual Machine (JVM) runs the bytecode on any OS This is why Java runs on Windows, Mac, Linux, and Android without changes. 3. Setting Up Java on Your Computer Step 1: Install Java JDK (Java Development Kit) Download from Oracle JDK or OpenJDK . Install it like a normal software. Check installation: java -version If it shows a...