0% found this document useful (0 votes)
2 views7 pages

Java Unit1 Detailed Notes

Uploaded by

SWAROOPA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Java Unit1 Detailed Notes

Uploaded by

SWAROOPA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Unit 1: Object-Oriented Thinking & Java

Basics
Comprehensive Beginner Notes & Study Guide

Section 1: The Object-Oriented Paradigm

Need for the OOP Paradigm

Historically, software development relied on the Procedural or Structured Programming Paradigm (such
as in the C programming language). In procedural programming, a program is viewed as a series of linear
steps or a sequence of functions executing procedures on passive data sets. While highly efficient for smaller
systems, this approach degrades as software complexity scales. Data variables are frequently declared with
global scope, leaving them exposed to accidental, unauthorized modification by any detached function within
the codebase. Debugging becomes tedious, and code reusability is significantly restricted.

The Object-Oriented Programming (OOP) paradigm was formulated specifically to address these
architectural deficiencies. Instead of organizing software around structural execution loops, OOP architectures
center computer software around real-world domain objects. An object encapsulates state (attributes/data
fields) and programmatic capabilities (methods/functions) together as a cohesive operational unit, preventing
arbitrary access from external systems.

Coping with Complexity & Abstraction Mechanisms

Software engineering is inherently a process of managing escalating operational complexity. OOP handles
this problem through two primary mental frameworks:

• Decomposition: Dividing a massive monolithic system into distinct, self-contained, manageable domain
entities (e.g., rather than writing an entire multi-thousand-line billing routine, developers create independent
Invoice , Customer , and TaxCalculator objects).

• Abstraction Mechanisms: Managing detail by completely masking backend logic and operational
mechanics, exposing only an intuitive, clean interface.

Summary of Core OOP Concepts

The entire foundation of Object-Oriented Programming rests firmly upon four distinct structural pillars:

1. Encapsulation: The technical methodology of bundling data attributes and operational methods tightly
within a single structural module (the class) while limiting direct visibility via access modifiers. This creates
a protective boundary that enforces data integrity.

2. Abstraction: The process of highlighting what an object does while hiding how it achieves its output. For
example, a driver interfaces seamlessly with a car using the gas pedal (an abstract system tool) without
needing to understand fuel-injection hydraulics.

Unit 1: Java Basics & OOP Paradigm Page 1 of 7


3. Inheritance: An structural framework where an existing class (the subclass or child class) automatically
inherits fields and behavioral methods from a defined base class (the superclass or parent class),
drastically reducing redundancy and boosting code reuse.

4. Polymorphism: Derived from the Greek roots for "many forms," polymorphism lets a singular method
signature adapt its processing behavior dynamically based on the exact type of object currently invoking it
(e.g., a uniform draw() function rendering distinct geometries for a Circle versus a Square object).

Section 2: Java Fundamentals & Language Architecture

History of Java

Java was conceived in 1991 by a specialized team known as the Green Team, led by James Gosling,
Patrick Naughton, and Mike Sheridan at Sun Microsystems. Initially codenamed "Oak" and intended for
embedded consumer electronic microchips (like interactive television set-top boxes), the technology pivoted
rapidly to match the explosive growth of the early World Wide Web. Rebranded as Java, the language
launched publicly in 1995, highlighting cross-platform network deployment and rich browser interactivity.

The Java Buzzwords

The definitive Java Architectural White Paper lists several core characteristics, traditionally referred to as the
"Java Buzzwords":

• Simple: Designed with a clean syntax derived from C++, but explicitly strips out complex, hazardous
operations like direct pointer arithmetic and multiple class inheritance hierarchies.

• Secure: Executes code within a strict runtime sandbox ecosystem, preventing untrusted applications from
altering raw local system memory or damaging host filesystems.

• Portable & Architecture-Neutral: Adheres to the mantra "Write Once, Run Anywhere" (WORA). The Java
Compiler outputs an intermediate architectural language known as bytecode. This bytecode runs on any
computer operating system featuring a native Java Virtual Machine (JVM).

