OOP Lab 01
OOP Lab 01
OOP Lab 01
Student Name
Reg. No.
Date
• Save the program in any directory with the name UOL(same as the name of class ) and
Extension (.java) for example UOL.java
• Now compile the program that converts the java source code into binary program consisting of
byte codes.
• 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 tempered and is safe to execute and then
execute the actions that the byte codes specify within the java virtual machine.
• If there is no exception in the program the output in printed
Program:
Program:
Variable is a name of memory location. There are three types of variables in java: local,
instance and static.
There are two types of data types in java: primitive and non-primitive.
Variable
Variable is name of reserved area allocated in memory. In other words, it is a name of memory
location. It is a combination of "vary + able" that means its value can be changed.
int data=50; //Here data is variable
Types of Variable
There are three types of variables in java:
Loca variable
instance variable
static variable
1. Local Variable
A variable which is declared inside the method is called local variable.
2. Instance Variable
A variable which is declared inside the class but outside the method, is called
instance variable. It is not declared as static.
3. Static variable
A variable that is declared as static is called static variable. It cannot be local.
Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc.
There are many types of operators in java which are given below:
• Unary Operator,
• Arithmetic Operator,
• shift Operator,
• Relational Operator,
• Bitwise Operator,
• Logical Operator, • Ternary Operator and
• Assignment Operator.
Type Casting
Assigning a value of one type to a variable of another type is known as Type Casting.
Example:
When you are assigning a larger type of value to a variable of smaller type, then you need to perform
explicit type casting.
Tasks:
1: Give your name and registration number as input and generate the output in interaction pane.
2: Test the results 36%10 and 36%40, 36/40 & 36/10, 6.0/4 & 6/4? What is the cube of 36?
3: Calculate the average, sum & difference of 876 & 767.First stores these values in proper
type, then calculate the result.
4: Calculate the circumference and area of the circle of radius 0.5 km. Circumference=2*pi *r.
Area= * r 2
5: Write a program to assign three values to three integer type variables a, b and c. Add
variables a and b and multiply their sum to variable c. Use compound assignment statement.
Task 1
Task 2
Task 3
Task 4
Task 5
Task 6
Average
Marks