0% found this document useful (0 votes)
11 views7 pages

Object Oriented Programming

oops in java

Uploaded by

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

Object Oriented Programming

oops in java

Uploaded by

bahuni604
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

OBJECT ORIENTED PROGRAMMING

BCE-03
LAB JOURNAL-01

SUBMITTED TO: SIR MUBASHIR


SUBMITTED BY: HASSAN BUKHARI
ENROLLMENT NO: 01-132232-017

DEPARTMENT OF COMPUTER ENGINEERING


BAHRIA UNIVERSITY ISLAMABAD CAMPUS
Lab 1
Introduction to Java

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:

Adding Class to Project:

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

public class HelloWorld

public static void main(String [] args)

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.

• System.out.print() command in java is same as cout in C++

• System.out.println() command: System is a built-in Java class that contains useful


members, such as out, which is short for "output". The println() method, short for "print line",
is used to print a value to the screen (or a file). Note that it will add a new line for each method

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:

int myNum=5; float


myFloat=5.99f; char
myLetter=’D’; Boolean
myBool=true;
String myText=”Hello”;

• 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.

You might also like