• Robust: Maximizes application safety by enforcing strict compile-time and runtime type checks, while
deploying automated memory validation safeguards.

• Object-Oriented: Modeled completely around real-world objects; nothing exists outside a class scope
except primitive tracking data types.

• Multithreaded: Features integrated, native support for multi-threaded programming, allowing software to
execute separate, concurrent background loops natively.

Data Types, Variables, and Memory Footprints

Java is a strictly, statically typed programming language. Every variable must have a explicitly declared type
before compile operations execute. Java features 8 Primitive Data Types managed directly within standard
execution registers:

Unit 1: Java Basics & OOP Paradigm Page 2 of 7


Category Type Size (Bytes) Default Value Value Range Allocation

Integer byte 1 0 -128 to 127

short 2 0 -32,768 to 32,767

int 4 0 -2³¹ to 2³¹-1

long 8 0L -2⁶³ to 2⁶³-1

Floating-Point float 4 0.0f Single-precision IEEE 754 float

double 8 0.0d Double-precision IEEE 754 float

Character char 2 '' 16-bit uniform Unicode character set

Logical boolean 1 bit false true or false literal values

Scope and Lifetime of Variables

In Java, variable tracking and physical memory lifetime are tightly bound to the enclosing curly braces {}
where they are instantiated:

• Class-Level Variables (Instance Fields): Declared directly within the class block but outside structural
methods. These are initialized upon object allocation on the heap and persist until the containing object is
purged by garbage collection.

• Local Variables: Instantiated within a specific method or loop scope block. They are allocated when
thread execution enters that block and are permanently wiped from the call stack when the block
completes.

Type Conversion and Casting

Type transitions in Java follow explicit widening and narrowing safety regulations:

// Widening (Automatic Type Conversion) - Low size to high capacity type


int baselineInteger = 45;
double comprehensiveDecimal = baselineInteger; // Safe conversion without data
degradation

// Narrowing (Explicit Cast Mandatory) - High size to low capacity type


double strictMeasurement = 194.89;
int truncatedInteger = (int) strictMeasurement; // Manual coercion; clips decimal
component to 194

Unit 1: Java Basics & OOP Paradigm Page 3 of 7


Section 3: Essential Programming Logic

Operators, Expressions, and Flow Structures

Java supports standard programming expressions using several operator types:

• Arithmetic Operators: + , - , * , / , and % (modulus calculation tracking remainder values).

• Relational Comparison Operators: == , != , < , > , <= , and >= .

• Logical Short-Circuit Operators: && (Conditional AND evaluation), || (Conditional OR evaluation),


and ! (Logical NOT inversion).

Control flow logic uses these structural statements:

// 1. Branch Selection (if-else)


if (academicScore >= 90) {
[Link]("Grade: Exceeded Baseline");
} else {
[Link]("Grade: Standard Pass");
}

// 2. Iterative Tracking Structure (for loop)


for (int step = 0; step < 3; step++) {
[Link]("Current step loop count: " + step);
}

Working with Arrays

An array is a fixed-length, contiguous sequence of memory locations holding uniform data elements. In Java,
arrays are treated as formal objects allocated on the heap rather than basic pointers.

// Array declaration, instantiation, and population


int[] examinationScores = new int[3];
examinationScores[0] = 98;
examinationScores[1] = 87;
examinationScores[2] = 91;

// Clean extraction using the modern enhanced for-each iteration structure


for (int specificScore : examinationScores) {
[Link]("Recorded data point: " + specificScore);
}

Unit 1: Java Basics & OOP Paradigm Page 4 of 7


Section 4: Object-Oriented Implementation Blueprint

Anatomy of a Simple Java Program

Below is a minimal executable Java application template. The class name must exactly match the source code
filename on disk:

// Main Application File: [Link]


public class ProgramStructure {
public static void main(String[] args) {
[Link]("Java compilation pipeline successfully validated.");
}
}

Classes, Objects, Constructors, and Methods

