OOP LabManual 1(Week 1)
OOP LabManual 1(Week 1)
Roll No
Name
Class
Lab Instructor
JAVA INTRODUCTION
Lab-01
Features of Java
• Object Oriented − In Java, everything is an Object. Java can be easily extended since
it is based on the Object model.
• Platform Independent − Unlike many other programming languages including C
and C++, when Java is compiled, it is not compiled into platform specific machine,
rather into platform independent byte code. This byte code is distributed over the web
and interpreted by the Java Virtual Machine (JVM) on whichever platform it is being
run on.
The Java Runtime Environment (JRE) is required to run Java applications but does not
include development tools. It consists of the Java Virtual Machine (JVM) and essential
libraries that Java programs need to function. The JRE is mainly for users who only want to
run Java applications without writing or compiling code.
The JVM (Java Virtual Machine) is a virtual machine, an abstract computer that has its
own ISA, memory, stack, heap, etc. It runs on the host OS and places its demands for
resources on it.The Java Virtual Machine (JVM) is the core component that executes Java
programs. It takes Java bytecode (compiled Java code) and converts it into machine code that
the computer understands. JVM is the core engine that enables Java's "Write Once, Run
Anywhere" feature The JVM is what makes Java platform-independent, allowing the same
Java program to run on different operating systems like Windows, macOS, and Linux. Every
Java application runs inside a JVM, ensuring security, memory management, and efficient
execution.
Basic Syntax:
Java is an object-oriented programming language which is known for its
simplicity, portability, and robustness. The syntax of Java programming
language is very closely aligned with C and C++ which makes it easier to
understand.
About Java programs, it is very important to keep in mind the following points.
• Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would
have different meaning in Java.
• Source File Name − Name of the source file should exactly match the class name.
When saving the file, you should save it using the class name (Remember Java is case
sensitive) and append '.java' to the end of the name (if the file name and the class name
do not match, your program will not compile).
But please make a note that in case you do not have a public class present in the file then
file name can be different than class name. It is also not mandatory to have a public
class in the file.
Example − Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved
as 'MyFirstJavaProgram.java'
• public static void main(String args[]) − Java program processing starts from the
main() method which is a mandatory part of every Java program.
• Comments in Java
// System.out.println("This is an comment.");
/*
System.out.println("This is the first line comment.");
System.out.println("This is the second line comment.");
*/
• To actually run the program, you must use the Java application launcher called java.
To do so, pass the class name Example as a command-line argument. Now, type java
Example to run your program.
• You will be able to see This is a simple Java program printed on the window.
Task 3: Write a Java program to print 'Hello' on screen and then print
your name on a separate line.(paste screenshot of code & output)
Task 4: Write a Java program to print the sum of two numbers. .(paste
screenshot of code & output)
Task 5: Write a Java program to display the following pattern. .(paste
screenshot of code & output)
Sample Pattern :
J a v v a
J aa v v aa
J J aaaaa V V aaaaa
J J a a V a a
QUESTIONS
Question 1:
What is byte code and which command is responsible for its creation?
Question 2:
Which command is responsible for the compilation of the java code?
Question 3:
What will be the name and the type of the file which will be created if the
following command is executed javac MyClass.java?
Question 4:
What is the difference between print() and println() functions?
Question 5:
Difference between JDK, JRE, and JVM
The End..