0% found this document useful (0 votes)
17 views41 pages

JAVA_-_UNIT_1

The document provides an introduction to Java, covering its history, key features, and how to get started with programming in Java. It explains the differences between Java applications and applets, the concept of variables, operators, data types, tokens, and the rules for keywords, identifiers, and literals. The content is structured into sections that detail the fundamental aspects of Java programming, making it suitable for beginners.

Uploaded by

SS GAMER
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)
17 views41 pages

JAVA_-_UNIT_1

The document provides an introduction to Java, covering its history, key features, and how to get started with programming in Java. It explains the differences between Java applications and applets, the concept of variables, operators, data types, tokens, and the rules for keywords, identifiers, and literals. The content is structured into sections that detail the fundamental aspects of Java programming, making it suitable for beginners.

Uploaded by

SS GAMER
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
You are on page 1/ 41

1️⃣

JAVA - UNIT 1
Summary of Page 1 (Unit-I: Introduction to Java)

1.1 History of Java


Origins: Developed by James Gosling and team at Sun Microsystems in the
early 1990s. Initially designed for programming consumer electronics.

Java 1.0 (1996): First official version. Famous for "Write Once, Run Anywhere"
capability—Java programs can run on any platform with a Java Virtual
Machine (JVM).

Acquisition by Oracle (2010): Oracle acquired Sun Microsystems, taking


ownership of Java.

Java 8 (2014): Introduced significant features like lambda expressions, Stream


API, and the java.time package for date and time.

Java 9 and beyond: Newer versions include modularity in Java 9 and long-
term support (LTS) starting with Java 11.

1.2 Key Features of Java


Platform Independence: Java code compiles into bytecode, which can run on
any system with a JVM.

Object-Oriented: Supports principles like inheritance, encapsulation,


polymorphism.

Strongly Typed: Data types are strictly enforced to prevent errors at compile-
time.

Automatic Memory Management: Java handles memory using garbage


collection.

Security: Includes built-in security features to prevent malicious code.

Rich Standard Library: Offers a vast set of libraries for tasks like I/O,
networking, and data structures.

Multi-threading: Supports running multiple threads simultaneously.

Exception Handling: Provides mechanisms to handle runtime errors


gracefully.

1.3 Getting Started with Java


1. Install Java: Download and install the Java Development Kit (JDK).

2. Choose an IDE: Common Java IDEs are Eclipse, IntelliJ IDEA, and NetBeans.

3. Write Your First Program: Example:

JAVA - UNIT 1 1
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

4. Compile and Run: Use the javac command to compile and the java command
to run the program.

5. Learn Basics: Focus on variables, data types, operators, control structures,


and functions.

6. Explore Advanced Topics: Move to advanced concepts like object-oriented


programming, exception handling, and multithreading.

7. Practice: Hands-on coding and exercises help reinforce learning.

8. Use Documentation: Refer to online resources and books for deeper


understanding.

Summary of Page 2 (Java Programs: Applications and Applets)

What is a Java Application?


A Java application is a standalone program that runs on an operating system
supported by the Java Virtual Machine (JVM).

Java applications don’t necessarily need a graphical user interface (GUI); they
can run without it.

Features of Java Applications:

Can run independently without a web browser.

Requires a main() method to execute.

Full access to local file systems and networks.

Suitable for performing tasks directly on the system.

What is a Java Applet?


A Java applet is a small Java program embedded in a web page and runs
inside a web browser.

Applets were popular for adding interactive content to websites, but their use
has diminished with the rise of modern web technologies.

Features of Java Applets:

Applets don’t need a main() method.

Require a web browser to execute.

Limited access to the local system for security reasons.

Primarily used for small tasks or as part of a web page.

JAVA - UNIT 1 2
Summary of Page 3 (Variables in Java)

What is a Variable?
A variable is a memory location used to store data, which can change during
program execution.

Variables must be declared before use.

They are essentially names for reserved memory locations that can hold
different types of data.

3.1 How to Declare a Variable


Syntax: data_type variable_name;

data_type : The type of data the variable will hold (e.g., int , String ).

variable_name : The name of the variable.

Example:

int age;

3.2 How to Initialize a Variable


Syntax: data_type variable_name = value;

You assign an initial value to the variable at the time of declaration.

Example:

int age = 20;

3.3 Scope and Lifetime of Variables


Scope: The part of the program where the variable can be accessed.

A variable cannot be used before it is declared.

Lifetime: The time during which a variable exists in memory.

Once the variable goes out of scope, its memory is released.

3.4 Scope vs Lifetime in Java


Scope determines where you can access the variable.

Method scope: Variables inside a method are accessible only within that
method (local variables).

Class scope: Instance variables are accessible throughout the class.

Lifetime refers to how long a variable occupies memory.

Local variables last until the method finishes.

Instance variables last as long as the object exists.

JAVA - UNIT 1 3
3.5 Naming Conventions for Variables
Variables are case-sensitive.

money , Money , and MONEY are all different variables.

