Types of Arrays

📊 Types of Arrays in Java Arrays in Java can be classified into two types: Single-Dimensional Arrays and Multidimensional Arrays. Both types store elements of the same data type, but their structure differs. 🧑‍🏫 1. Single-Dimensional Arrays A single-dimensional array is a linear list of elements, where each element is accessed via its index. 🔹 Example int[] numbers = {10, 20, 30, 40, 50}; System.out.println("Element at index 2: " + numbers[2]); // Output: 30 🔹 Declaring and Initializing int[] arr = new int[5]; // Declaring with fixed size arr[0] = 1; // Assigning values 📐 2. Multidimensional Arrays Multidimensional arrays are arrays of arrays. A 2D array is the most common, where each element is itself an array. ...

May 8, 2025 · 2 min · Rohan

Arrays

🧑‍💻 Arrays in Java An array is a data structure in Java that stores multiple values of the same type in a single variable. It provides a way to group variables under a single name, making it easier to manage and manipulate data. 🌱 Declaring and Initializing Arrays Declaring an Array Syntax: dataType[] arrayName; int[] arr; // Declaration 2. **Initializing an Array** * **Static Initialization**: Assigning values at the time of declaration. ```java int[] arr = {1, 2, 3, 4, 5}; // Initialization Dynamic Initialization: Assigning values later. int[] arr = new int[5]; // Creates an array of size 5 arr[0] = 1; // Assign values arr[1] = 2; 🚀 Example: Using Arrays public class ArraysExample { public static void main(String[] args) { int[] numbers = {10, 20, 30, 40, 50}; // Accessing array elements System.out.println("First Element: " + numbers[0]); // Iterating over array for (int i = 0; i < numbers.length; i++) { System.out.println("Element at index " + i + ": " + numbers[i]); } } } 🔍 Multidimensional Arrays Java also supports arrays with multiple dimensions, like 2D arrays. ...

May 8, 2025 · 2 min · Rohan

Program Control Statements

🔄 Program Control Statements in Java Control statements in Java allow you to dictate the flow of execution in your program. They can be broadly categorized into conditional, looping, and branching statements. 🧠 Types of Control Statements Conditional Statements if, else, else if: Used to make decisions in code. int a = 10, b = 20; if (a > b) { System.out.println("a is greater"); } else { System.out.println("b is greater"); } 2. **Switch Statement** * Used for multiple condition checks, simplifying `if-else if` chains. ```java int day = 3; switch (day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; default: System.out.println("Invalid day"); } Looping Statements ...

May 8, 2025 · 2 min · Rohan

Operators

➗ Operators in Java In Java, operators are special symbols used to perform operations on variables and values. Java has a rich set of operators that can be categorized into several types. 🧮 Types of Operators in Java Arithmetic Operators +, -, *, /, % Used to perform mathematical operations. Relational Operators ==, !=, >, <, >=, <= Used to compare two values. Logical Operators &&, ||, ! Used to perform logical operations (AND, OR, NOT). Assignment Operators ...

May 8, 2025 · 2 min · Rohan

Variables

📊 Variables in Java In Java, variables are used to store data that can be used later in the program. Each variable has a data type and is associated with a name that can be used to reference the value it holds. 🧠 Types of Variables in Java Instance Variables Declared inside a class but outside any method. Associated with an object instance. Local Variables Declared inside a method, constructor, or block. Exist only within the scope of the method/block. Static Variables (Class Variables) ...

May 8, 2025 · 1 min · Rohan

Data Types

🔢 Data Types in Java Java is a strongly typed language, meaning each variable must be declared with a specific data type. Java supports two main categories of data types: primitive and reference types. 🏷️ Primitive Data Types Java has eight primitive data types, each with a specific size and value range: byte – 1 byte, range: -128 to 127 short – 2 bytes, range: -32,768 to 32,767 int – 4 bytes, range: -2^31 to 2^31-1 long – 8 bytes, range: -2^63 to 2^63-1 float – 4 bytes, single-precision floating point double – 8 bytes, double-precision floating point char – 2 bytes, represents a single character boolean – 1 bit, either true or false 🧱 Reference Data Types Reference types are objects, arrays, or any other instance of a class. They do not hold the actual data but refer to the memory location where the data is stored. ...

May 8, 2025 · 2 min · Rohan

Command Line Arguments

🧾 Command Line Arguments in Java Command Line Arguments allow users to pass input parameters to the program when it is executed, enabling dynamic behavior without changing code. 🧠 Concept Java’s main() method accepts an array of String arguments: public static void main(String[] args) args holds the command line values as strings. args[0], args[1], etc. refer to individual arguments. 🧪 Example public class CmdArgs { public static void main(String[] args) { System.out.println("Number of arguments: " + args.length); for (int i = 0; i < args.length; i++) { System.out.println("Arg " + i + ": " + args[i]); } } } 🔹 Running the program: java CmdArgs Alice Bob 🔹 Output: Number of arguments: 2 Arg 0: Alice Arg 1: Bob ⚠️ Notes All inputs are read as String. You must parse them (e.g., Integer.parseInt()) if needed. Handle cases when arguments are missing to avoid ArrayIndexOutOfBoundsException. 🔗 Related Notes Input Output Statements Features of Java

May 8, 2025 · 1 min · Rohan

Input Output Statements

🖨️ Input/Output Statements in Java Java provides various mechanisms to accept input from the user and display output to the screen, typically using classes from the java.io and java.util packages. 📥 Input in Java The most common way to accept user input is through the Scanner class. 🔹 Example Using Scanner import java.util.Scanner; public class InputExample { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter your name: "); String name = sc.nextLine(); System.out.println("Hello, " + name); } } 📤 Output in Java Java uses System.out.println() and System.out.print() for output. ...

May 8, 2025 · 1 min · Rohan

Features of Java

🚀 Features of Java Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. 🌟 Key Features of Java Simple – Easy to learn, especially if you’re familiar with C/C++. Object-Oriented – Everything is treated as an object (except primitives). Platform-Independent – Write Once, Run Anywhere (WORA) using the JVM. Secure – Provides bytecode verification and runtime security features. Robust – Strong memory management, exception handling, type checking. Multithreaded – Supports concurrent execution of two or more threads. Architecture-Neutral – Bytecode is not dependent on any specific processor. Portable – Java programs can run on any system with the JVM. High Performance – Just-In-Time (JIT) compiler boosts performance. Distributed – Built-in support for networking and RMI. Dynamic – Loads classes at runtime, supports dynamic linking. 🧪 Code Snippet: Basic Java Structure public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, Java!"); } } 🎯 Summary Java’s design makes it ideal for web, enterprise, mobile, and embedded systems. Its features have helped it remain one of the most widely used languages in the world. ...

May 8, 2025 · 1 min · Rohan

Object Oriented Programming Principles

🧠 Object Oriented Programming Principles Object-Oriented Programming (OOP) is based on four core principles that guide how we design software around real-world objects. 🔑 The Four Core Principles Encapsulation Hides internal details and exposes only what’s necessary. Inheritance Allows a class to inherit methods and properties from another class. Polymorphism Enables a single interface to operate on different types. Abstraction Focuses on essential characteristics, hiding implementation. 🎯 Goals of These Principles Improve modularity Enhance code reuse Simplify maintenance Align software design with real-world modeling 🧪 Java in Action interface Vehicle { void start(); } class Car implements Vehicle { public void start() { System.out.println("Car started"); } } This example combines: ...

May 8, 2025 · 1 min · Rohan