Lab Manual - 1: CLO No. Learning Outcomes Assessment Item BT Level PLO
Lab Manual - 1: CLO No. Learning Outcomes Assessment Item BT Level PLO
Lab Manual - 1: CLO No. Learning Outcomes Assessment Item BT Level PLO
Lab Manual - 1
OOP
3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse
Libraries: also known as Application Programming Interface (API), these files are previously
written classes and methods that contain some common functionality.
Compiler: the program that translates files written in Java language (human language) into
binary files (machine language) in order to execute them.
Interpreter: Some programming languages do not compile the source code file into directly
executable form (native code), but they instead compile it into partially compiled file that could
be executed by a program called interpreter.
Java programming language is an interpreted programming language, that is, when the source
code is compiled into binary file, it needs an interpreter called Java Virtual Machine (JVM) to
run it. Java compiler is called javac.exe, and interpreter is called java.exe.
1. JDK INSTALLATION:
• Following window will appear on your screen. Check the accept license option and
click on the highlighted version to download jdk.
• After downloading double click the jdk icon to start installation process.
INSTALLATION STEPS:
Under “System variables” click the “New…” button and enter JAVA_HOME as “Variable
name” and the path to your Java JDK directory under “Variable value”.
this will print out the directory JAVA_HOME points to or empty line if the environment
variable is not set correctly
this will print out the version of the java compiler if the Path variable is set correctly
or “javac is not recognized as an internal or external command…” otherwise
The following are some important changes in and information about this release.
• The deployment stack, required for Applets and Web Start Applications, was deprecated in
JDK 9 and has been removed in JDK 11.
• In Windows and macOS, installing the JDK in previous releases optionally installed a JRE. In
JDK 13, this is no longer an option.
• JavaFX is no longer included in the JDK. It is now available as a separate download from
openjfx.io. JavaFX is a Java library used to build Rich Internet Applications. The applications
written using this library can run consistently across multiple platforms. The applications
developed using JavaFX can run on various devices such as Desktop Computers, Mobile
Phones, TVs, Tablets, etc.
• Previous releases were translated into English, Japanese, and Simplified Chinese as well as
French, German, Italian, Korean, Portuguese (Brazilian), Spanish, and Swedish. However, in
JDK 11 and later, French, German, Italian, Korean, Portuguese (Brazilian), Spanish, and
Swedish translations are no longer provided.
• Updated packaging format for Windows has changed from tar.gz to .zip, which is more
common in Windows OSs.
New Features:
▪ JEP 351: ZGC: Uncommit Unused Memory
▪ JEP 353: Reimplement the Legacy Socket API
▪ JEP 354: Switch Expressions (Preview Feature)
▪ JEP 355: Text Blocks (Preview Feature)
class Uet
{
public static void main(String abc[])
{
System.out.println("My first Java Program");
}
}
• Save the program in C:\program Files\java\jdk13\bin with the name Uet (same as the
name of class) and Extension (.java) i.e.; Uet.java.
This is done to change the directory to the drive where bin of java is installed.
The command javac converts the java source code into byte code program.
• 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.
• To execute the byte code program in the .class file with the java interpreter in the JDK,
you enter the command
• If there is no exception in the program the output is printed on the command prompt.
File->New->JAVA Project.
Create new Class and type the above code. Click on run icon. Eclipse will show output on
console.
LAB TASKS
Task 1: Marks: 4
Run the following codes on CMD and in Eclipse and observer the outputs.
Run the following programs. Observe the output. Focus on comments to enhance the
understandability.
Program # 1
class Program1{
//your program begins with a call to main().
System.out.println(" Welcome to java world ! "); //println() displays the string which is passed
to it.
Program # 2
class Program2 {
public static void main(String args[]) {
int a,b,c; //this statement declares three variables a, b and c.
a=2;
b=3;
c=a+b;
System.out.println("Sum of two numbers = "+c); }
}
Task 2: Marks: 6
Run the following code by saving it firstly with name abc.java and then with bcd.java
and check the output.
class abc
{
public static void main(String args[])
{
System.out.println("hello world!");
}
}
class bcd
{
public static void main(String args[])
{
System.out.println("This is my First Program!");
}
}
******************