Variable names cannot contain spaces or special symbols (e.g., @ , # ).

Allowed special characters: $ and _ .

Conventions:

Start variable names with a lowercase letter.

Use camelCase for multiple-word variables (e.g., smallNumber ).

3.6 Types of Variables in Java


1. Local Variables:

Declared inside a method and accessible only within that method.

Must be initialized before use.

Example:

int age = 30;

2. Instance Variables:

Declared inside a class but outside methods, constructors, or blocks.

They belong to an instance of the class.

Default initialization happens (e.g., 0 for integers).

Example:

int marks;

3. Static Variables (Class Variables):

Declared with the static keyword.

Shared among all instances of a class.

Example:

static double salary;

Summary of Page 4 (Operators in Java)

What is an Operator?
An operator is a symbol used to perform operations on variables or values.

Example: In 2 + 3 = 5 , + is the operator, and 2 and 3 are operands.

Types of Operators in Java

JAVA - UNIT 1 4
1. Arithmetic Operators: Used for mathematical operations.

Addition ( + ), Subtraction ( ), Multiplication ( ), Division ( / ), Modulus


( % ).

Example:

int a = 10;
int b = 5;
int sum = a + b; // 15

2. Assignment Operators: Used to assign values to variables.

Simple assignment ( = ), compound assignment (e.g., += , = , = , /= , %= ).

Example:

int a = 10;
a += 5; // a = a + 5; Result: a = 15

3. Relational Operators: Compare two values and return a boolean ( true or


false ).

Equal to ( == ), Not equal to ( != ), Greater than ( > ), Less than ( < ), Greater
than or equal to ( >= ), Less than or equal to ( <= ).

Example:

int a = 10, b = 20;


boolean result = a > b; // false

4. Logical Operators: Used to combine multiple conditions.

AND ( && ), OR ( || ), NOT ( ! ).

Example:

boolean a = true, b = false;


boolean result = a && b; // false

5. Bitwise Operators: Operate on binary digits of integers.

AND ( & ), OR ( | ), XOR ( ^ ), NOT ( ~ ).

Example:

int a = 12; // 1100 in binary


int b = 5; // 0101 in binary
int result = a & b; // 0100 (4 in decimal)

6. Unary Operators: Work with a single operand to perform various operations.

Increment ( ++ ), Decrement ( - ), Unary minus ( ), Unary plus ( + ),


Logical NOT ( ! ).

JAVA - UNIT 1 5
Example:

int a = 5;
a++; // a becomes 6

7. Shift Operators: Shift the bits of a number.

Left Shift ( << ), Right Shift ( >> ), Unsigned Right Shift ( >>> ).

Example:

int a = 10; // 1010 in binary


int result = a << 2; // 101000 (40 in decimal)

8. Ternary Operator: A shorthand for the if-else statement.

Syntax: condition ? value_if_true : value_if_false .

Example:

int a = 10, b = 20;


int max = (a > b) ? a : b; // Result: max = 20

Operator Precedence
Determines the order in which operators are evaluated.

Multiplication and division have higher precedence than addition and


subtraction.

Parentheses can be used to override the default precedence.

Summary of Page 5 (Data Types in Java)

What is a Data Type?


A data type defines:

1. The size of the memory location.

2. The range of data that can be stored.

3. The operations that can be performed on the data.

4. The result of operations involving the data type.

Classification of Data Types


Data types in Java are categorized into two types:

1. Primitive Data Types: Basic types like integers, floating-point numbers,


characters, and boolean.

2. Non-Primitive Data Types: More complex types like arrays, classes, and
interfaces.

5.1 Primitive Data Types

JAVA - UNIT 1 6
Primitive data types hold a single value and include:

1. Integer Types:

byte: 8-bit, range from -128 to 127.

short: 16-bit, range from -32,768 to 32,767.

int: 32-bit, range from -2^31 to 2^31-1 (commonly used).

long: 64-bit, range from -2^63 to 2^63-1.

Example:

int number = 100;


long largeNumber = 100000L;

2. Floating-Point Types (for decimal values):

float: 32-bit single-precision floating point.

double: 64-bit double-precision floating point.

Example:

float pi = 3.14f;
double bigDecimal = 123456.789;

3. Character Type:

char: 16-bit, used for storing characters using Unicode.

Example:

char letter = 'A';

4. Boolean Type:

boolean: Can hold only two values: true or false .

Example:

boolean isJavaFun = true;

5.2 Non-Primitive Data Types


Non-primitive data types include arrays, classes, and interfaces.

These are more complex data structures used to store multiple values or
objects.

Data Type Table:


Data Type Size Range Example

byte 8-bit -128 to 127 byte b = 10;

short 16-bit -32,768 to 32,767 short s = 1000;

JAVA - UNIT 1 7
int 32-bit -2^31 to 2^31-1 int i = 50000;

long l =
long 64-bit -2^63 to 2^63-1 100000L;

IEEE 754 single-precision floating


float 32-bit float f = 3.14f;
point

IEEE 754 double-precision


double 64-bit double d = 1.23;
floating point

char 16-bit '\u0000' to '\uffff' (0 to 65,535) char c = 'A';

boolean b =
boolean 1-bit true or false true;

This table summarizes the most common primitive data types in Java along with
their size, range, and examples of usage.

Summary of Page 6 (Tokens in Java)

What is a Token?
A token is the smallest unit in a Java program. It is the basic building block
used to write code.

Examples of tokens include keywords, identifiers, literals, operators, and


special symbols.

Types of Tokens in Java


1. Keywords: Reserved words defined by the language, such as int , float ,
class , etc. Keywords cannot be used as variable names.

Example: int , public , class .

Note: Java has 50 keywords.

2. Identifiers: Names used to identify variables, methods, classes, etc. Identifiers


must follow specific rules:

They can contain alphabets, digits, $ , and _ , but cannot start with a digit
or contain spaces.

Must not match Java keywords.

Examples: myVar , Employee , calculateSum .

3. Literals: Fixed values assigned to variables. They represent constants in the


code.

Types of literals:

Integer literal: int a = 10;

Floating-point literal: float f = 3.14f;

Character literal: char c = 'A';

String literal: String s = "Hello";

Boolean literal: boolean b = true;

4. Operators: Symbols that perform operations on variables or values.

JAVA - UNIT 1 8
Examples: + , , , / , = , && .

5. Special Symbols/Separators: Used to structure and separate code elements.

Examples:

Braces: {} (used to define blocks of code).

Parentheses: () (used in method calls or control statements).

Semicolon: ; (marks the end of a statement).

Example of Tokens in Java:

public class Example { // 'public', 'class', 'Exampl


e', '{' are tokens
public static void main(String[] args) { // 'public',
'static', 'void' are tokens
int number = 10; // 'int', 'number', '=', '10'
are tokens
System.out.println("Hello, World!"); // 'System',
'out', '.', 'println', '("Hello, World!")' are tokens
}
}

Token Summary Table:


Token Type Description Example

Keyword Reserved words defined by Java int , class

Identifier Name of variable, method, class, etc. myVariable

Literal Constant value assigned to a variable 10 , true

Operator Symbols that perform operations + , = , &&

Special Symbol Separators and symbols used in structuring code {} , () , ;

These five token types are the foundation of all Java programs, making up the
building blocks that the Java compiler uses to interpret the code.

Summary of Page 7 (Keywords, Identifiers, and Literals)

6.1 Keywords
Keywords are reserved words predefined by the Java language, which cannot
be used as identifiers (names for variables, methods, etc.).

All keywords in Java are written in lowercase.

Java has 50 keywords like int , float , class , static , void , etc.

Example:

int number = 10; // 'int' is a keyword

JAVA - UNIT 1 9
6.2 Identifiers
Identifiers are names given to variables, methods, classes, etc.

Rules for Identifiers:

Can contain letters (a-z, A-Z), digits (0-9), $ , and _ .

Cannot start with a digit or contain spaces.

Must not match any Java keyword.

No limit on the length of the identifier.

Example of valid identifiers:

$technoname , tech_21

Example of invalid identifiers:

tech no (contains a space), 33tech (starts with a digit), float

(keyword).

Example:

int myVar = 100; // 'myVar' is a valid identifier

6.3 Literals
Literals are constant values directly used in the program.

Types of literals:

1. Integer Literals: Whole numbers.

Example: int num = 10;

2. Floating-point Literals: Numbers with decimal points.

Example: float pi = 3.14f;

3. Character Literals: Single characters enclosed in single quotes.

Example: char ch = 'A';

4. String Literals: Sequence of characters enclosed in double quotes.

Example: String name = "Java";

5. Boolean Literals: Represents true or false .

Example: boolean isJavaFun = true;

Example of Keywords, Identifiers, and Literals:

public class Example { // 'public', 'class' are keywords, 'E


xample' is an identifier
int age = 30; // 'int' is a keyword, 'age' is an id
entifier, '30' is a literal
String name = "John"; // 'String' is an identifier, "Joh

JAVA - UNIT 1 10
n" is a string literal
}

Summary Table:
Term Description Example

Keyword Reserved word that cannot be used as an identifier int , class

Identifier Name for a variable, class, method, etc. myVar , age

Literal Fixed constant value used in the program 10 , "Java"

These three elements—keywords, identifiers, and literals—form the foundation


of Java syntax, allowing you to define variables, classes, and constants in your
programs.

Summary of Page 8 (Operators in Java)

6.4 Operators
Operators in Java are special symbols used to perform operations on
variables and values.

They can be categorized into several types based on their functionality:

Types of Operators
1. Arithmetic Operators: Used for mathematical calculations.

Symbols: + , , , / , %

Examples:

int a = 10, b = 5;
int sum = a + b; // sum = 15
int difference = a - b; // difference = 5
int product = a * b; // product = 50
int quotient = a / b; // quotient = 2
int remainder = a % b; // remainder = 0

2. Assignment Operators: Used to assign values to variables.

Symbols: = , += , = , = , /= , %=

Examples:

int x = 10; // simple assignment


x += 5; // x = x + 5; (x becomes 15)
x -= 3; // x = x - 3; (x becomes 12)

3. Relational Operators: Used to compare two values, returning true or false .

Symbols: == , != , < , > , <= , >=

Examples:

JAVA - UNIT 1 11
int a = 10, b = 20;
boolean result1 = (a == b); // false
boolean result2 = (a < b); // true

4. Logical Operators: Used to combine multiple boolean expressions.

Symbols: && , || , !

Examples:

boolean a = true, b = false;


boolean result1 = (a && b); // false
boolean result2 = (a || b); // true
boolean result3 = !a; // false

5. Bitwise Operators: Operate on bits and perform bit-level operations.

Symbols: & , | , ^ , ~

Examples:

int a = 5; // 0101 in binary


int b = 3; // 0011 in binary
int result1 = a & b; // 0001 (1 in decimal)
int result2 = a | b; // 0111 (7 in decimal)

6. Unary Operators: Operate on a single operand.

Symbols: ++ , - , , + , !

Examples:

int a = 10;
int increment = ++a; // a becomes 11
int decrement = --a; // a becomes 10 again

7. Shift Operators: Used to shift bits to the left or right.

Symbols: << , >> , >>>

Examples:

int a = 10; // 1010 in binary


int leftShift = a << 2; // 00101000 (40 in decimal)
int rightShift = a >> 2; // 00000010 (2 in decimal)

8. Ternary Operator: A shorthand for the if-else statement.

Syntax: condition ? expression_if_true : expression_if_false

Example:

JAVA - UNIT 1 12
int a = 10, b = 20;
int max = (a > b) ? a : b; // max = 20

Summary of Operators Table:

Operator Type Description Examples

Arithmetic Basic mathematical operations +, -, *, /, %

Assignment Assigns values to variables = , += , -=

Relational Compares two values == , != , < , >

Logical Combines boolean expressions && , `

Bitwise Operates on bits &,`

Unary Operates on a single operand ++ , -- , - , !

Shift Shifts bits left or right << , >> , >>>

Ternary Shorthand for if-else condition ? true : false

Operators are fundamental in programming as they enable various types of


calculations and comparisons, forming the basis of expressions in Java.

Summary of Page 9 (Operator Precedence and Associativity in


Java)

4.9 Operator Precedence


Operator precedence determines the order in which operators are evaluated
in expressions.

Operators with higher precedence are evaluated before those with lower
precedence.

For example, in the expression 1 + 2 * 3 , the multiplication is performed first,


resulting in 1 + (2 * 3) .

Precedence Order
Here’s a simplified list of operator precedence from highest to lowest:

Precedence Level Operator Type Operators

1 Parentheses ()

2 Postfix Increment/Decrement ++ , --

3 Unary Increment/Decrement ++ , -- , - , + , ! , ~

4 Type Cast, New Operator () , new

5 Multiplicative *, /, %

6 Additive +, -

7 Shift << , >> , >>>

8 Relational < , <= , > , >= , instanceof

9 Equality == , !=

JAVA - UNIT 1 13
10 Bitwise AND &

11 Bitwise XOR ^

12 Bitwise OR `

13 Logical AND &&

14 Logical OR `

15 Ternary Operator ?:

16 Assignment = , += , -= ...

4.9.1 Associativity
Associativity determines the order of evaluation when two operators of the
same precedence appear in an expression.

Most operators in Java are left-to-right associative, meaning they are


evaluated from left to right.

Example: In the expression a - b + c , it is evaluated as ((a - b) + c) .

However, some operators like the assignment operator ( = ) and the ternary
operator ( ?: ) are right-to-left associative.

Example: In the expression x = y = z = 17 , it is evaluated as x = (y = (z =

17)) .

Summary Table of Precedence and Associativity


Operator Type Description Precedence Level Associativity

Parentheses Grouping expressions Highest Left to Right

Postfix Increment/Decrement (postfix) 2nd Not Associative

Unary Increment/Decrement (unary) 3rd Right to Left

Multiplicative *, /, % 5th Left to Right

Additive +, - 6th Left to Right

Shift << , >> , >>> 7th Left to Right

Relational < , <= , > , >= , instanceof 8th Left to Right

Equality == , != 9th Left to Right

Bitwise &, ^,` ` 10th to 12th

Logical && , ` `

Ternary ?: 15th Right to Left

Assignment = , += , -= ... Lowest Right to Left

Understanding operator precedence and associativity is crucial for writing correct


expressions and avoiding unintended results in Java programs.

Summary of Page 10 (Data Types in Java)

5. DATA TYPES

JAVA - UNIT 1 14
Data types specify the type of data that can be stored in a variable, the
operations that can be performed on that data, and the size of memory
allocation.

5.1 Primitive Data Types


Java has eight primitive data types that are built into the language. These are:

Data Type Size Range Example

byte 8-bit -128 to 127 byte b = 10;

short s =
short 16-bit -32,768 to 32,767 1000;

int 32-bit -2,147,483,648 to 2,147,483,647 int i = 50000;

-9,223,372,036,854,775,808 to long l =
long 64-bit 100000L;
9,223,372,036,854,775,807
float f =
float 32-bit Single-precision floating point 3.14f;

double d =
double 64-bit Double-precision floating point 1.23;

Unicode characters, range from


char 16-bit char c = 'A';
'\u0000' to '\uffff'
boolean b =
boolean 1-bit true or false
true;

Primitive Data Types Explained


1. Integer Types:

Used for whole numbers.

byte: Smallest integer type (8 bits).

short: Medium size integer (16 bits).

int: Commonly used integer type (32 bits).

long: Large integer type (64 bits).

2. Floating-point Types:

Used for numbers with decimal points.

float: 32-bit single precision.

double: 64-bit double precision (more accurate than float).

3. Character Type:

char: Represents a single 16-bit Unicode character.

4. Boolean Type:

boolean: Represents a value of either true or false .

5.2 Non-Primitive Data Types


Non-primitive data types are more complex data structures and include:

Classes: User-defined data types that represent real-world entities.

JAVA - UNIT 1 15
Interfaces: Abstract types that represent a contract of methods.

Arrays: Collections of elements of the same type.

Summary
Understanding data types is essential for effective programming in Java. It
helps in memory management, data manipulation, and determining the
operations you can perform on different types of data. Java is a strongly
typed language, meaning variables must be declared with a data type before
they can be used.

Example of Data Types in Java:

public class DataTypeExample {


public static void main(String[] args) {
int age = 30; // int
double salary = 50000.50; // double
char grade = 'A'; // char
boolean isEmployed = true; // boolean

System.out.println("Age: " + age);


System.out.println("Salary: " + salary);
System.out.println("Grade: " + grade);
System.out.println("Employed: " + isEmployed);
}
}

This example demonstrates the declaration and initialization of different primitive


data types in Java.

Summary of Page 11 (Continued: Data Types in Java)

5.3 Non-Primitive Data Types Explained


Non-primitive data types can hold multiple values and are created using
primitive data types and/or other non-primitive data types.

1. Classes:

A class is a blueprint for creating objects. It can contain fields (variables)


and methods (functions).

Example:

public class Person {


String name; // Field
int age; // Field

// Method
void displayInfo() {
System.out.println("Name: " + name + ", Age: "

JAVA - UNIT 1 16
+ age);
}
}

2. Interfaces:

An interface is a reference type similar to a class but is a collection of


abstract methods (methods without a body). A class that implements an
interface must provide the implementation for all of its methods.

Example:

public interface Animal {


void makeSound(); // Abstract method
}

public class Dog implements Animal {


public void makeSound() {
System.out.println("Bark");
}
}

3. Arrays:

An array is a collection of elements of the same type, stored in a single


variable. Arrays can hold primitive types and objects.

Example:

int[] numbers = {1, 2, 3, 4, 5}; // Array of integers


String[] fruits = {"Apple", "Banana", "Cherry"}; // Arr
ay of strings

5.4 String Data Type


In Java, a string is an object that represents a sequence of characters. Strings
are non-primitive and can be created using the String class.

Example:

String greeting = "Hello, World!";


System.out.println(greeting);

Summary of Data Types


Java provides a rich set of data types for developers to use based on the
requirements of their programs.

Primitive Data Types: Basic types that represent single values.

Non-Primitive Data Types: Complex types that can represent collections of


values or objects.

JAVA - UNIT 1 17
Example of Non-Primitive Data Types in Java:

public class Main {


public static void main(String[] args) {
// Using a class
Person person = new Person();
person.name = "Alice";
person.age = 25;
person.displayInfo(); // Output: Name: Alice, Age: 2
5

// Using an array
int[] numbers = {1, 2, 3, 4, 5};
for (int number : numbers) {
System.out.println(number); // Output: 1, 2, 3,
4, 5
}

// Using a String
String message = "Welcome to Java!";
System.out.println(message); // Output: Welcome to J
ava!
}
}

This example demonstrates the use of non-primitive data types, including a class
( Person ), an array, and a string in Java. Understanding both primitive and non-
primitive data types is crucial for effective programming in Java.

Summary of Page 12 (Tokens: Keywords, Identifiers, Literals)

6. TOKENS
Tokens are the smallest individual units of a Java program, serving as the
building blocks of the language.

In Java, tokens include keywords, identifiers, literals, operators, and special


symbols.

6.1 Keywords
Keywords are reserved words defined by the Java language. They cannot be
used as identifiers.

Examples include:

int , class , public , static , void , if , else , for , while .

Keywords are always in lowercase.

6.2 Identifiers

JAVA - UNIT 1 18
Identifiers are names given to variables, methods, classes, and other entities.

Rules for Identifiers:

Can contain letters (a-z, A-Z), digits (0-9), $ , and _ .

Cannot start with a digit or contain spaces.

Must not match any keyword.

There is no limit on the length of identifiers.

Valid Identifiers:

myVariable , _temp , $value , count1

Invalid Identifiers:

1stValue (starts with a digit), my name (contains a space), float (keyword).

6.3 Literals
Literals are constant values that are directly used in the code.

Types of literals:

1. Integer Literals: Whole numbers.

Example: int num = 10;

2. Floating-point Literals: Numbers with decimal points.

Example: float pi = 3.14f;

3. Character Literals: A single character enclosed in single quotes.

Example: char letter = 'A';

4. String Literals: A sequence of characters enclosed in double quotes.

Example: String message = "Hello";

5. Boolean Literals: Represents true or false .

Example: boolean isJavaFun = true;

Example Code with Tokens

public class TokenExample { // 'public', 'class', 'Token


Example' are tokens
public static void main(String[] args) { // 'public', 'st
atic', 'void', 'main' are tokens
int number = 10; // 'int', 'number', '=', '1
0' are tokens
String text = "Java"; // 'String', 'text', '=',
'"Java"' are tokens
System.out.println(text); // 'System', 'out', 'printl
n' are tokens
}
}

JAVA - UNIT 1 19
Summary
Understanding tokens is fundamental to programming in Java, as they are the
essential components that form the structure and syntax of the code.

Each token type serves a specific purpose and plays a critical role in how a
Java program is constructed and executed.

Summary of Page 13 (Operators in Java)

6.4 Operators in Java


Operators are symbols that perform operations on variables and values. They
are classified based on their functionality.

Types of Operators
1. Arithmetic Operators:

Used for mathematical operations.

Symbols: + , , , / , %

Examples:

int a = 10, b = 5;
int sum = a + b; // sum = 15
int difference = a - b; // difference = 5
int product = a * b; // product = 50
int quotient = a / b; // quotient = 2
int remainder = a % b; // remainder = 0

2. Assignment Operators:

Used to assign values to variables.

Symbols: = , += , = , = , /= , %=

Examples:

int x = 10; // simple assignment


x += 5; // x = x + 5; (x becomes 15)
x -= 3; // x = x - 3; (x becomes 12)

3. Relational Operators:

Used to compare two values, returning true or false .

Symbols: == , != , < , > , <= , >=

Examples:

int a = 10, b = 20;


boolean isEqual = (a == b); // false
boolean isGreater = (a > b); // false

JAVA - UNIT 1 20
4. Logical Operators:

Used to combine multiple boolean expressions.

Symbols: && , || , !

Examples:

boolean x = true, y = false;


boolean result1 = (x && y); // false
boolean result2 = (x || y); // true
boolean result3 = !x; // false

5. Bitwise Operators:

Perform operations on binary digits.

Symbols: & , | , ^ , ~

Examples:

int a = 5; // 0101 in binary


int b = 3; // 0011 in binary
int result1 = a & b; // 0001 (1 in decimal)
int result2 = a | b; // 0111 (7 in decimal)

6. Unary Operators:

Operate on a single operand.

Symbols: ++ , - , , !

Examples:

int num = 10;


num++; // num becomes 11
num--; // num becomes 10 again

7. Shift Operators:

Shift the bits of a number left or right.

Symbols: << , >> , >>>

Examples:

int a = 10; // 1010 in binary


int leftShift = a << 2; // 00101000 (40 in decimal)
int rightShift = a >> 2; // 00000010 (2 in decimal)

8. Ternary Operator:

A shorthand for the if-else statement.

Syntax: condition ? expression_if_true : expression_if_false

JAVA - UNIT 1 21
Example:

int a = 10, b = 20;


int max = (a > b) ? a : b; // max = 20

Summary of Operators Table:

Operator Type Description Examples

Arithmetic Basic mathematical operations +, -, *, /, %

Assignment Assigns values to variables = , += , -=

Relational Compares two values == , != , < , >

Logical Combines boolean expressions && , `

Bitwise Operates on bits &,`

Unary Operates on a single operand ++ , -- , - , !

Shift Shifts bits left or right << , >> , >>>

Ternary Shorthand for if-else condition ? true : false

Operators are crucial for performing calculations, comparisons, and logical


operations in Java. Understanding how to use them effectively is essential for
programming in Java.

Summary of Page 14 (Operator Precedence and Associativity)

4.9 Operator Precedence


Operator precedence determines the order in which operators are evaluated
in expressions.

Operators with higher precedence are evaluated before those with lower
precedence.

For example, in the expression 1 + 2 * 3 , the multiplication is performed first,


resulting in 1 + (2 * 3) .

Precedence Order
Here’s a list of operator precedence from highest to lowest:

Precedence Level Operator Type Operators

1 Parentheses ()

2 Postfix Increment/Decrement ++ , --

3 Unary Increment/Decrement ++ , -- , - , + , ! , ~

4 Type Cast, New Operator () , new

5 Multiplicative *, /, %

6 Additive +, -

7 Shift << , >> , >>>

8 Relational < , <= , > , >= , instanceof

JAVA - UNIT 1 22
9 Equality == , !=

10 Bitwise AND &

11 Bitwise XOR ^

12 Bitwise OR `

13 Logical AND &&

14 Logical OR `

15 Ternary Operator ?:

16 Assignment = , += , -= ...

4.9.1 Associativity
Associativity determines the order of evaluation when two operators of the
same precedence appear in an expression.

Most operators in Java are left-to-right associative, meaning they are


evaluated from left to right.

Example: In the expression a - b + c , it is evaluated as ((a - b) + c) .

However, some operators, like the assignment operator ( = ) and the ternary
operator ( ?: ), are right-to-left associative.

Example: In the expression x = y = z = 17 , it is evaluated as x = (y = (z =

17)) .

Summary Table of Precedence and Associativity

Operator Type Description Precedence Level Associativity

Parentheses Grouping expressions Highest Left to Right

Postfix Increment/Decrement (postfix) 2nd Not Associative

Unary Increment/Decrement (unary) 3rd Right to Left

Multiplicative *, /, % 5th Left to Right

Additive +, - 6th Left to Right

Shift << , >> , >>> 7th Left to Right

Relational < , <= , > , >= , instanceof 8th Left to Right

Equality == , != 9th Left to Right

Bitwise &, ^,` ` 10th to 12th

Logical && , ` `

Ternary ?: 15th Right to Left

Assignment = , += , -= ... Lowest Right to Left

Understanding operator precedence and associativity is crucial for writing correct


expressions and avoiding unintended results in Java programs.

Summary of Page 15 (Data Types in Java Continued)

5. DATA TYPES (Continued)

JAVA - UNIT 1 23
Data types in Java dictate the kind of data a variable can hold, the size of
memory allocated, and the operations allowed on that data.

5.1 Primitive Data Types Recap


Java has eight primitive data types:

byte: 8-bit signed integer, range -128 to 127.

short: 16-bit signed integer, range -32,768 to 32,767.

int: 32-bit signed integer, range -2,147,483,648 to 2,147,483,647.

long: 64-bit signed integer, range -9,223,372,036,854,775,808 to


9,223,372,036,854,775,807.

float: 32-bit single-precision floating point.

double: 64-bit double-precision floating point.

char: 16-bit Unicode character.

boolean: Represents one of two values: true or false.

5.2 Non-Primitive Data Types Recap


Non-primitive data types include:

1. Classes: User-defined types that can contain fields and methods.

2. Interfaces: Abstract types that define a contract of methods.

3. Arrays: Collections of elements of the same type.

4. Strings: Objects representing a sequence of characters.

5.3 Example of Primitive and Non-Primitive Data Types


Primitive Example:

int age = 25; // Primitive data type


double height = 5.9; // Primitive data type
boolean isStudent = true; // Primitive data type

Non-Primitive Example:

// Using a class
class Car {
String model;
int year;
}

Car myCar = new Car(); // Non-primitive data type (obj


ect)
myCar.model = "Toyota";
myCar.year = 2020;

JAVA - UNIT 1 24
// Using an array
int[] scores = {85, 90, 78}; // Non-primitive data type (a
rray)

