0% found this document useful (0 votes)
10 views15 pages

Module

The document outlines the syllabus for the Fundamentals of Java Programming course for the academic year 2025-2026, focusing on Object-Oriented Programming (OOP) principles such as classes, objects, abstraction, encapsulation, and polymorphism. It details Java syntax, data types, variables, operators, control statements, and the Java architecture, including the roles of the Java Compiler, JVM, and JDK. The content is structured to provide a comprehensive understanding of Java programming fundamentals and its application in real-world scenarios.

Uploaded by

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

Module

The document outlines the syllabus for the Fundamentals of Java Programming course for the academic year 2025-2026, focusing on Object-Oriented Programming (OOP) principles such as classes, objects, abstraction, encapsulation, and polymorphism. It details Java syntax, data types, variables, operators, control statements, and the Java architecture, including the roles of the Java Compiler, JVM, and JDK. The content is structured to provide a comprehensive understanding of Java programming fundamentals and its application in real-world scenarios.

Uploaded by

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

Academic Year: 2025-2026

Regulation: IFETCE R2023

DEPARTMRNT OF CSE
SUBJECT CODE: 23CS 6601 YEAR/SEM: III/VI
SUBJECT NAME: FUNDAMENTALS OF JAVA PROGRAMMING
MODULE
UNIT -1 INTRODUCTION TO OOP AND JAVA FUNDAMENTALS
OOP – Classes and Objects – Abstraction – Encapsulation – Polymorphism – Java Architecture
Programming Structures – Defining Classes , Data Types, Variables ,Operators ,Keywords, Control
Statements, Array – Constructors – Packages.

1.1 INTRODUCTION TO OOPS


 Object-Oriented Programming or OOPs relates to languages that use objects in programming.
Object-oriented programming intends to achieve real-world entities such as inheritance,
hiding, polymorphism, etc in programming.
 The main purpose of OOP is to tie together the data and the functions that operate on them
thus no other part of the code can enter this data except that function. Mainly, the course of
the Object-Oriented Programming is intended to implement a broad study of the java
programming language. OOPs is an extension of the java programming language.

