Object Oriented Programming
Object Oriented Programming
BCE-03
LAB JOURNAL-01
Objectives:
The main objective of this lab is to practice the basic programming concepts learnt so far e.g.
variables, their types how they assigned, passing command line arguments etc in JAVA. Use naming
conventions.
Software used:
• Net Beans.
Description:
In Java, every application begins with a class name, and that class must match the filename. Every
line of code that runs in Java must be inside a class. A class should always start with an uppercase
first letter. Java is case-sensitive: "My Class" and "my class" has different meaning.
Example
System.out.println("Hello World”);
}}
Assuming your program contains no errors, the compiler generates a byte code program that is
equivalent of your source code. The compiler stores the byte code program in a file with the same
name as source file, but with the extension .class. Java executable modules are always stored in a
file with the extension .class. When you execute a java program, a program called the Java interpreter
inspects the byte code for it, checks it out to ensure that it has not been tampered and is safe to
execute and then execute the actions that the byte codes specify within the java virtual machine.
• static means that the method belongs to the Main class and not an object of the Main class.
Java Variables:
• Declaring variables in JAVA requires data type followed by variable name. You can assign
constant literal or a variable to the declared variable
Example:
• If you don't want others (or yourself) to overwrite existing values, use the final keyword (this
will declare the variable as "final" or "constant", which means unchangeable and read-only):
final int myNum = 15;
Lab Tasks:
Task1:
Write an application that displays the shapes shown in the sample output using asterisks.
Code:
Output:
Task 2:
Write an application that reads three integers (inputs) from the user and compute the product of
them.
Code:
Output:
Task 3:
Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent
numbers separated by one space. Use the following techniques:
a) Use one System.out.println statement.
b) Use four System.out.print statements.
c) Use one System.out.printf statement.
Code:
Output:
Task 4:
Write an application that asks the user to enter two integers, obtains them from the user and
displays the larger number followed by the words "is larger". If the numbers are equal, print the
message "These numbers are equal".
Code:
Output:
Conclusion:
In this lab, we studied about java which is mostly same as c++, we performs all the task
successfully and really enjoy to perform them.