5.4 Importance of Data Types


Understanding data types is crucial for:

Memory Management: Knowing the size of each type helps optimize


memory usage.

Data Manipulation: Each data type allows specific operations, influencing


how you write your code.

Error Prevention: Strong typing helps catch errors at compile time.

Summary
Java's rich set of primitive and non-primitive data types provides flexibility in
handling various data requirements in programming. The choice of data type
affects how data is stored, manipulated, and processed, making it essential for
developers to choose the appropriate type for their needs.

Summary of Page 16 (Operators in Java Continued)

4. OPERATOR PRECEDENCE AND ASSOCIATIVITY

4.9 Operator Precedence Recap


Operator precedence dictates the order in which operators are evaluated in
expressions.

Operators with higher precedence are evaluated first.

For example, in the expression 5 + 2 * 3 , multiplication takes precedence over


addition, resulting in 5 + (2 * 3) .

Key Points of Precedence


Precedence levels determine how expressions are grouped.

Parentheses can be used to override the default precedence.

Complete Precedence Order Table


Precedence Level Operator Type Operators

1 Parentheses ()

2 Postfix Increment/Decrement ++ , --

3 Unary Increment/Decrement ++ , -- , - , + , ! , ~

4 Type Cast, New Operator () , new

5 Multiplicative *, /, %

