SlideShare a Scribd company logo
University of Sindh Campus Naushahro Feroze
Subject Object Oriented Programing
Student Name Muskan Aijaz
Roll No 2k24/NFIT/35
Teacher Name Sir Khalid
Date of Submission 2-Dec-2024
Practical Lab Manual
University of Sindh Campus Naushahro Feroze
CERTIFICATE
This is to certify that Ms. Muskan Aijaz of 2k24 BS (IT) class bearing Roll No.
2k24/NFIT/35 has carried out the necessary Project work as per course of studies
Object Oriented Programing “OOP’s” for the 1st
Year 2nd
Semester as above in
practical schedule of his journal.
2K24/NFIT/35 Miss. Muskan Aijaz 2 | P a g e
University of Sindh Campus Naushahro Feroze
Index
Lab #01
Introduction to Java Programming
Objective:
Introduction to Java Programming: Java is an object-oriented programming language valued
for its portability, allowing code to run on any device with a Java Virtual Machine (JVM).
Overview of Java:
History:
 Java was developed by James Ghosling, Patrick Naughton, Mike Sheridan at Sun
Microsystems Inc. in 1991. It took 18 months to develop the first working version.
 Java was designed with a “write once, run anywhere” philosophy.
2K24/NFIT/35 Miss. Muskan Aijaz 3 | P a g e
S.No Name Of Lab Manual Page.
No
1 Introduction to java Programing 4-9
2 Variables and Data Types 10-22
3 Operators in Java 23-51
4 Control Statements, Conditional Statements 52-60
5 Methods and Functions 61-64
6 Object Oriented Programing(OOP’s) in Java 65-66
University of Sindh Campus Naushahro Feroze
 The initial name was Oak but it was renamed to Java in 1995 as OAK was a registered
trademark of another Tech company.
Features:
 Platform Independence: Java programs can run on any device with a Java Virtual
Machine (JVM).
 Object-Oriented: Encourages modular code with reusable classes.
 Robust and Secure: Exception handling and security features make it reliable.
 High Performance: Bytecode execution provides speed while retaining platform
flexibility.
 Multithreading: Supports concurrent execution, optimizing performance.
Uses: Java is used in:
 Web Development: Java is widely used in server-side applications and frameworks like
Spring.
 Mobile Applications: Forms the core of Android development.
 Enterprise Applications: Used for large-scale systems (banking, e-commerce) due to its
stability.
 Standalone Application
Installing of JDK and NetBean
Objective:
To familiar installation of JDK
1. Download and Install JDK:
Download JDK:
2K24/NFIT/35 Miss. Muskan Aijaz 4 | P a g e
University of Sindh Campus Naushahro Feroze
 Visit the [Oracle JDK download page]