A Class serves as an architectural blueprint or abstract template mapping out common fields and capabilities.
An Object is a live, individual instance of that class template allocated on the system heap. A Constructor is
a specialized code block designed to initialize the newly created object instance. It shares the exact name of
the parent class, does not specify a return type, and runs automatically when the new operator runs.

class CustomerAccount {
private String clientName;
private double currentBalance;

// Class Constructor with naming collision management via 'this'


public CustomerAccount(String clientName, double currentBalance) {
[Link] = clientName; // 'this' isolates the class variable
from the parameter
[Link] = currentBalance;
}

// Behavioral Method
public void processDeposit(double transactionAmount) {
[Link] += transactionAmount;
}
}

Access Control Modifiers

Access specifiers implement encapsulation by restricting method visibility outside the parent package or class
architecture:

Unit 1: Java Basics & OOP Paradigm Page 5 of 7


Enclosing Containing Derived Global
Modifier Specifier
Class Package Subclass Context

private Yes No No No

default (no
Yes Yes No No
keyword)

protected Yes Yes Yes No

public Yes Yes Yes Yes

Critical Concept: Method Overloading


Method overloading occurs when multiple methods within the same class share identical names but
feature different parameter lists (differing in signature count, sequencing, or literal data configurations).
The return type alone cannot differentiate overloaded methods.

Parameter Passing: Call-by-Value

A crucial rule for Java beginners is that Java is exclusively a Call-by-Value language. It never passes
arguments by reference. When passing a primitive type, Java clones the value into a new stack variable.
Modifications made inside the method stay local to that method. When passing an object reference, Java
copies the memory address handle. While changes to the object's fields affect the original object on the heap,
reassigning the reference pointer inside the method does not change the caller's original object pointer.

Garbage Collection Basics

Unlike languages like C/C++ that require manual memory reclamation, Java automates memory cleanup. The
JVM runs an internal background routine called the Garbage Collector (GC). The GC regularly scans heap
memory blocks to find objects that are no longer reachable by any active thread execution paths. Once
verified as unreachable, their memory blocks are automatically reclaimed for future processing loops.

Section 5: Advanced Java Structures

Recursion, Nested Classes, and Strings

Recursion is an algorithmic pattern where a method repeatedly calls itself to resolve a large problem by
breaking it into smaller, bite-sized tasks, running until a terminal base condition is met:

Unit 1: Java Basics & OOP Paradigm Page 6 of 7


public class CalculationEngine {
public static int computeFactorial(int value) {
if (value <= 1) return 1; // Base Guard Condition
return value * computeFactorial(value - 1); // Recursive Step
}
}

Java also supports defining a class within another class block, known as Nested or Inner Classes, logically
grouping connected structures together:

class ExternalSystem {
private String proprietaryKey = "SYS_KEY_TOKEN";

class InternalWorker {
void printAccess() {
// Inner classes can read private elements of the enclosing outer class
[Link]("Processing secure key: " + proprietaryKey);
}
}
}

Exploring the String Class & Immutability

In Java, strings are treated as full object instances of the [Link] class rather than simple
character arrays. Strings are strictly immutable; once an alphanumeric sequence is constructed on the heap,
its literal character order cannot be modified. Any operations that appear to change a string actually instantiate
a completely new string object behind the scenes.

To reduce memory footprint, the JVM runs a specialized storage reservoir called the String Constant Pool
(SCP):

// String references matching literal sequences share reference space inside the pool
String stringRefA = "CoreData";
String stringRefB = "CoreData";
[Link](stringRefA == stringRefB); // Evaluates to true (same memory
pointer)

// Instantiating a completely distinct memory footprint outside the pool


String distinctString = new String("CoreData");
[Link](stringRefA == distinctString); // Evaluates to false (different
pointers)

// CRITICAL BEST PRACTICE: Always evaluate string values using .equals(), never with
==
[Link]([Link](distinctString)); // Evaluates to true (matching
text)

Unit 1: Java Basics & OOP Paradigm Page 7 of 7

You might also like