6 Additive +, -

JAVA - UNIT 1 25
7 Shift << , >> , >>>

8 Relational < , <= , > , >= , instanceof

9 Equality == , !=

10 Bitwise AND &

11 Bitwise XOR ^

12 Bitwise OR `

13 Logical AND &&

14 Logical OR `

15 Ternary Operator ?:

16 Assignment = , += , -= ...

4.9.1 Associativity Recap


Associativity defines how operators of the same precedence are evaluated.

Most operators are left-to-right associative, meaning they are evaluated from
left to right.

Example: a - b + c is evaluated as ((a - b) + c) .

Some operators, such as assignment ( = ) and ternary ( ?: ), are right-to-left


associative.

Example: x = y = z = 17 is evaluated as x = (y = (z = 17)) .

Summary of Associativity
Understanding both operator precedence and associativity is essential for
writing clear and correct expressions in Java.

Misunderstanding these concepts can lead to unexpected results, making it


crucial to grasp how Java evaluates expressions.

Conclusion
Operator precedence and associativity are fundamental concepts in Java
programming that affect how expressions are evaluated. Mastering these
concepts will help prevent logical errors in code and enhance overall
programming skills.

Summary of Page 17 (Data Types and Example)

5. DATA TYPES (Continued)


Data types play a crucial role in defining the size and nature of the values
stored in variables, as well as the operations that can be performed on those
values.