Java Syntax
In the previous chapter, we created a Java file called [Link], and we used the following code to
print "Hello World" to the screen:
public class Main {
public static void main(String[] args) {
[Link]("Hello World");
}
}
The main Method
The main() method is required and you will see it in every Java program:
public static void main(String[] args)
[Link]()
Inside the main() method, we can use the println() method to print a line of text to the screen:
public static void main(String[] args) {
[Link]("Hello World");
}
The Print() Method
There is also a print() method, which is similar to println().
The only difference is that it does not insert a new line at the end of the output:
Example
[Link]("Hello World! ");
[Link]("I will print on the same line.”);

Double Quotes
Text must be wrapped inside double quotations marks "".
If you forget the double quotes, an error occurs:
Example
[Link]("This sentence will work!");
[Link](This sentence will produce an error);

Print Numbers
You can also use the println() method to print numbers.
Academic Year: 2025-2026
Regulation: IFETCE R2023

However, unlike text, we don't put numbers inside double quotes:


Example:
[Link](3);
[Link](358);
[Link](50000);

1.2 Class and Object


 Java is an object-oriented programming language.
 Everything in Java is associated with classes and objects, along with its attributes and methods.
 For example: in real life, a car is an object. The car has attributes, such as weight and color, and
methods, such as drive and brake.
 A Class is like an object constructor, or a "blueprint" for creating objects. 1.2.1 Class
 Classes are user-defined data types and behave like built-in types of the programming language.
 A class is declared by use of the class keyword.
 A class is a collection of data and methods that operate on that data.
It defines the abstract characteristics of a thing (object), including its characteristics and the thing’s
behaviors.
 A simplified general form of a class definition is
Class
Class name
{
type instance-variable1;
type instance-variable2;
// ... type instance-variableN;
type methodname1(parameter-list)
{
// body of method
}
type methodname2(parameter-list)
{
// body of method
}
// ... typemethodnameN(parameter-list)
{
// body of method
}
}
Example: public class
MyClass { int x = 5; }
Object
 Objects are basic run-time entities in an object-oriented system.
 Objects have states and behaviors.
 An object is an instance of a class.
 They may represent a person, a place, a bank account, a table of data or any item that the program
has to handle.
 Each object has the data and code to manipulate the data and theses objects interact with each
other. The general form for creating Object is
Classname objectname = new Classname();
Or
Classname objectname;
objectname = new Classname();
Example:
public class MyClass
Academic Year: 2025-2026
Regulation: IFETCE R2023

{
int x = 5;
public static void main(String[] args)
{
MyClass myObj = new MyClass();
[Link](myObj.x);
}}
Output:
5
1.3 Abstraction
 Hiding internal implementation and showing only the necessary details.
 Achieved through abstract classes and interfaces.
 Abstraction defines the essential characteristics of an object that distinguish it from
all other kinds of objects.
 Abstraction provides crisply-defined conceptual boundaries relative to the perspective
of the viewer. It’s the process of focusing on the essential characteristics of an object.
Abstraction is one of the fundamental elements of the object model.
 Abstraction is creating interface to denote common behavior without specifying
any details about how that behavior works
 For e.g. User create an interface called Server which has start() and stop() method.

abstract class Animal {


abstract void sound();
}

class Dog extends Animal {


void sound() {
[Link]("Bark");
}
}
1.4 Encapsulation
 Wrapping data and code into a single unit (class).
 Restricting direct access to some components using access modifiers (private, public,
protected).
 Achieved using getters and setters.

 Encapsulation is the mechanism that binds together code and the data it manipulates,
and keeps both safe from outside interference and misuse.
 Encapsulation is a protective wrapper that prevents the code and data from being
arbitrarily accessed by other code defined outside the wrapper.
 Access to the code and data inside the wrapper is tightly controlled through a well-
defined interface.
Academic Year: 2025-2026
Regulation: IFETCE R2023

Fig: 1.2 Encapsulation

class Student {
private String name;
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
}

1.5 Polymorphism
 Polymorphism (many forms) is a feature that allows one interface to be used
for a general class of actions.
 The specific action is determined by the exact nature of the situation.
 One task performed in different ways.
 Types:
o Compile-time (Method Overloading)
o Run-time (Method Overriding)
// Method Overloading
class MathUtils {
int add(int a, int b) {
return a + b;
}
double add(double a, double b) {
return a + b;
}
}
// Method Overriding
class Animal {
void sound() {
[Link]("Animal sound");
}
}
class Cat extends Animal {
Academic Year: 2025-2026
Regulation: IFETCE R2023

void sound() {
[Link]("Meow");
}
}
1.6 JAVA ARCHITECTURE PROGRAMMING STRUCTURE
Java architecture describes how the Java programming language works internally, from writing a
program to its execution. It consists of several important components that together provide the Write
Once, Run Anywhere feature.

Fig1.3 Java Architecture


Key Components of Java Architecture
Java Source Code (.java)
This is the code written by the programmer using the Java language. It contains classes, objects,
methods, and logic in human-readable form.
Java Compiler (javac)
The javac compiler translates the .java file (source code) into bytecode. This bytecode is not specific
to any processor or OS, making it platform-independent.
Input: .java file
Output: .class file (bytecode)
Bytecode (.class)
This is the intermediate, compiled code produced by the Java compiler. Bytecode can be executed on
any system that has a Java Virtual Machine (JVM). It is not readable by humans but is understood
by the JVM.
Java Virtual Machine (JVM)
The JVM is a virtual runtime environment that interprets and executes Java bytecode. It provides
features like memory management, garbage collection, security, and platform independence.
JVM works in two modes:
 Interpreter – reads and executes bytecode line by line.
 Just-In-Time (JIT) Compiler – improves performance by converting bytecode into native
machine code at runtime.
Java Runtime Environment (JRE)
JRE includes:
 JVM
 Java class libraries (built-in packages like [Link], [Link])
Academic Year: 2025-2026
Regulation: IFETCE R2023

 Supporting files
JRE provides the environment to run Java programs but not to develop them.
Java Development Kit (JDK)
The JDK is a complete software development kit that includes:
 JRE (which includes JVM)
 Development tools (like javac, java, javadoc, debugger, etc.)
The JDK is used for writing, compiling, and executing Java programs.
1.7 DEFINING CLASSES
In Java, a class is a blueprint or template for creating objects. It defines data (fields/variables) and
methods (functions) that describe the behavior of the object.
A class groups related data and functions under one structure.
Syntax:
class ClassName {
// Fields (variables)
// Methods (functions)
}
Example of a Class
class Student {
// Data members
int id;
String name;
// Method
void display() {
[Link]("ID: " + id + ", Name: " + name);
}
}
Creating and Using an Object
public class Main {
public static void main(String[] args) {
Student s1 = new Student(); // Creating object
[Link] = 101; // Accessing variables
[Link] = "Anu";
[Link](); // Calling method
}
}
Output:
ID: 101, Name: Anu

1.8 DATA TYPES, VARIABLES ,OPERATORS ,KEYWORDS, CONTROL STATEMENTS


AND ARRAY
1.8.1 DATA TYPES IN JAVA
Java is a strongly typed language, meaning every variable must be declared with a data type. Data
types specify the size and type of values that can be stored.
Academic Year: 2025-2026
Regulation: IFETCE R2023

1. Primitive Data Types (Built-in)


Java has 8 primitive data types:
Data Type Size Example Description
Byte 1 byte byte a = 10; Small integers (-128 to 127)
short 2 bytes short s = 1000; Larger than byte
Int 4 bytes int x = 50000; Default integer type
Long 8 bytes long l = 100000L; Very large numbers
float 4 bytes float f = 5.75f; Decimal numbers (single)
double 8 bytes double d = 19.99; Decimal (double precision)
char 2 bytes char c = 'A'; A single character
boolean 1 bit boolean b = true; True or false
2. Non-Primitive Data Types
 Also called Reference Types
 Includes: String, Arrays, Classes, Interfaces, Objects
Eg : String name = "Java";
1.8.2 VARIABLES IN JAVA
Variables are containers for storing data values.
Types of Variables:
Type Description Example
Local Declared inside a method int sum = a + b;
Instance Declared inside a class, but outside methods int speed;
Static Declared with static keyword (shared) static int count = 0;
class Car {
int speed; // Instance variable
static int wheels = 4; // Static variable
void run() {
int fuel = 50; // Local variable
}
}
1.8.3OPERATORS
In Java, operators are special symbols or keywords used to perform operations on variables and
values.
Types of Operators in Java
Java supports the following categories of operators:
Arithmetic Operators
Used to perform basic mathematical operations.
Operator Description Example Result
+ Addition a+b Sum of a and b
- Subtraction a-b Difference of a and b
* Multiplication a*b Product of a and b
/ Division a/b Quotient of a and b
% Modulus (Remainder) a % b Remainder after division
Academic Year: 2025-2026
Regulation: IFETCE R2023

Relational (Comparison) Operators


Used to compare two values.
Operator Meaning Example Result
== Equal to a == b true / false
!= Not equal to a != b true / false
> Greater than a>b true / false
< Less than a<b true / false
>= Greater than or equal a >= b true / false
<= Less than or equal a <= b true / false
Logical Operators
Used to perform logical operations, mostly with boolean values.
Operator Description Example
&& Logical AND a > 10 && b < 20
! Logical NOT !true (gives false)
Assignment Operators
Used to assign values to variables.
Operator Example Meaning
= a=5 Assign 5 to a
+= a += 2 a=a+2
-= a -= 2 a=a-2
*= a *= 3 a=a*3
/= a /= 2 a=a/2
%= a %= 2 a=a%2
Unary Operators
Work with a single operand.
Operator Description Example
+ Unary plus +a
- Unary minus -a
++ Increment (prefix/postfix) ++a or a++
-- Decrement (prefix/postfix) --a or a--
! Logical complement !flag
Bitwise Operators
Operate on bits and perform bit-by-bit operations.
Operator Description Example
& Bitwise AND a&b
` ` Bitwise OR
^ Bitwise XOR a^b
~ Bitwise Complement ~a
<< Left shift a << 2
>> Right shift a >> 2
>>> Unsigned right shift a >>> 2
Academic Year: 2025-2026
Regulation: IFETCE R2023

Ternary Operator
Also called the conditional operator. It is a shorthand for if-else.
Eg: int result = (a > b) ? a : b;
If a > b, result is a; otherwise, it is b.
Instanceof Operator
Checks if an object is an instance of a specific class.
Eg: if (obj instanceof String) {
// do something
}
Example Program Using Operators
public class OperatorExample {
public static void main(String[] args) {
int a = 10, b = 20;
[Link]("a + b = " + (a + b));
[Link]("a > b: " + (a > b));
[Link]("a == b: " + (a == b));
[Link]("a != b: " + (a != b));
[Link]("a & b: " + (a & b));
}
}
Output:
a + b = 30
a > b: false
a == b: false
a != b: true
a & b: 0
1.8.4 KEYWORD
In Java, keywords are the reserved words that have some predefined meanings and are used by the
Java compiler for some internal process or represent some predefined actions. These words cannot be
used as identifiers such as variable names, method names, class names, or object names.

class Geeks {
public static void main(String[] args)
{
// Using final and int keyword
final int x = 10;

// Using if and else keywords


if(x > 10){
[Link]("Failed");
}
else {
[Link]("Successful demonstration"
+" of keywords.");
}
Academic Year: 2025-2026
Regulation: IFETCE R2023

}
}
Output
Successful demonstration of keyword

1.8.5 CONTROL STATEMENTS


Control Statements in Java are used to control the flow of execution of the program based on
certain conditions or repetitions.

Fig 1.4 Control Statements


Categories of Control Statements:
Conditional (Decision-Making) Statements
Used to execute a block of code based on a condition.
a. if Statement
if (condition) {
// code block
}
b. if-else Statement
if (co
ndition) {
// true block
} else {
// false block
}
c. if-else-if Ladder
if (condition1) {
// block1
} else if (condition2) {
// block2
} else {
// default block
}
Academic Year: 2025-2026
Regulation: IFETCE R2023

d. switch Statement
switch (variable) {
case value1:
// block1
break;
case value2:
// block2
break;
default:
// default block
}
Looping (Iteration) Statements
Used to repeat a block of code multiple times.
a. for Loop
for (int i = 0; i < 5; i++) {
[Link](i);
}
b. while Loop
int i = 0;
while (i < 5) {
[Link](i);
i++;
}
c. do-while Loop
int i = 0;
do {
[Link](i);
i++;
} while (i < 5);
Jumping Statements
Used to alter the normal flow of control.
a. break
 Exits the current loop or switch.
for (int i = 0; i < 5; i++) {
if (i == 3) break;
[Link](i);
}
b. continue
 Skips current iteration and continues with the next.
for (int i = 0; i < 5; i++) {
if (i == 2) continue;
[Link](i);
}
c. return
 Exits from a method and optionally returns a value.
Academic Year: 2025-2026
Regulation: IFETCE R2023

public int add(int a, int b) {


return a + b;
}
1.8.6 ARRAYS IN JAVA
An array is a container object that holds a fixed number of elements of the same data type.
Declaration & Initialization
int[] numbers = new int[5]; // Declaration with size
int[] marks = {90, 85, 70, 95}; // Declaration with values
Accessing Elements
[Link](marks[2]); // Output: 70
Array Example
public class ArrayExample {
public static void main(String[] args) {
int[] scores = {80, 90, 100};

for (int i = 0; i < [Link]; i++) {


[Link]("Score " + i + ": " + scores[i]);
}
}
}

1.9 CONSTRUCTORS
A constructor in Java is a special method that is automatically called when an object is created. It is used to
initialize objects. A constructor is a method which is invoked when an object of a class is created. It has no
return type in java. A constructor initializes an object immediately upon creation. It has the same name as the
class in which it resides and is syntactically similar to a method. Once defined, the constructor is
automatically called immediately after the object is created, before the new operator completes.
Constructor is classified into two types:
 Default Constructor: it is also called as no-argument constructor.
 Parameterized Constructor: constructor with one or more arguments.
Rules for creating Java constructor
 Constructor name must be the same as its class name
 A Constructor must have no explicit return type
 A Java constructor cannot be abstract, static, final, and synchronized
1.9.1 Features of Constructors
 Same name as the class
 No return type (not even void)
 Called automatically when an object is created
 Can be overloaded (multiple constructors with different parameters)
1.9.2 Syntax of Constructor
class ClassName {
ClassName() {
// Constructor body
}
}
Academic Year: 2025-2026
Regulation: IFETCE R2023

1.9.3 Types of Constructors


Default Constructor
 Constructor with no parameters
 Provided automatically by Java if no constructor is defined
class Bike {
Bike() {
[Link]("Bike is created");
}
}
public class Main {
public static void main(String[] args) {
Bike b = new Bike(); // Constructor is called automatically
}
}
Output:
Bike is created
Parameterized Constructor
 Constructor with parameters to initialize object with values
class Student {
int id;
String name;
Student(int i, String n) {
id = i;
name = n;
}
void display() {
[Link](id + " " + name);
}
}
public class Main {
public static void main(String[] args) {
Student s1 = new Student(101, "Anu");
[Link]();
}
}
Output:
101 Anu
Constructor Overloading
 Multiple constructors with different parameter lists
class Person {
String name;
int age;
Person() {
name = "Unknown";
age = 0;
Academic Year: 2025-2026
Regulation: IFETCE R2023

}
Person(String n, int a) {
name = n;
age = a;
}
void show() {
[Link](name + " " + age);
}
}
public class Main {
public static void main(String[] args) {
Person p1 = new Person();
Person p2 = new Person("John", 25);
[Link]();
[Link]();
}
}
Output:
Unknown 0
John 25

1.10 PACKAGES
A package in Java is a namespace that organizes a set of related classes and interfaces. Think of it
like a folder in a computer. A java package is a group of similar types of classes, interfaces and sub-
packages.
 Package in java can be categorized in two form, built-in package and user-defined package.
 There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
 The package keyword is used to create a package in java.

Types of Packages
1. Built-in Packages – Provided by Java (e.g., [Link], [Link], [Link]).
2. User-defined Packages – Created by the programmer.
Advantages of Packages
 Prevents name conflicts.
 Makes classes easier to locate and use.
 Provides access protection.
 Groups related classes.
Creating a Package
 Use the package keyword at the top of the Java file.
package mypackage;
Using a Package
 Use the import keyword.
import [Link];
Academic Year: 2025-2026
Regulation: IFETCE R2023

Example: User-Defined Package


Step 1: Create the package
File: [Link]
package mypack;
public class MyClass {
public void showMessage() {
[Link]("Hello from MyClass in mypack package!");
}
}
Step 2: Use the package
File: [Link]
import [Link];
public class Main {
public static void main(String[] args) {
MyClass obj = new MyClass();
[Link]();
}
}
Compile and Run Instructions:
# Step 1: Compile MyClass and create package folder
javac -d . [Link]

# Step 2: Compile [Link]


javac [Link]

# Step 3: Run the program


java Main

Output:
Hello from MyClass in mypack package!

You might also like