(https://www.oracle.com/java/technologies/javase-downloads.html).
 Click on the JDK version you want to download.
 Choose the Windows installer (.exe) for your system (e.g., jdk-<version>-windows-
x64_bin.exe).
2. Install JDK:
 Run the downloaded .exe file.
 Follow the installation wizard instructions.
 By default, JDK will be installed in C:Program FilesJavajdk-<version>.
3. Set Up JDK Environment Variables:
Set JAVA_HOME:
 Right-click on "This PC" or "Computer" on the desktop or in File Explorer and select
"Properties."
 Click "Advanced system settings."
 In the "System Properties" window, click the "Environment Variables" button.
 Click "New" under "System variables."
 Enter JAVA_HOME as the variable name and the path to the JDK installation directory
(e.g., C:Program FilesJavajdk-<version>) as the variable value.
Update Path Variable:
 In the "Environment Variables" window, find the Path variable in the "System
variables" section and click "Edit."
 Click "New" and add %JAVA_HOME%bin to the list.
 Click "OK" to close all dialogs.
2K24/NFIT/35 Miss. Muskan Aijaz 5 | P a g e
University of Sindh Campus Naushahro Feroze
Installing NetBeans
1. Download NetBeans:
Visit the NetBeans Download Page:
Go to the [NetBeans download page](https://netbeans.apache.org/download/index.html).
Choose the Download Option:
 Select the version suitable for your operating system (Windows, macOS, Linux).
 Typically, you will download a .zip or .dmg file for macOS, a .exe file for Windows,
or a .tar.gz file for Linux.
2. Install NetBeans
1. Run the Installer:
 Locate the downloaded .exe file (e.g., netbeans-<version>-win32-x64.exe).
 Double-click the file to start the installer.
2. Follow the Installation Wizard:
 Click "Next" on the welcome screen.
 Choose the installation directory if needed or proceed with the default location.
 Select the components you want to install (e.g., Java SE, PHP, C/C++). Ensure "Java
SE" is selected if you're planning to develop Java applications.
 Click "Next" and then "Install" to begin the installation.
2K24/NFIT/35 Miss. Muskan Aijaz 6 | P a g e
University of Sindh Campus Naushahro Feroze
 Once the installation is complete, click "Finish" to exit the wizard.
Writing and running a simple "Hello, World!" program:
Objective:
To understand the basic structure of a Java program and to write a simple "Hello, World!"
program.
Input:
Fig: 1.1 It Represent the print method how to print any argument.
Output:
Fig:1.2 It shows print method output.
Structure of a Java Program:
Class Declaration:
2K24/NFIT/35 Miss. Muskan Aijaz 7 | P a g e
University of Sindh Campus Naushahro Feroze
 public class HelloWorld declares a class named HelloWorld.
 The class name should match the filename (in this case, HelloWorld.java)
Main Method:
 public static void main(String[] args) is the entry point where execution starts.
 public: Accessible to any part of the program.
 static: Allows main to run without creating an instance of the class.
 void: Indicates that main doesn’t return any value.
Statements:
 System.out.println("Hello, World!"); prints "Hello, World!" to the console.
Components of a Java Program:
 Class: Defines the structure of the program.
 Public : Keyword is an access modifier which represents visibility. It means it is visible
to all.
 Static is a keyword. The benefit of the static method is that there is no need to create an
object to invoke the static method.
 Void is the return type of the method. It means it doesn't return any value.
 Main Method: Contains the code that will be executed when the program runs.
 Void is the return type of the method. It means it doesn't return any value.
 System.out.println() is used to print statement. Here, System is a class, out is the object
of PrintStream class, println() is the method of PrintStream class.
2K24/NFIT/35 Miss. Muskan Aijaz 8 | P a g e
University of Sindh Campus Naushahro Feroze
Lab #02
Variable, Data Type and It’s Type
Objective:
Variables in Java, including how to declare, initialize, and use different types of variables (local,
instance, and static) to store and manage data effectively within a program.
Different data types in Java, including both primitive and reference types helps us to print
different type of data using java programing language.
Variable:
2K24/NFIT/35 Miss. Muskan Aijaz 9 | P a g e
University of Sindh Campus Naushahro Feroze
A variable is a name given to a memory location. In Java, each variable has a type, which
determines the kind of data it can hold.
2. Types of Variables:
Java supports different types of variables based on their use and scope:
 Local Variables: Declared inside a method or block and can only be used within that
scope.
 Instance Variables: Declared inside a class but outside methods. They are non-static and
associated with an instance of the class.
 Static Variables: Declared inside a class with the static keyword, shared among all
instances of the class.
Fig:2.1 It Shows type of variables.
Data Type:
In Java, data types are divided into two main categories: primitive data types and reference (or
non-primitive) data types.
2K24/NFIT/35 Miss. Muskan Aijaz 10 | P a g e
University of Sindh Campus Naushahro Feroze
1. Primitive Data Types:
Primitive data types are predefined by the Java language and store simple values. There are 8
primitive data types.
i. byte (1 byte: -128 to 127):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 11 | P a g e
Data Type
Primitive
Boolean
boolean
Numeric
Character
char
Integral
Integer
byte short int long
Floating-
point
float double
Non
Primitive
Array String class
University of Sindh Campus Naushahro Feroze
Fig:2.2 It shows how
to use byte data type.
Output:
Fig:2.3 It shows the output of byte data type.
ii. short (2 bytes: -32,768 to 32,767):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 12 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 2.4 It shows how to use short data type.
Output:
Fig: 2.5 It shows the output of short data type.
iii. int (4 bytes: -2^31 to 2^31-1):
Input:
Fig: 2.6 It shows how to use int data type.
2K24/NFIT/35 Miss. Muskan Aijaz 13 | P a g e
University of Sindh Campus Naushahro Feroze
Output:
Fig: 2.7 It shows the output of int
data type.
iv. long (8 bytes: -2^63 to 2^63-1):
Input:
Fig: 2.8 It shows how to
use long data type.
Output:
Fig: 2.9 It shows the
output of long datatype.
2K24/NFIT/35 Miss. Muskan Aijaz 14 | P a g e
University of Sindh Campus Naushahro Feroze
v. float (4 bytes: fractional numbers, single precision):
Input:
Fig: 2.10
It shows how to use float data type.
Output:
Fig: 2.11 It shows the
output of float datatype.
vi. double (8 bytes: fractional numbers, double precision):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 15 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 2.12 It shows how to use double data type.
Output:
Fig: 2.13 It shows the
output of double data type.
vii. char (2 bytes: single character):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 16 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 2.14 It shows how to use char data type.
Output:
Fig:2.15 It shows the output of char data type.
viii. boolean (1 bit: true/false):
Input:
Fig: 2.16 It shows how to use boolean data type.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 17 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 2.17 It shows the output of boolean data type.
2. Non-Primitive (Reference) Data Types:
Reference types store objects and are created by the programmer. They include:
 Classes
 Interfaces
 Arrays
 Strings
Naming Conventions and Rules for Identifiers in Java:
In Java, identifiers are names for variables, methods, classes, and other program elements. Using
consistent naming conventions and rules helps make code readable and maintainable.
1. Naming Rules (Syntax Rules):
 Start with a Letter: Identifiers must begin with a letter (A–Z, a–z), an underscore (_),
or a dollar sign ($).
Example: name, _temp, $value.
 No Spaces or Special Characters: Spaces, symbols, or special characters (except _ and
$) are not allowed.
 No Starting with Numbers: Numbers can be included, but an identifier cannot start
with a digit.
2K24/NFIT/35 Miss. Muskan Aijaz 18 | P a g e
University of Sindh Campus Naushahro Feroze
Example: age1 is valid, but 1age is not.
 Case-Sensitive: Java distinguishes between uppercase and lowercase letters. Count and
count are different identifiers.
2. Naming Conventions:
 Classes and Interfaces: Start with a capital letter, and if multiple words are used,
capitalize each subsequent word (PascalCase).
Example: StudentRecord, AccountManager.
 Methods and Variables: Start with a lowercase letter, and use camelCase for multiple
words.
Example: calculateTotal, employeeId.
 Constants: Use all uppercase letters with underscores between words.
Example: PI, MAX_VALUE.
 Packages: Use all lowercase letters, often following a reverse domain name pattern for
uniqueness.
Example: com.example.myapp.
Type casting (implicit and explicit):
In Java, type casting is used to convert a variable from one data type to another. There are two
main types of type casting: implicit (automatic) and explicit (manual).
1. Implicit Type Casting (Widening):
 This happens automatically when converting a smaller data type to a larger data type,
without data loss. Java handles this conversion internally.
2K24/NFIT/35 Miss. Muskan Aijaz 19 | P a g e
University of Sindh Campus Naushahro Feroze
 Example of widening: byte → short → int → long → float → double
Example:
Input:
Fig: 2.18 It shows how int data type convert into double data type using implicit type
casting.
Output:
Fig: 2.19 It shows the
output of how int data type convert into double data type using implicit type casting.
2. Explicit Type Casting (Narrowing):
2K24/NFIT/35 Miss. Muskan Aijaz 20 | P a g e
University of Sindh Campus Naushahro Feroze
 This is needed when converting a larger data type to a smaller data type, as there may be
data loss. It requires specifying the target data type in parentheses before the value.
 Example of narrowing: double → float → long → int → short → byte.
Example:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 21 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 2.20 It shows how double data type convert into int data type using explicit type
casting.
Output:
Fig: 2.21 It shows the output of how double data type convert into int data type using
explicit type casting.
2K24/NFIT/35 Miss. Muskan Aijaz 22 | P a g e
University of Sindh Campus Naushahro Feroze
Lab #03
Operators and Type of Operators
Objective:
Operators are special symbols used to perform operations on variables and values.
Types of Operators:
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Unary Operators
1. Arithmetic Operators: Perform basic arithmetic operations.
i. Addition (+)
ii. Subtraction (-)
iii. Multiplication (*)
iv. Division (/)
v. Modulus (%)
i. Addition(+):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 23 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.1 It shows how to use Addition(+) Arithmetic Operator.
Output:
Fig: 3.2 It shows the output of Addition(+) Arithmetic Operator.
ii. Subtraction(-):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 24 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.3 It shows how to use Subtraction(-) Arithmetic Operator.
Output:
Fig: 3.4 It shows the
output Subtraction(-) Arithmetic Operator.
iii. Multiplication(*):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 25 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.5 It shows how to use Multiplication(*) Arithmetic Operator.
Output:
Fig: 3.6 It shows the output of Multiplication(*) Arithmetic Operator .
iv. Division(/):
Input:
Fig: 3.7 It shows
how to use Division(/) Arithmetic Operator .
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 26 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.8 It shows the output of Division(/) Arithmetic Operator .
v. Modulus(%):
Input:
Fig: 3.9 It shows how to use Modulus(%) Arithmetic Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 27 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.10 It shows the output of Modulus(%) Arithmetic Operator .
2. Relational Operators: Compare two values.
i. Equal to (==)
ii. Not equal to (!=)
iii. Greater than (>)
iv. Less than (<)
v. Greater than or equal to (>=)
vi. Less than or equal to (<=)
vii. Increment (++)
viii. Decrement (--)
i. Equal to(==):
Input:
Fig: 3.11 It shows how to use Equal to(==) Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 28 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.12 It shows the output of Equal to(==) Relational Operator.
ii. Not equal to( !=):
Input:
Fig: 3.13 It shows how to use Not equal to( !=) Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 29 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.14 It shows the output of Not equal to( !=) Relational Operator.
iii. Greater than(>):
Input:
Fig: 3.15 It shows how to use Greater than(>) Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 30 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.16 It shows the output of Greater than(>) Relational Operator.
iv. Less than(<):
Input:
Fig: 3.17 It shows how to use Less than(<) Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 31 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.18 It shows the output of Less than(<) Relational Operator.
v. Greater than or equal to( >=):
Input:
Fig: 3.19 It shows how to use Greater than or equal to( >=) Relational Operator.
Output:
Fig: 3.20 It shows the
output of Greater than or equal to( >=) Relational Operator.
vi. Less than or equal to(<=):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 32 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.21 It shows how to use Less than or equal to(<=) Relational Operator.
Output:
Fig: 3.21 It shows the
output of Less than or equal to(<=) Relational Operator.
vii. Increment(++)
 Post-Increment
 Pre-Increment
Post-Increment:
Input:
Fig: 3.23 It shows how to use Post-Increment Relational Operator.
2K24/NFIT/35 Miss. Muskan Aijaz 33 | P a g e
University of Sindh Campus Naushahro Feroze
Output:
Fig: 3.24 It shows the
output of Post-Increment Relational Operator.
Pre-Increment:
Input:
Fig: 3.25 It shows how to use Pre-Increment Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 34 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.26 It shows the output of Pre-Increment Relational Operator.
Decrement:
 Post-Decrement
 Pre-Decrement
Post-Decrement:
Input:
Fig: 3.27 It shows how to use Post-Decrement Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 35 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.28 It shows the output of Post-Decrement Relational Operator.
Pre-Decrement:
Input:
Fig: 3.29 It shows how to use Pre-Decrement Relational Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 36 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.30 It shows the output of Pre-Decrement Relational Operator.
3. Logical Operators: Perform logical operations.
i. Logical AND (&&)
ii. Logical OR (||)
iii. Logical NOT (!)
i. Logical AND(&&):
Input:
Fig: 3.31 It shows how to use Logical AND(&&) Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 37 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.32 It shows the output of Logical AND(&&) Operator.
ii. Logical OR(||):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 38 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.33 It shows how to use Logical OR(||) Operator.
Output:
Fig: 3.34 It shows the output of Logical OR(||) Operator.
iii. Logical NOT(!):
Input:
Fig: 3.35 It shows how to use Logical NOT(!) Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 39 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.36 It shows the output of Logical NOT(!) Operator.
Combining Logical Operators:
Input:
Fig: 3.37
It shows how to use Combining Logical Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 40 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.38 It shows the output of Combining Logical Operator.
4. Assignment Operators: Assign values to variables.
i. Assign(=)
ii. Addition assignment( +=)
iii. Subtraction assignment (-=)
iv. Multiplication assignment (*=)
v. Division assignment(/=)
vi. Modulus assignment( %= )
i. Assign(=):
Input:
Fig: 3.39 It shows how to assign value using Assign(=) Assignment Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 41 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.40 It shows the output of assign value using Assign(=) Assignment Operator.
ii. Addition assignment (+=):
Input:
Fig: 3.41 It shows how to assign value using Addition assignment (+=) Assignment
Operator.
Output:
Fig: 3.42 It shows
the output of assign value using Addition assignment (+=) Assignment Operator.
iii. Subtraction assignment (-=):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 42 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.43 It shows how to assign value using Subtraction assignment (-=)Assignment
Operator.
Output:
Fig: 3.44 It shows
the output of assign value using Subtraction assignment (-=)Assignment Operator.
iv. Multiplication assignment( *=):
Input:
Fig: 3.45 It shows how to assign value using Multiplication
assignment( *=)Assignment Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 43 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.46 It shows the output of assign value using Multiplication
assignment( *=)Assignment Operator.
v. Division assignment(/=):
Input:
Fig: 3.47 It shows how to assign value using Division assignment(/=) Assignment
Operator.
Output:
Fig: 3.48 It shows the output of assign value using Division assignment(/=)
Assignment Operator.
2K24/NFIT/35 Miss. Muskan Aijaz 44 | P a g e
University of Sindh Campus Naushahro Feroze
vi. Modulus assignment (%= ):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 45 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.49 It shows how to assign value using Modulus assignment (%= )Assignment
Operator.
Output:
Fig: 3.50 It shows the
output of assign value using Modulus assignment (%= )Assignment Operator.
5. Unary Operators:
i. Unary Plus (+)
ii. Unary Minus (-)
iii. Increment (++)
iv. Decrement (--)
v. NOT’ Operator(!)
i. Unary Plus (+):
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 46 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.51 It shows how to use Unary Plus (+) Operator.
Output:
Fig: 3.52 It shows the output of Unary Plus (+) Operator.
ii. Unary Minus (-):
Input:
Fig: 3.53 It shows
how to use Unary Minus (-) Operator.
2K24/NFIT/35 Miss. Muskan Aijaz 47 | P a g e
University of Sindh Campus Naushahro Feroze
Output:
Fig: 3.54 It shows the
output of Unary Minus (-) Operator.
iii. Increment (++):
a. Post-Increment Operator
b. Pre-Increment Operator
a. Post-Increment Operator:
Input:
Fig: 3.55 It shows how to use Unary Post-Increment Operator.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 48 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.56 It shows the output of Unary Post-Increment Operator.
b. Pre-Increment Operator:
Input:
Fig: 3.57 It shows how to use Unary Pre-Increment Operator.
Output:
Fig: 3.58 It shows the
output of Unary Pre-Increment Operator.
2K24/NFIT/35 Miss. Muskan Aijaz 49 | P a g e
University of Sindh Campus Naushahro Feroze
iv. Decrement (--):
a. Post-Decrement
b. Pre-Decrement
a. Post-Decrement:
Input:
Fig: 3.59 It shows how to use Unary Post-Decrement Operator.
Output:
Fig: 3.60 It shows the
output of Unary Post-Decrement Operator.
b. Pre-Decrement:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 50 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.61 It shows how to use Unary Pre-Decrement Operator.
Output:
Fig: 3.62 It shows the output of Unary Pre-Decrement Operator.
v. NOT(!) Operator:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 51 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 3.63 It shows how to use Unary NOT(!) Operator.
Output:
Fig: 3.64S It shows the output of Unary NOT(!) Operator.
Lab #04
Control Statements
Objective:
Control statements is to understand how to manage the flow of a program using conditional,
looping, and branching statements.
Control Statements are categorized into three main types:
2K24/NFIT/35 Miss. Muskan Aijaz 52 | P a g e
University of Sindh Campus Naushahro Feroze
1. Conditional Statements
2. Switch Statement
3. Looping Statement
1. Conditional Statements:
i. if statement
ii. if-else statement
iii. if-else-if ladder
iv. nested if statement
i. if statement:
Input:
Fig: 4.1 It
shows how to use if Conditional Statement.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 53 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 4.2 It shows the output of if Conditional Statement.
ii.if-else statement:
Input:
Fig: 4.3
It shows how to use if-else Conditional Statement.
Output:
Fig: 4.4 It shows the
output of if-else Conditional Statement.
iii. if-else-if ladder:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 54 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 4.5 It shows how to use if-else-if ladder Conditional Statement.
Output:
Fig: 4.6 It shows the output of if-else-if ladder Conditional Statement.
iv. nested if statement:
Input:
Fig: 4.7 It shows how to use nested if Conditional Statement.
2K24/NFIT/35 Miss. Muskan Aijaz 55 | P a g e
University of Sindh Campus Naushahro Feroze
Output:
Fig: 4.8 It shows the output of nested if Conditional Statement.
2. Switch Statement:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 56 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 4.9 It shows the input of Switch Statement.
Output:
Fig: 4.10 It
shows the output of Switch Statement.
3. Looping Statement :
i. for loop
ii. while loop
iii. do-while loop
2K24/NFIT/35 Miss. Muskan Aijaz 57 | P a g e
University of Sindh Campus Naushahro Feroze
i. for loop
Input:
Fig: 4.11 It shows the input of for loop Statement.
Output:
Fig: 4.12 It shows the output of for loop Statement.
ii. while loop:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 58 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 4.13 It shows the input of while loop Statement.
Output:
Fig: 4.14 It shows the
output of while loop Statement.
iii. do-while loop:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 59 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 4.15 It shows the input of do while loop Statement.
Output:
Fig: 4.16 It shows the output of do while loop Statement.
2K24/NFIT/35 Miss. Muskan Aijaz 60 | P a g e
University of Sindh Campus Naushahro Feroze
Lab # 5
Methods and Functions
Objective:
A method in Java is a block of code designed to perform a specific task.
Functions and methods are often used interchangeably in Java, they are referred to as
methods.Methods and Functions in Java:
1. Defining and Calling Methods
 Definition: A method is defined with a name, return type, parameters (optional), and a body.
 Calling: Methods are called using the method name, and parameters (if any) are passed
during the call.
Code Example:
Input:
Fig: 5.1 It Shows how we call the method.
2K24/NFIT/35 Miss. Muskan Aijaz 61 | P a g e
University of Sindh Campus Naushahro Feroze
Output:
Fig: 5.2 It Shows the output of call the method
2. Method Overloading
 Definition: Method overloading allows multiple methods with the same name but different
parameter lists (types or number of arguments).
 Use: Improves code readability and reuse.
Code Example:
Fig: 5.3 It Shows how to we call the overloading method.
2K24/NFIT/35 Miss. Muskan Aijaz 62 | P a g e
University of Sindh Campus Naushahro Feroze
Output:
Fig: 5.4
It Shows the output of calling overloading method.
3.Parameterized vs Non-Parameterized Methods:
Non-Parameterized:
Input:
Fig: 5.5 It Shows the input of non-parameterized method.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 63 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 5.6 It Shows the output of non-parameterized method.
Parameterized:
Input:
Fig: 5.7 It Shows the input of parameterized method.
Output:
Fig: 5.8 It Shows the output of parameterized method.
2K24/NFIT/35 Miss. Muskan Aijaz 64 | P a g e
University of Sindh Campus Naushahro Feroze
Lab #6
Object-Oriented Programming (OOP) in Java
Objective:
Objects and classes in Java, their role in object-oriented programming, and how to implement
them in real-world applications.
.
1. Classes and Objects
 Class: A class is a blueprint or template for creating objects.
It defines the properties (fields) and behaviors (methods) that an object can have.
 Object: An object is an instance of a class.
It represents a specific entity with unique values for the properties defined in the class.
Code Example:
Input:
2K24/NFIT/35 Miss. Muskan Aijaz 65 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 6.1 It Shows how to use class and object at a time.
Output:
2K24/NFIT/35 Miss. Muskan Aijaz 66 | P a g e
University of Sindh Campus Naushahro Feroze
Fig: 6.2 It Shows the output of class and object.
2K24/NFIT/35 Miss. Muskan Aijaz 67 | P a g e

More Related Content

PPTX
Unit-1_GHD.pptxguguigihihihihihihoihihhi
PPT
Java SpringMVC SpringBOOT (Divergent).ppt
PPTX
Java platform
PPTX
JAVA Module 1______________________.pptx
PPTX
Java Basics.pptx from nit patna ece department
DOC
java handout.doc
PPTX
Core java &collections
PPTX
Core java1
Unit-1_GHD.pptxguguigihihihihihihoihihhi
Java SpringMVC SpringBOOT (Divergent).ppt
Java platform
JAVA Module 1______________________.pptx
Java Basics.pptx from nit patna ece department
java handout.doc
Core java &collections
Core java1

Similar to Object Oriented programming language (PRACTICAL LAB MANUAL) (20)

PPTX
Core java
PDF
JAVA PPT-1 BY ADI.pdf
PDF
JAVA PPT Part-1 BY ADI.pdf
PDF
Programming in Java Unit 1 lesson Notes for Java
PPT
java introduction
PPTX
Object oriented programming1 Week 1.pptx
PPTX
Java programming(unit 1)
PPTX
lecture 6
PPTX
Introduction to computer science
PPT
a basic java programming and data type.ppt
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
PPTX
2. Introduction to Java for engineering stud
PPT
Unit 2 Java
PDF
M251_Meeting 1(M251_Meeting 1_updated.pdf)
PPTX
Class 8 - Java.pptx
PPT
JAVA_BASICS.ppt
PPTX
Advanced java programming - DATA TYPES, VARIABLES, ARRAYS
PDF
Complete Java Course
PPT
CSL101_Ch1.ppt Computer Science
PPT
Programming with Java by Faizan Ahmed & Team
Core java
JAVA PPT-1 BY ADI.pdf
JAVA PPT Part-1 BY ADI.pdf
Programming in Java Unit 1 lesson Notes for Java
java introduction
Object oriented programming1 Week 1.pptx
Java programming(unit 1)
lecture 6
Introduction to computer science
a basic java programming and data type.ppt
Java programming material for beginners by Nithin, VVCE, Mysuru
2. Introduction to Java for engineering stud
Unit 2 Java
M251_Meeting 1(M251_Meeting 1_updated.pdf)
Class 8 - Java.pptx
JAVA_BASICS.ppt
Advanced java programming - DATA TYPES, VARIABLES, ARRAYS
Complete Java Course
CSL101_Ch1.ppt Computer Science
Programming with Java by Faizan Ahmed & Team
Ad

Recently uploaded (20)

PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPT
Introduction Database Management System for Course Database
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
history of c programming in notes for students .pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
L1 - Introduction to python Backend.pptx
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Softaken Excel to vCard Converter Software.pdf
PTS Company Brochure 2025 (1).pdf.......
Digital Systems & Binary Numbers (comprehensive )
Reimagine Home Health with the Power of Agentic AI​
Introduction Database Management System for Course Database
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
CHAPTER 2 - PM Management and IT Context
Upgrade and Innovation Strategies for SAP ERP Customers
history of c programming in notes for students .pptx
Odoo Companies in India – Driving Business Transformation.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
L1 - Introduction to python Backend.pptx
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms II-SECS-1021-03
Design an Analysis of Algorithms I-SECS-1021-03
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Softaken Excel to vCard Converter Software.pdf
Ad

Object Oriented programming language (PRACTICAL LAB MANUAL)

  • 1. University of Sindh Campus Naushahro Feroze Subject Object Oriented Programing Student Name Muskan Aijaz Roll No 2k24/NFIT/35 Teacher Name Sir Khalid Date of Submission 2-Dec-2024 Practical Lab Manual
  • 2. University of Sindh Campus Naushahro Feroze CERTIFICATE This is to certify that Ms. Muskan Aijaz of 2k24 BS (IT) class bearing Roll No. 2k24/NFIT/35 has carried out the necessary Project work as per course of studies Object Oriented Programing “OOP’s” for the 1st Year 2nd Semester as above in practical schedule of his journal. 2K24/NFIT/35 Miss. Muskan Aijaz 2 | P a g e
  • 3. University of Sindh Campus Naushahro Feroze Index Lab #01 Introduction to Java Programming Objective: Introduction to Java Programming: Java is an object-oriented programming language valued for its portability, allowing code to run on any device with a Java Virtual Machine (JVM). Overview of Java: History:  Java was developed by James Ghosling, Patrick Naughton, Mike Sheridan at Sun Microsystems Inc. in 1991. It took 18 months to develop the first working version.  Java was designed with a “write once, run anywhere” philosophy. 2K24/NFIT/35 Miss. Muskan Aijaz 3 | P a g e S.No Name Of Lab Manual Page. No 1 Introduction to java Programing 4-9 2 Variables and Data Types 10-22 3 Operators in Java 23-51 4 Control Statements, Conditional Statements 52-60 5 Methods and Functions 61-64 6 Object Oriented Programing(OOP’s) in Java 65-66
  • 4. University of Sindh Campus Naushahro Feroze  The initial name was Oak but it was renamed to Java in 1995 as OAK was a registered trademark of another Tech company. Features:  Platform Independence: Java programs can run on any device with a Java Virtual Machine (JVM).  Object-Oriented: Encourages modular code with reusable classes.  Robust and Secure: Exception handling and security features make it reliable.  High Performance: Bytecode execution provides speed while retaining platform flexibility.  Multithreading: Supports concurrent execution, optimizing performance. Uses: Java is used in:  Web Development: Java is widely used in server-side applications and frameworks like Spring.  Mobile Applications: Forms the core of Android development.  Enterprise Applications: Used for large-scale systems (banking, e-commerce) due to its stability.  Standalone Application Installing of JDK and NetBean Objective: To familiar installation of JDK 1. Download and Install JDK: Download JDK: 2K24/NFIT/35 Miss. Muskan Aijaz 4 | P a g e
  • 5. University of Sindh Campus Naushahro Feroze  Visit the [Oracle JDK download page] (https://www.oracle.com/java/technologies/javase-downloads.html).  Click on the JDK version you want to download.  Choose the Windows installer (.exe) for your system (e.g., jdk-<version>-windows- x64_bin.exe). 2. Install JDK:  Run the downloaded .exe file.  Follow the installation wizard instructions.  By default, JDK will be installed in C:Program FilesJavajdk-<version>. 3. Set Up JDK Environment Variables: Set JAVA_HOME:  Right-click on "This PC" or "Computer" on the desktop or in File Explorer and select "Properties."  Click "Advanced system settings."  In the "System Properties" window, click the "Environment Variables" button.  Click "New" under "System variables."  Enter JAVA_HOME as the variable name and the path to the JDK installation directory (e.g., C:Program FilesJavajdk-<version>) as the variable value. Update Path Variable:  In the "Environment Variables" window, find the Path variable in the "System variables" section and click "Edit."  Click "New" and add %JAVA_HOME%bin to the list.  Click "OK" to close all dialogs. 2K24/NFIT/35 Miss. Muskan Aijaz 5 | P a g e
  • 6. University of Sindh Campus Naushahro Feroze Installing NetBeans 1. Download NetBeans: Visit the NetBeans Download Page: Go to the [NetBeans download page](https://netbeans.apache.org/download/index.html). Choose the Download Option:  Select the version suitable for your operating system (Windows, macOS, Linux).  Typically, you will download a .zip or .dmg file for macOS, a .exe file for Windows, or a .tar.gz file for Linux. 2. Install NetBeans 1. Run the Installer:  Locate the downloaded .exe file (e.g., netbeans-<version>-win32-x64.exe).  Double-click the file to start the installer. 2. Follow the Installation Wizard:  Click "Next" on the welcome screen.  Choose the installation directory if needed or proceed with the default location.  Select the components you want to install (e.g., Java SE, PHP, C/C++). Ensure "Java SE" is selected if you're planning to develop Java applications.  Click "Next" and then "Install" to begin the installation. 2K24/NFIT/35 Miss. Muskan Aijaz 6 | P a g e
  • 7. University of Sindh Campus Naushahro Feroze  Once the installation is complete, click "Finish" to exit the wizard. Writing and running a simple "Hello, World!" program: Objective: To understand the basic structure of a Java program and to write a simple "Hello, World!" program. Input: Fig: 1.1 It Represent the print method how to print any argument. Output: Fig:1.2 It shows print method output. Structure of a Java Program: Class Declaration: 2K24/NFIT/35 Miss. Muskan Aijaz 7 | P a g e
  • 8. University of Sindh Campus Naushahro Feroze  public class HelloWorld declares a class named HelloWorld.  The class name should match the filename (in this case, HelloWorld.java) Main Method:  public static void main(String[] args) is the entry point where execution starts.  public: Accessible to any part of the program.  static: Allows main to run without creating an instance of the class.  void: Indicates that main doesn’t return any value. Statements:  System.out.println("Hello, World!"); prints "Hello, World!" to the console. Components of a Java Program:  Class: Defines the structure of the program.  Public : Keyword is an access modifier which represents visibility. It means it is visible to all.  Static is a keyword. The benefit of the static method is that there is no need to create an object to invoke the static method.  Void is the return type of the method. It means it doesn't return any value.  Main Method: Contains the code that will be executed when the program runs.  Void is the return type of the method. It means it doesn't return any value.  System.out.println() is used to print statement. Here, System is a class, out is the object of PrintStream class, println() is the method of PrintStream class. 2K24/NFIT/35 Miss. Muskan Aijaz 8 | P a g e
  • 9. University of Sindh Campus Naushahro Feroze Lab #02 Variable, Data Type and It’s Type Objective: Variables in Java, including how to declare, initialize, and use different types of variables (local, instance, and static) to store and manage data effectively within a program. Different data types in Java, including both primitive and reference types helps us to print different type of data using java programing language. Variable: 2K24/NFIT/35 Miss. Muskan Aijaz 9 | P a g e
  • 10. University of Sindh Campus Naushahro Feroze A variable is a name given to a memory location. In Java, each variable has a type, which determines the kind of data it can hold. 2. Types of Variables: Java supports different types of variables based on their use and scope:  Local Variables: Declared inside a method or block and can only be used within that scope.  Instance Variables: Declared inside a class but outside methods. They are non-static and associated with an instance of the class.  Static Variables: Declared inside a class with the static keyword, shared among all instances of the class. Fig:2.1 It Shows type of variables. Data Type: In Java, data types are divided into two main categories: primitive data types and reference (or non-primitive) data types. 2K24/NFIT/35 Miss. Muskan Aijaz 10 | P a g e
  • 11. University of Sindh Campus Naushahro Feroze 1. Primitive Data Types: Primitive data types are predefined by the Java language and store simple values. There are 8 primitive data types. i. byte (1 byte: -128 to 127): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 11 | P a g e Data Type Primitive Boolean boolean Numeric Character char Integral Integer byte short int long Floating- point float double Non Primitive Array String class
  • 12. University of Sindh Campus Naushahro Feroze Fig:2.2 It shows how to use byte data type. Output: Fig:2.3 It shows the output of byte data type. ii. short (2 bytes: -32,768 to 32,767): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 12 | P a g e
  • 13. University of Sindh Campus Naushahro Feroze Fig: 2.4 It shows how to use short data type. Output: Fig: 2.5 It shows the output of short data type. iii. int (4 bytes: -2^31 to 2^31-1): Input: Fig: 2.6 It shows how to use int data type. 2K24/NFIT/35 Miss. Muskan Aijaz 13 | P a g e
  • 14. University of Sindh Campus Naushahro Feroze Output: Fig: 2.7 It shows the output of int data type. iv. long (8 bytes: -2^63 to 2^63-1): Input: Fig: 2.8 It shows how to use long data type. Output: Fig: 2.9 It shows the output of long datatype. 2K24/NFIT/35 Miss. Muskan Aijaz 14 | P a g e
  • 15. University of Sindh Campus Naushahro Feroze v. float (4 bytes: fractional numbers, single precision): Input: Fig: 2.10 It shows how to use float data type. Output: Fig: 2.11 It shows the output of float datatype. vi. double (8 bytes: fractional numbers, double precision): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 15 | P a g e
  • 16. University of Sindh Campus Naushahro Feroze Fig: 2.12 It shows how to use double data type. Output: Fig: 2.13 It shows the output of double data type. vii. char (2 bytes: single character): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 16 | P a g e
  • 17. University of Sindh Campus Naushahro Feroze Fig: 2.14 It shows how to use char data type. Output: Fig:2.15 It shows the output of char data type. viii. boolean (1 bit: true/false): Input: Fig: 2.16 It shows how to use boolean data type. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 17 | P a g e
  • 18. University of Sindh Campus Naushahro Feroze Fig: 2.17 It shows the output of boolean data type. 2. Non-Primitive (Reference) Data Types: Reference types store objects and are created by the programmer. They include:  Classes  Interfaces  Arrays  Strings Naming Conventions and Rules for Identifiers in Java: In Java, identifiers are names for variables, methods, classes, and other program elements. Using consistent naming conventions and rules helps make code readable and maintainable. 1. Naming Rules (Syntax Rules):  Start with a Letter: Identifiers must begin with a letter (A–Z, a–z), an underscore (_), or a dollar sign ($). Example: name, _temp, $value.  No Spaces or Special Characters: Spaces, symbols, or special characters (except _ and $) are not allowed.  No Starting with Numbers: Numbers can be included, but an identifier cannot start with a digit. 2K24/NFIT/35 Miss. Muskan Aijaz 18 | P a g e
  • 19. University of Sindh Campus Naushahro Feroze Example: age1 is valid, but 1age is not.  Case-Sensitive: Java distinguishes between uppercase and lowercase letters. Count and count are different identifiers. 2. Naming Conventions:  Classes and Interfaces: Start with a capital letter, and if multiple words are used, capitalize each subsequent word (PascalCase). Example: StudentRecord, AccountManager.  Methods and Variables: Start with a lowercase letter, and use camelCase for multiple words. Example: calculateTotal, employeeId.  Constants: Use all uppercase letters with underscores between words. Example: PI, MAX_VALUE.  Packages: Use all lowercase letters, often following a reverse domain name pattern for uniqueness. Example: com.example.myapp. Type casting (implicit and explicit): In Java, type casting is used to convert a variable from one data type to another. There are two main types of type casting: implicit (automatic) and explicit (manual). 1. Implicit Type Casting (Widening):  This happens automatically when converting a smaller data type to a larger data type, without data loss. Java handles this conversion internally. 2K24/NFIT/35 Miss. Muskan Aijaz 19 | P a g e
  • 20. University of Sindh Campus Naushahro Feroze  Example of widening: byte → short → int → long → float → double Example: Input: Fig: 2.18 It shows how int data type convert into double data type using implicit type casting. Output: Fig: 2.19 It shows the output of how int data type convert into double data type using implicit type casting. 2. Explicit Type Casting (Narrowing): 2K24/NFIT/35 Miss. Muskan Aijaz 20 | P a g e
  • 21. University of Sindh Campus Naushahro Feroze  This is needed when converting a larger data type to a smaller data type, as there may be data loss. It requires specifying the target data type in parentheses before the value.  Example of narrowing: double → float → long → int → short → byte. Example: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 21 | P a g e
  • 22. University of Sindh Campus Naushahro Feroze Fig: 2.20 It shows how double data type convert into int data type using explicit type casting. Output: Fig: 2.21 It shows the output of how double data type convert into int data type using explicit type casting. 2K24/NFIT/35 Miss. Muskan Aijaz 22 | P a g e
  • 23. University of Sindh Campus Naushahro Feroze Lab #03 Operators and Type of Operators Objective: Operators are special symbols used to perform operations on variables and values. Types of Operators: 1. Arithmetic Operators 2. Relational Operators 3. Logical Operators 4. Assignment Operators 5. Unary Operators 1. Arithmetic Operators: Perform basic arithmetic operations. i. Addition (+) ii. Subtraction (-) iii. Multiplication (*) iv. Division (/) v. Modulus (%) i. Addition(+): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 23 | P a g e
  • 24. University of Sindh Campus Naushahro Feroze Fig: 3.1 It shows how to use Addition(+) Arithmetic Operator. Output: Fig: 3.2 It shows the output of Addition(+) Arithmetic Operator. ii. Subtraction(-): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 24 | P a g e
  • 25. University of Sindh Campus Naushahro Feroze Fig: 3.3 It shows how to use Subtraction(-) Arithmetic Operator. Output: Fig: 3.4 It shows the output Subtraction(-) Arithmetic Operator. iii. Multiplication(*): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 25 | P a g e
  • 26. University of Sindh Campus Naushahro Feroze Fig: 3.5 It shows how to use Multiplication(*) Arithmetic Operator. Output: Fig: 3.6 It shows the output of Multiplication(*) Arithmetic Operator . iv. Division(/): Input: Fig: 3.7 It shows how to use Division(/) Arithmetic Operator . Output: 2K24/NFIT/35 Miss. Muskan Aijaz 26 | P a g e
  • 27. University of Sindh Campus Naushahro Feroze Fig: 3.8 It shows the output of Division(/) Arithmetic Operator . v. Modulus(%): Input: Fig: 3.9 It shows how to use Modulus(%) Arithmetic Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 27 | P a g e
  • 28. University of Sindh Campus Naushahro Feroze Fig: 3.10 It shows the output of Modulus(%) Arithmetic Operator . 2. Relational Operators: Compare two values. i. Equal to (==) ii. Not equal to (!=) iii. Greater than (>) iv. Less than (<) v. Greater than or equal to (>=) vi. Less than or equal to (<=) vii. Increment (++) viii. Decrement (--) i. Equal to(==): Input: Fig: 3.11 It shows how to use Equal to(==) Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 28 | P a g e
  • 29. University of Sindh Campus Naushahro Feroze Fig: 3.12 It shows the output of Equal to(==) Relational Operator. ii. Not equal to( !=): Input: Fig: 3.13 It shows how to use Not equal to( !=) Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 29 | P a g e
  • 30. University of Sindh Campus Naushahro Feroze Fig: 3.14 It shows the output of Not equal to( !=) Relational Operator. iii. Greater than(>): Input: Fig: 3.15 It shows how to use Greater than(>) Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 30 | P a g e
  • 31. University of Sindh Campus Naushahro Feroze Fig: 3.16 It shows the output of Greater than(>) Relational Operator. iv. Less than(<): Input: Fig: 3.17 It shows how to use Less than(<) Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 31 | P a g e
  • 32. University of Sindh Campus Naushahro Feroze Fig: 3.18 It shows the output of Less than(<) Relational Operator. v. Greater than or equal to( >=): Input: Fig: 3.19 It shows how to use Greater than or equal to( >=) Relational Operator. Output: Fig: 3.20 It shows the output of Greater than or equal to( >=) Relational Operator. vi. Less than or equal to(<=): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 32 | P a g e
  • 33. University of Sindh Campus Naushahro Feroze Fig: 3.21 It shows how to use Less than or equal to(<=) Relational Operator. Output: Fig: 3.21 It shows the output of Less than or equal to(<=) Relational Operator. vii. Increment(++)  Post-Increment  Pre-Increment Post-Increment: Input: Fig: 3.23 It shows how to use Post-Increment Relational Operator. 2K24/NFIT/35 Miss. Muskan Aijaz 33 | P a g e
  • 34. University of Sindh Campus Naushahro Feroze Output: Fig: 3.24 It shows the output of Post-Increment Relational Operator. Pre-Increment: Input: Fig: 3.25 It shows how to use Pre-Increment Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 34 | P a g e
  • 35. University of Sindh Campus Naushahro Feroze Fig: 3.26 It shows the output of Pre-Increment Relational Operator. Decrement:  Post-Decrement  Pre-Decrement Post-Decrement: Input: Fig: 3.27 It shows how to use Post-Decrement Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 35 | P a g e
  • 36. University of Sindh Campus Naushahro Feroze Fig: 3.28 It shows the output of Post-Decrement Relational Operator. Pre-Decrement: Input: Fig: 3.29 It shows how to use Pre-Decrement Relational Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 36 | P a g e
  • 37. University of Sindh Campus Naushahro Feroze Fig: 3.30 It shows the output of Pre-Decrement Relational Operator. 3. Logical Operators: Perform logical operations. i. Logical AND (&&) ii. Logical OR (||) iii. Logical NOT (!) i. Logical AND(&&): Input: Fig: 3.31 It shows how to use Logical AND(&&) Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 37 | P a g e
  • 38. University of Sindh Campus Naushahro Feroze Fig: 3.32 It shows the output of Logical AND(&&) Operator. ii. Logical OR(||): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 38 | P a g e
  • 39. University of Sindh Campus Naushahro Feroze Fig: 3.33 It shows how to use Logical OR(||) Operator. Output: Fig: 3.34 It shows the output of Logical OR(||) Operator. iii. Logical NOT(!): Input: Fig: 3.35 It shows how to use Logical NOT(!) Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 39 | P a g e
  • 40. University of Sindh Campus Naushahro Feroze Fig: 3.36 It shows the output of Logical NOT(!) Operator. Combining Logical Operators: Input: Fig: 3.37 It shows how to use Combining Logical Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 40 | P a g e
  • 41. University of Sindh Campus Naushahro Feroze Fig: 3.38 It shows the output of Combining Logical Operator. 4. Assignment Operators: Assign values to variables. i. Assign(=) ii. Addition assignment( +=) iii. Subtraction assignment (-=) iv. Multiplication assignment (*=) v. Division assignment(/=) vi. Modulus assignment( %= ) i. Assign(=): Input: Fig: 3.39 It shows how to assign value using Assign(=) Assignment Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 41 | P a g e
  • 42. University of Sindh Campus Naushahro Feroze Fig: 3.40 It shows the output of assign value using Assign(=) Assignment Operator. ii. Addition assignment (+=): Input: Fig: 3.41 It shows how to assign value using Addition assignment (+=) Assignment Operator. Output: Fig: 3.42 It shows the output of assign value using Addition assignment (+=) Assignment Operator. iii. Subtraction assignment (-=): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 42 | P a g e
  • 43. University of Sindh Campus Naushahro Feroze Fig: 3.43 It shows how to assign value using Subtraction assignment (-=)Assignment Operator. Output: Fig: 3.44 It shows the output of assign value using Subtraction assignment (-=)Assignment Operator. iv. Multiplication assignment( *=): Input: Fig: 3.45 It shows how to assign value using Multiplication assignment( *=)Assignment Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 43 | P a g e
  • 44. University of Sindh Campus Naushahro Feroze Fig: 3.46 It shows the output of assign value using Multiplication assignment( *=)Assignment Operator. v. Division assignment(/=): Input: Fig: 3.47 It shows how to assign value using Division assignment(/=) Assignment Operator. Output: Fig: 3.48 It shows the output of assign value using Division assignment(/=) Assignment Operator. 2K24/NFIT/35 Miss. Muskan Aijaz 44 | P a g e
  • 45. University of Sindh Campus Naushahro Feroze vi. Modulus assignment (%= ): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 45 | P a g e
  • 46. University of Sindh Campus Naushahro Feroze Fig: 3.49 It shows how to assign value using Modulus assignment (%= )Assignment Operator. Output: Fig: 3.50 It shows the output of assign value using Modulus assignment (%= )Assignment Operator. 5. Unary Operators: i. Unary Plus (+) ii. Unary Minus (-) iii. Increment (++) iv. Decrement (--) v. NOT’ Operator(!) i. Unary Plus (+): Input: 2K24/NFIT/35 Miss. Muskan Aijaz 46 | P a g e
  • 47. University of Sindh Campus Naushahro Feroze Fig: 3.51 It shows how to use Unary Plus (+) Operator. Output: Fig: 3.52 It shows the output of Unary Plus (+) Operator. ii. Unary Minus (-): Input: Fig: 3.53 It shows how to use Unary Minus (-) Operator. 2K24/NFIT/35 Miss. Muskan Aijaz 47 | P a g e
  • 48. University of Sindh Campus Naushahro Feroze Output: Fig: 3.54 It shows the output of Unary Minus (-) Operator. iii. Increment (++): a. Post-Increment Operator b. Pre-Increment Operator a. Post-Increment Operator: Input: Fig: 3.55 It shows how to use Unary Post-Increment Operator. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 48 | P a g e
  • 49. University of Sindh Campus Naushahro Feroze Fig: 3.56 It shows the output of Unary Post-Increment Operator. b. Pre-Increment Operator: Input: Fig: 3.57 It shows how to use Unary Pre-Increment Operator. Output: Fig: 3.58 It shows the output of Unary Pre-Increment Operator. 2K24/NFIT/35 Miss. Muskan Aijaz 49 | P a g e
  • 50. University of Sindh Campus Naushahro Feroze iv. Decrement (--): a. Post-Decrement b. Pre-Decrement a. Post-Decrement: Input: Fig: 3.59 It shows how to use Unary Post-Decrement Operator. Output: Fig: 3.60 It shows the output of Unary Post-Decrement Operator. b. Pre-Decrement: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 50 | P a g e
  • 51. University of Sindh Campus Naushahro Feroze Fig: 3.61 It shows how to use Unary Pre-Decrement Operator. Output: Fig: 3.62 It shows the output of Unary Pre-Decrement Operator. v. NOT(!) Operator: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 51 | P a g e
  • 52. University of Sindh Campus Naushahro Feroze Fig: 3.63 It shows how to use Unary NOT(!) Operator. Output: Fig: 3.64S It shows the output of Unary NOT(!) Operator. Lab #04 Control Statements Objective: Control statements is to understand how to manage the flow of a program using conditional, looping, and branching statements. Control Statements are categorized into three main types: 2K24/NFIT/35 Miss. Muskan Aijaz 52 | P a g e
  • 53. University of Sindh Campus Naushahro Feroze 1. Conditional Statements 2. Switch Statement 3. Looping Statement 1. Conditional Statements: i. if statement ii. if-else statement iii. if-else-if ladder iv. nested if statement i. if statement: Input: Fig: 4.1 It shows how to use if Conditional Statement. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 53 | P a g e
  • 54. University of Sindh Campus Naushahro Feroze Fig: 4.2 It shows the output of if Conditional Statement. ii.if-else statement: Input: Fig: 4.3 It shows how to use if-else Conditional Statement. Output: Fig: 4.4 It shows the output of if-else Conditional Statement. iii. if-else-if ladder: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 54 | P a g e
  • 55. University of Sindh Campus Naushahro Feroze Fig: 4.5 It shows how to use if-else-if ladder Conditional Statement. Output: Fig: 4.6 It shows the output of if-else-if ladder Conditional Statement. iv. nested if statement: Input: Fig: 4.7 It shows how to use nested if Conditional Statement. 2K24/NFIT/35 Miss. Muskan Aijaz 55 | P a g e
  • 56. University of Sindh Campus Naushahro Feroze Output: Fig: 4.8 It shows the output of nested if Conditional Statement. 2. Switch Statement: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 56 | P a g e
  • 57. University of Sindh Campus Naushahro Feroze Fig: 4.9 It shows the input of Switch Statement. Output: Fig: 4.10 It shows the output of Switch Statement. 3. Looping Statement : i. for loop ii. while loop iii. do-while loop 2K24/NFIT/35 Miss. Muskan Aijaz 57 | P a g e
  • 58. University of Sindh Campus Naushahro Feroze i. for loop Input: Fig: 4.11 It shows the input of for loop Statement. Output: Fig: 4.12 It shows the output of for loop Statement. ii. while loop: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 58 | P a g e
  • 59. University of Sindh Campus Naushahro Feroze Fig: 4.13 It shows the input of while loop Statement. Output: Fig: 4.14 It shows the output of while loop Statement. iii. do-while loop: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 59 | P a g e
  • 60. University of Sindh Campus Naushahro Feroze Fig: 4.15 It shows the input of do while loop Statement. Output: Fig: 4.16 It shows the output of do while loop Statement. 2K24/NFIT/35 Miss. Muskan Aijaz 60 | P a g e
  • 61. University of Sindh Campus Naushahro Feroze Lab # 5 Methods and Functions Objective: A method in Java is a block of code designed to perform a specific task. Functions and methods are often used interchangeably in Java, they are referred to as methods.Methods and Functions in Java: 1. Defining and Calling Methods  Definition: A method is defined with a name, return type, parameters (optional), and a body.  Calling: Methods are called using the method name, and parameters (if any) are passed during the call. Code Example: Input: Fig: 5.1 It Shows how we call the method. 2K24/NFIT/35 Miss. Muskan Aijaz 61 | P a g e
  • 62. University of Sindh Campus Naushahro Feroze Output: Fig: 5.2 It Shows the output of call the method 2. Method Overloading  Definition: Method overloading allows multiple methods with the same name but different parameter lists (types or number of arguments).  Use: Improves code readability and reuse. Code Example: Fig: 5.3 It Shows how to we call the overloading method. 2K24/NFIT/35 Miss. Muskan Aijaz 62 | P a g e
  • 63. University of Sindh Campus Naushahro Feroze Output: Fig: 5.4 It Shows the output of calling overloading method. 3.Parameterized vs Non-Parameterized Methods: Non-Parameterized: Input: Fig: 5.5 It Shows the input of non-parameterized method. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 63 | P a g e
  • 64. University of Sindh Campus Naushahro Feroze Fig: 5.6 It Shows the output of non-parameterized method. Parameterized: Input: Fig: 5.7 It Shows the input of parameterized method. Output: Fig: 5.8 It Shows the output of parameterized method. 2K24/NFIT/35 Miss. Muskan Aijaz 64 | P a g e
  • 65. University of Sindh Campus Naushahro Feroze Lab #6 Object-Oriented Programming (OOP) in Java Objective: Objects and classes in Java, their role in object-oriented programming, and how to implement them in real-world applications. . 1. Classes and Objects  Class: A class is a blueprint or template for creating objects. It defines the properties (fields) and behaviors (methods) that an object can have.  Object: An object is an instance of a class. It represents a specific entity with unique values for the properties defined in the class. Code Example: Input: 2K24/NFIT/35 Miss. Muskan Aijaz 65 | P a g e
  • 66. University of Sindh Campus Naushahro Feroze Fig: 6.1 It Shows how to use class and object at a time. Output: 2K24/NFIT/35 Miss. Muskan Aijaz 66 | P a g e
  • 67. University of Sindh Campus Naushahro Feroze Fig: 6.2 It Shows the output of class and object. 2K24/NFIT/35 Miss. Muskan Aijaz 67 | P a g e