5.5 Summary of Primitive Data Types


Primitive Data Types in Java:

byte: 8-bit signed integer, range -128 to 127.

JAVA - UNIT 1 26
short: 16-bit signed integer, range -32,768 to 32,767.

int: 32-bit signed integer, range -2,147,483,648 to 2,147,483,647.

long: 64-bit signed integer, range -9,223,372,036,854,775,808 to


9,223,372,036,854,775,807.

float: 32-bit single-precision floating point.

double: 64-bit double-precision floating point.

char: 16-bit Unicode character.

boolean: Represents one of two values: true or false .

5.6 Example of Using Data Types


Example Code:

public class DataTypesExample {


public static void main(String[] args) {
// Primitive Data Types
byte age = 25; // byte
short year = 2024; // short
int population = 1000000; // int
long distance = 123456789L; // long
float pi = 3.14f; // float
double e = 2.718281828459; // double
char initial = 'J'; // char
boolean isJavaFun = true; // boolean

// Outputting Values
System.out.println("Age: " + age);
System.out.println("Year: " + year);
System.out.println("Population: " + population);
System.out.println("Distance: " + distance);
System.out.println("Value of Pi: " + pi);
System.out.println("Value of e: " + e);
System.out.println("Initial: " + initial);
System.out.println("Is Java fun? " + isJavaFun);
}
}

