LAB 01
LAB 01
Karachi
Objective
By the end of this lecture, students will be able to:
1. Understand the concept and importance of programming languages and their role in
problem-solving.
2. Define and create basic flowcharts and algorithms to represent logical problem-solving
steps.
3. Identify the key features of Java, including Java tokens, data types, and the structure of a
Java program.
4. Demonstrate basic input and output operations in Java using IO streams.
5. Write simple Java programs with a clear understanding of its structure and syntax
Instructions
You are required to complete the lab tasks outlined below and submit your work by the given
deadline. If you encounter any issues during the lab, please raise your hand for assistance. Use
of ChatGPT or any other AI tool is strictly prohibited. If any such usage is detected, marks
will be deducted.
How to Submit
• Submit lab work in a single .txt file on LMS. (No other format will be accepted)
• Lab work file name should be saved with your roll number (e.g. 22542_lab01.txt)
Computer Science, Iqra University, Gulshan Campus,
Karachi
Java is one of the most popular object-oriented programming (OOP) languages. It allows
developers to create a wide range of applications that can run on different types of hardware and
operating systems. Java is also a platform that provides an environment for running these
applications.
Initially, Java was designed to solve small-scale problems, but it quickly proved useful for
handling larger issues, especially over the internet. This led to its rapid rise in popularity, and
soon, millions of programmers worldwide started using it.
● Java Platform, Standard Edition (Java SE) - for building desktop applications.
● Java Platform, Enterprise Edition (Java EE) - for building server-side applications.
● Java Platform, Micro Edition (Java ME) - for building mobile or handheld
applications.
3. Accept terms in the license agreement and then click on next button
4. Then a window will appear that will ask you to set a location for NetBeans.
Computer Science, Iqra University, Gulshan Campus,
Karachi
5. Then select install on the window that appears right after destination selection.
Computer Science, Iqra University, Gulshan Campus,
Karachi
6. After that installation will start
7. Once it's completed a window will be displayed that asks you to select finish
Computer Science, Iqra University, Gulshan Campus,
Karachi
Computer Science, Iqra University, Gulshan Campus,
Karachi
1.4 Algorithm:
An algorithm is a finite set of well-defined, step-by-step instructions used to solve a specific
problem or perform a computation. Algorithms are essential in programming as they define the
logic for solving problems before translating them into code.
1.4.1 Characteristics of a Good Algorithm:
1. Clear and Unambiguous: Each step of the algorithm must be clear and lead to only one
meaning.
2. Well-defined Inputs and Outputs: The algorithm should clearly specify input and
produce output.
3. Finiteness: The algorithm must terminate after a finite number of steps.
4. Feasibility: The steps of the algorithm must be simple enough to be executed.
5. Independence: The algorithm should not depend on any specific programming language.
Algorithm:
1. Start.
2. Take three numbers as input, say A, B, and C.
3. Compare A with B.
o If A > B, go to step 4.
o Otherwise, go to step 5.
4. Compare A with C.
o If A > C, print A is the largest.
o Otherwise, print C is the largest.
5. Compare B with C.
o If B > C, print B is the largest.
o Otherwise, print C is the largest.
6. Stop.
Computer Science, Iqra University, Gulshan Campus,
Karachi
1.5 Flowchart:
1.5.2 Example:
Computer Science, Iqra University, Gulshan Campus,
Karachi
Output:
● Class Names - For all class names the first letter should be in Upper Case. If several
words are used to form a name of the class, each inner word's first letter should be in
Upper Case.
Example: class MyFirstJavaClass
Computer Science, Iqra University, Gulshan Campus,
Karachi
● Method Names - All method names should start with a Lower Case letter. If several
words are used to form the name of the method, then each inner word's first letter should
be in Upper Case.
Example: public void myMethodName().
● public static void main(String args[]) - Java program processing starts from the main()
method which is a mandatory part of every Java program.
Code:
Output:
System.out.println(); or System.out.print();
Code:
Output:
● boolean
● byte
● char
● short
● int
● long
● float
● double
Computer Science, Iqra University, Gulshan Campus,
Karachi
Example Program:
Computer Science, Iqra University, Gulshan Campus,
Karachi
Output:
Lab Task
Computer Science, Iqra University, Gulshan Campus,
Karachi
Question No 1: Write a Java Program to display “Hello World” and your Student ID.
Question No 2: Write a java program to declare two Integers, Doubles and Characters.
Question No 3: Write a Java program to initialize two Integers, Doubles and Characters and
display them.
Question No: 4 Write a Java program that demonstrates the use of the following escape sequences:
\\ (Backslash)
\' (Single quote)
\" (Double quote)
\n (New line)
\t (Tab)
\b (Backspace)
\r (Carriage return)
\f (Form feed)
Question No: 5 Write a Java language program to produce the following output.