KEMBAR78
Practical 01-It1214 | PDF | Class (Computer Programming) | Parameter (Computer Programming)
0% found this document useful (0 votes)
31 views7 pages

Practical 01-It1214

The document outlines four practical sessions on Java programming, covering basic concepts such as program structure, classes, methods, loops, and command-line arguments. Each practical includes objectives, theoretical concepts, algorithms, source code links, expected outputs, observations, and conclusions. The sessions emphasize hands-on learning through coding exercises and understanding Java's syntax and functionality.

Uploaded by

jestudio22
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)
31 views7 pages

Practical 01-It1214

The document outlines four practical sessions on Java programming, covering basic concepts such as program structure, classes, methods, loops, and command-line arguments. Each practical includes objectives, theoretical concepts, algorithms, source code links, expected outputs, observations, and conclusions. The sessions emphasize hands-on learning through coding exercises and understanding Java's syntax and functionality.

Uploaded by

jestudio22
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
You are on page 1/ 7

Practical 01 - Introduction to Java Programming (14.03.2025 10.30 - 12.

30)

1. Objectives

 To understand the basic structure of a Java program.


 To learn how to use the System.out.print() and System.out.println() functions for
console output.

2. Theory / Concept

This practical introduces:

1. Classes and Methods


2. Printing the java code in terminal
3. Importing packages into the java code

3. Algorithm / Flowchart

Algorithm

1. Starting the java program which we created.


2. Importing necessary packages to the java program.
3. Define a class (MyClass).
4. Inside the class, define the main method.
5. Print multiple lines of text using System.out.print() and System.out.println().
6. Ending and closing the program.

Flowchart

 Start → Importing the Packages → Defining Class → Define main Method → Print
Output → End

4. Source Code

Source code for the Github: https://github.com/JThiagarajah/IT1214.git

5. Sample Input & Expected Output

Expected Output:

HiThis is IT1214 Practical Session 1

This prints in a new line


6. Observations

 The program executed successfully without any errors.


 Since System.out.print() does not add a new line, the first two statements print text in
a single line.
 The System.out.println() statement moves the cursor to the next line after printing.

7. Conclusion

 Learned the basic structure of a Java program.


 Understood the difference between System.out.print() and System.out.println().

Practical 02 - Introduction to Java Programming (14.03.2025 10.30 - 12.30)

1. Objectives

To understand the basic syntax and structure of a Java program, including class declaration,
the main method, command-line arguments, and printing output.

2. Theory / Concept

 Java Programming Basics


 Class Declaration
 Main Method
 Command-Line Arguments
 Printing Output

3. Algorithm / Flowchart

Algorithm:

1. Start the program


2. Import the necessary package (java.io.*).
3. Define a class named FirstClass.
4. Inside the class, create the main method.
5. Print using System.out.println().
6. End.
4. Source Code:
Source code: https://github.com/JThiagarajah/IT1214.git

5. Sample Input & Expected Output

Expected Output:

The first argument is Hello


The second argument is World

6. Observations

 The program successfully prints the first and second command-line arguments.
 If fewer than two arguments are provided,
an ArrayIndexOutOfBoundsException occurs.
 The issue can be resolved by checking the length of ar before accessing elements.

7. Conclusion

This practical helped me understanding:

 Java syntax and structure.


 How to define a class and the main method.
 The concept of command-line arguments.
 Handling runtime errors using input validation techniques.

Practical 03 - Introduction to Java Programming (14.03.2025 10.30 - 12.30)

1. Objectives
 To understand variable declaration, initialization, and the use of methods in Java.
 To explore the concept of classes and objects, and their interaction through method
invocation.

2. Theory / Concept:

Variable Declaration and Initialization:


In Java, variables need to be declared with a specific data type before being used. A variable can
also be initialized with a value.

Methods

Methods are designed to perform a specific task. They are defined within classes and can be
call on objects of that class.

Classes and Objects

• Class: A blueprint or template for creating objects, defining properties and behaviors.

• Object: An instance of a class with actual values, created based on the class blueprint.

3. Algorithm / Flowchart

Algorithm:

1. Declare a class `One` with instance variables `a` and `b` and a method `print_details()` to print
their values.

2. Declare a class `Two` with instance variables `a` and `c` and a method `print_details()` to
print their values.

3. In the `main()` method, create instances of `One` and `Two`.

4. Call the `print_details()` method for both objects to display their variable values.

5. Source Code:
The source code for the github: https://github.com/JThiagarajah/IT1214.git

6.. Sample Input & Expected Output:

In this case we don’t need ay input from the user.

Expected Output:

a = 10

b=0

From class Two a = 0

From class Two c = 0


6. Observations:

There were no syntax errors during the compilation and execution of the program. According to
the coding we were able to the expected output as shown above.

 Class `One` initializes `a` to 10 but `b` remains uninitialized, which defaults to 0.
 Class `Two` has `a` and `c` uninitialized, so they also default to 0.

7. Conclusion:

- This practical helped in understanding the basics of Java class structure, variable declaration,
and method usage.

- Key takeaways: Java automatically initializes uninitialized variables to default values (0 for
integers). We also learned how to define and call methods within classes.

Practical 04 – Printing a Rectangle with stars (04.04.2025 10:30 - 12:30)

1. Objectives

 To learn how to use loops to print patterns in Java.


 To understand the concept of methods and how to pass parameters.

2. Theory / Concept

 Loops: The program uses two nested for loops. The outer loop controls the number of
rows (height), and the inner loop controls the number of columns (width).
 Methods: A method named print is used to print the rectangle, and it takes two
parameters, width and height.
 System.out.print(): Used to print without a line break.
 System.out.println(): Used to print a new line after each row of asterisks.

3. Algorithm / Flowchart

Algorithm:

1. Define a method print that takes two parameters: width and height.
2. Start an outer loop to iterate through rows (height).
3. Inside the outer loop, start an inner loop to print the asterisks for each column (width).
4. Print an asterisk without moving to the next line after each column.
5. After printing all columns in a row, move to the next line.
6. End both loops.

Flowchart:

 You can visualize it with two nested loops where the outer loop runs for height, and the
inner loop prints * for width in each row.

4. Source Code

The source code link:

5. Sample Input & Expected Output

Input:

 Width: 3
 Height: 4

Expected Output:

***
***
***
***

Test Case 2: Input:

 Width: 5
 Height: 2

Expected Output:

*****
*****

6. Observations

 There were no errors during the program execution.


 Changing the input values for width and height prints a rectangle of the desired size.
 If the width or height is set to zero, no output is printed.

7. Conclusion

 In this practical, I learned how to use loops to print simple patterns and how to structure
the program using methods and parameters.

You might also like