Explanation of Example Code


Primitive Data Types are declared and initialized with specific values.

The System.out.println method is used to output the values of each variable to


the console.

Conclusion

JAVA - UNIT 1 27
Understanding data types is fundamental to programming in Java, as they
dictate how data is stored, manipulated, and processed.

The example illustrates how to declare and use various primitive data types
effectively, providing a solid foundation for further Java programming
concepts.

Summary of Pages 18-20 (Advanced Data Types and Concepts in


Java)

5.7 Non-Primitive Data Types


Non-primitive data types, also known as reference data types, are more
complex than primitive data types. They can store multiple values and are
defined using classes and interfaces.

1. Classes:

A class is a blueprint for creating objects. It can contain fields (attributes)


and methods (functions) that define the behaviors of the objects.

Example:

public class Student {


String name; // Field
int age; // Field

// Method to display student information


void display() {
System.out.println("Name: " + name + ", Age: "
+ age);
}
}

2. Interfaces:

An interface is a reference type that can contain only constants, method


signatures, default methods, static methods, and nested types. It cannot
contain instance fields.

A class implements an interface to provide the behavior defined by the


interface.

Example:

public interface Animal {


void sound(); // Method signature
}

public class Dog implements Animal {


public void sound() {
System.out.println("Bark");

JAVA - UNIT 1 28
}
}

3. Arrays:

An array is a collection of similar data types stored in a single variable. It


can hold multiple values of the same type.

Example:

int[] numbers = {1, 2, 3, 4, 5}; // Array of integers


String[] fruits = {"Apple", "Banana", "Cherry"}; // Arr
ay of strings

4. Strings:

Strings in Java are objects that represent a sequence of characters.


Strings are created using the String class.

Example:

String greeting = "Hello, World!";

5.8 Using Non-Primitive Data Types


Example Code:

public class Main {


public static void main(String[] args) {
// Using Class
Student student = new Student();
student.name = "Alice";
student.age = 20;
student.display(); // Output: Name: Alice, Age: 20

// Using Interface
Dog dog = new Dog();
dog.sound(); // Output: Bark

// Using Array
int[] scores = {85, 90, 78};
for (int score : scores) {
System.out.println("Score: " + score);
}

// Using String
String message = "Welcome to Java!";
System.out.println(message); // Output: Welcome to
Java!

JAVA - UNIT 1 29
}
}

Conclusion
Understanding both primitive and non-primitive data types is essential for
effective Java programming.

Non-primitive types allow for more complex data handling and organization,
enabling the creation of robust applications.

Mastering classes, interfaces, arrays, and strings will enhance your


programming skills and allow you to write more organized and maintainable
code.

Key Takeaways
Primitive Data Types: Basic types like int , float , char , and boolean .

Non-Primitive Data Types: More complex structures such as classes,


interfaces, arrays, and strings.

Each data type serves specific purposes in programming, and understanding


their usage is crucial for effective Java development.

Summary of Pages 20-22 (Control Structures and Flow Control in


Java)

6. CONTROL STRUCTURES IN JAVA


Control structures are essential for managing the flow of execution in a Java
program. They allow for decision-making, looping, and branching based on
conditions.

6.1 Types of Control Structures


1. Decision-Making Statements:

Used to perform different actions based on different conditions.

If Statement:

Executes a block of code if the condition is true.

Example:

if (condition) {
// code to execute if condition is true
}

If-Else Statement:

Provides an alternative block of code if the condition is false.

Example:

JAVA - UNIT 1 30
if (condition) {
// code if condition is true
} else {
// code if condition is false
}

Else If Ladder:

Allows multiple conditions to be checked.

Example:

if (condition1) {
// code if condition1 is true
} else if (condition2) {
// code if condition2 is true
} else {
// code if both conditions are false
}

Switch Statement:

Selects one of many code blocks to execute based on the value of a


variable.

Example:

switch (expression) {
case value1:
// code for value1
break;
case value2:
// code for value2
break;
default:
// code if no case matches
}

2. Looping Statements:

Used to execute a block of code multiple times.

For Loop:

Executes a block of code a specific number of times.

Example:

for (int i = 0; i < 10; i++) {


// code to execute
}

JAVA - UNIT 1 31
While Loop:

Executes a block of code as long as the condition is true.

Example:

while (condition) {
// code to execute
}

Do-While Loop:

Similar to a while loop, but guarantees that the block of code is


executed at least once.

Example:

do {
// code to execute
} while (condition);

3. Jump Statements:

Control the flow of execution by jumping to a specific point in the code.

Break Statement:

Exits the loop or switch statement.

Example:

for (int i = 0; i < 10; i++) {


if (i == 5) {
break; // exits loop when i equals 5
}
}

Continue Statement:

Skips the current iteration of a loop and moves to the next iteration.

Example:

for (int i = 0; i < 10; i++) {


if (i % 2 == 0) {
continue; // skips even numbers
}
// code for odd numbers
}

Return Statement:

Exits from the current method and returns control to the calling
method.

JAVA - UNIT 1 32
Example:

public int add(int a, int b) {


return a + b; // exits method and returns sum
}

Conclusion
Control structures are fundamental for creating dynamic and functional Java
programs.

By mastering decision-making, looping, and jump statements, you can


effectively control the flow of execution in your applications, enabling complex
logic and data handling.

Key Takeaways
Decision-Making Statements: Determine the execution path based on
conditions.

Looping Statements: Repeatedly execute code based on specified conditions.

Jump Statements: Change the flow of execution within loops and methods.

These structures are essential for implementing logic and behavior in Java
applications. Understanding how to use them will enhance your programming
skills and allow for the development of more sophisticated applications.

Summary of Pages 22-25 (More on Control Structures, Loops,


and Exception Handling in Java)

6. CONTROL STRUCTURES IN JAVA (Continued)


Control structures are vital for controlling the execution flow of Java programs.
This section delves deeper into loops and introduces exception handling.

6.1 More on Loops


1. For-Each Loop:

A simplified loop used to iterate over arrays and collections.

Syntax:

for (dataType item : arrayOrCollection) {


// code to execute
}

Example:

String[] fruits = {"Apple", "Banana", "Cherry"};


for (String fruit : fruits) {

JAVA - UNIT 1 33
System.out.println(fruit); // Outputs each fruit
}

2. Nested Loops:

Loops can be nested inside other loops.

Example:

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {
System.out.println("i: " + i + ", j: " + j);
}
}

6.2 Exception Handling


Exception Handling: A mechanism to handle runtime errors and maintain
normal application flow.

Common Keywords:

try: Block of code to test for errors.

catch: Block of code that handles the error.

finally: Block of code that executes after try and catch, regardless of the
outcome.

throw: Used to explicitly throw an exception.

throws: Indicates that a method can throw exceptions.

1. Try-Catch Block:

Used to handle exceptions.

Example:

try {
int result = 10 / 0; // This will cause an Arithmet
icException
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero: " + e.ge
tMessage());
}

2. Finally Block:

Executes code regardless of whether an exception was thrown or caught.

Example:

try {
// code that may throw an exception

JAVA - UNIT 1 34
} catch (Exception e) {
// handling exception
} finally {
System.out.println("This will always execute.");
}

3. Throwing Exceptions:

You can throw an exception manually using the throw keyword.

Example:

public void checkAge(int age) {


if (age < 18) {
throw new IllegalArgumentException("Age must be
18 or older.");
}
}

4. Method Declaration with Throws:

Indicates that a method may throw exceptions, allowing the calling method
to handle them.

Example:

public void readFile() throws IOException {


// code that may throw IOException
}

Conclusion
Mastering control structures, loops, and exception handling is essential for
effective Java programming.

Proper use of these constructs enables developers to write more robust,


maintainable, and error-resistant code.

Key Takeaways
For-Each Loop: Simplifies iteration over arrays and collections.

Nested Loops: Allows complex data processing by iterating through multiple


levels.

Exception Handling: Provides a way to gracefully handle errors and maintain


program flow.

Understanding these concepts will significantly enhance your ability to create


functional and efficient Java applications.

Summary of Pages 25-27 (Object-Oriented Programming


Concepts in Java)

JAVA - UNIT 1 35
7. OBJECT-ORIENTED PROGRAMMING (OOP) IN JAVA
Object-Oriented Programming (OOP) is a programming paradigm based on the
concept of "objects," which can contain data and methods. Java is a fully object-
oriented language.

7.1 Key OOP Concepts


1. Classes and Objects:

A class is a blueprint for creating objects. It defines properties (attributes)


and behaviors (methods).

An object is an instance of a class.

Example:

public class Car {


// Attributes
String color;
String model;

// Method
void displayInfo() {
System.out.println("Model: " + model + ", Colo
r: " + color);
}
}

public class Main {


public static void main(String[] args) {
Car myCar = new Car(); // Creating an object o
f Car class
myCar.color = "Red";
myCar.model = "Toyota";
myCar.displayInfo(); // Outputs: Model: Toyot
a, Color: Red
}
}

2. Encapsulation:

The practice of wrapping data (attributes) and methods that operate on


the data into a single unit, or class.

Encapsulation restricts access to certain components and can prevent


unintended interference and misuse.

Example:

public class BankAccount {


private double balance; // Private attribute

JAVA - UNIT 1 36
// Method to access private attribute
public double getBalance() {
return balance;
}

// Method to modify the private attribute


public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
}

3. Inheritance:

A mechanism where a new class (subclass) can inherit attributes and


methods from an existing class (superclass).

Promotes code reusability.

Example:

public class Vehicle {


void start() {
System.out.println("Vehicle is starting");
}
}

public class Bike extends Vehicle { // Inheriting Vehic


le class
void ride() {
System.out.println("Bike is riding");
}
}

public class Main {


public static void main(String[] args) {
Bike myBike = new Bike();
myBike.start(); // Inherited method
myBike.ride(); // Bike specific method
}
}

4. Polymorphism:

The ability of a single interface to be used for different underlying forms


(data types).

JAVA - UNIT 1 37
Achieved through method overriding (runtime polymorphism) and method
overloading (compile-time polymorphism).

Method Overloading:

Multiple methods with the same name but different parameters.

Example:

public class MathUtils {


int add(int a, int b) {
return a + b;
}

double add(double a, double b) {


return a + b;
}
}

Method Overriding:

Redefining a method in a subclass that already exists in the


superclass.

Example:

public class Animal {


void sound() {
System.out.println("Animal makes sound");
}
}

public class Dog extends Animal {


@Override
void sound() {
System.out.println("Dog barks");
}
}

Conclusion
OOP is a fundamental concept in Java that enhances code organization,
reusability, and scalability.

Understanding classes, objects, encapsulation, inheritance, and


polymorphism is essential for effective Java programming.

Key Takeaways
Classes and Objects: Central to OOP; classes are blueprints for objects.

Encapsulation: Protects data by restricting access.

JAVA - UNIT 1 38
Inheritance: Allows code reuse by deriving new classes from existing ones.

Polymorphism: Provides flexibility by allowing methods to perform different


functions based on the object type.

Mastering these OOP concepts will greatly enhance your ability to design and
implement robust Java applications.

Summary of Pages 27-29 (Advanced Object-Oriented


Programming and Conclusion)

7. OBJECT-ORIENTED PROGRAMMING (OOP) IN JAVA


(Continued)

7.2 Additional OOP Concepts


1. Abstraction:

Abstraction is the concept of hiding the complex implementation details


and showing only the essential features of an object.

Achieved using abstract classes and interfaces.

Abstract Class:

A class that cannot be instantiated and may contain abstract methods


(methods without a body).

Example:

abstract class Shape {


abstract void draw(); // Abstract method
}

class Circle extends Shape {


void draw() {
System.out.println("Drawing Circle");
}
}

public class Main {


public static void main(String[] args) {
Shape shape = new Circle();
shape.draw(); // Output: Drawing Circle
}
}

Interface:

A reference type in Java, similar to a class, that can only contain


constants, method signatures, default methods, static methods, and
nested types.

Example:

JAVA - UNIT 1 39
interface Drawable {
void draw(); // Method signature
}

class Rectangle implements Drawable {


public void draw() {
System.out.println("Drawing Rectangle");
}
}

2. Composition:

A design principle where one class contains references to objects of other


classes, establishing a "has-a" relationship.

Promotes code reuse and flexibility.

Example:

class Engine {
void start() {
System.out.println("Engine starting");
}
}

class Car {
Engine engine; // Car "has-a" engine

Car() {
engine = new Engine();
}

void startCar() {
engine.start(); // Delegation
System.out.println("Car starting");
}
}

public class Main {


public static void main(String[] args) {
Car myCar = new Car();
myCar.startCar(); // Output: Engine starting\\n
Car starting
}
}

7.3 Best Practices in OOP

JAVA - UNIT 1 40
Encapsulate Your Data: Use private access modifiers and provide public
getters/setters.

Favor Composition Over Inheritance: Use composition to achieve greater


flexibility.

Use Interfaces for Abstraction: Define behavior contracts for classes to


implement.

Conclusion
Object-Oriented Programming (OOP) is a powerful paradigm in Java that
facilitates better software design through concepts like encapsulation,
inheritance, polymorphism, abstraction, and composition.

Mastery of these concepts will enable you to write more organized, reusable,
and maintainable code.

Key Takeaways
Abstraction: Hides complex implementation details.

Composition: Establishes a "has-a" relationship and promotes code reuse.

Best Practices: Encourage encapsulation, composition over inheritance, and


interface usage for cleaner design.

These principles are fundamental for developing robust Java applications and for
adapting to complex software design requirements. Understanding and applying
these OOP concepts will significantly improve your programming skills in Java.

JAVA - UNIT 1 41

You might also like