Lab Manual - 1: CLO No. Learning Outcomes Assessment Item BT Level PLO

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

UET TAXILA

CLO Learning Outcomes Assessment Item BT Level PLO


No.

1 Construct the experiments / projects of Lab Task, Mid Exam, Final


varying complexities. Exam, Quiz, Assignment, P2 3
Semester Project

2 Use modern tool and languages. Lab Task, Semester Project P2 5

3 Demonstrate an original solution of Lab Assignment, Lab Task,


A2 8
problem under discussion. Semester Project

4 Work individually as well as in teams Lab Task, Semester Project A2 9

Lab Manual - 1
OOP
3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

Laboratory 01: Introduction to Running Simple Programs in Java


Lab Objectives: After this lab, the students should be able to

1. Install JDK -13.0.2


2. Run simple Java Programs on Command Prompt and in Eclipse

Software Development Kit (SDK) that contains the following:

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:

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.

The Figure below shows a complete path of running Java programs.

1. JDK INSTALLATION:

For compiling and running java programs we need to install JDK.

A JDK distribution consists of a JRE distribution (a Java Virtual Machine implementation)


plus a collection of development tools including javac :a Java compiler, and javadoc: Java
documentation generator.

DOWNLOADING JDK 13:

Follow the steps for downloading jdk from net.

Engr. Sidra Shafi Lab-01 1


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

• Go to this link and download JDK 13.0.2


• https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-
5672538.html

• Click on the Java Download icon.

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

• Click NEXT to move ahead.


• Select directory where you want to install this software.
• Then click next.
• Click OK.

• Now you can create, compile and run java programs.

Note: For Lab, JDK 13 is given.

Setting Environment Variable:


1. Open Advanced System Settings
In Windows 10 press Windows key + Pause Key, This will open the System Settings
window. Go to Change settings and select the Advanced tab.

2. Set JAVA_HOME Environment variable


In “System Properties window” click “Environment Variables…

Engr. Sidra Shafi Lab-01 2


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

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

Add JAVA_HOME as system variable

Engr. Sidra Shafi Lab-01 3


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

3. Update System PATH


1. In “Environment Variables” window under “System variables” select Path
2. Click on “Edit…”
3. In “Edit environment variable” window click “New”
4. Type in %JAVA_HOME%\bin

Engr. Sidra Shafi Lab-01 4


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

4.Test your configuration


Open a new command prompt and type in:

this will print out the directory JAVA_HOME points to or empty line if the environment
variable is not set correctly

Now type in:

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

For other Operating Systems use the following link.


https://www.java.com/en/download/help/path.xml

Important Changes and Information

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)

Engr. Sidra Shafi Lab-01 5


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

2. CREATING A SIMPLE JAVA PROGRAM:

• Open up an editor (notepad) and write the following code.

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.

• In order to compile and run the program do the following


Start -> Run ->(type) cmd ->(press Ok).

• Then in command prompt write the following.

This is done to change the directory to the drive where bin of java is installed.

cd is a command used for changing directory.

• Now compile the program on command prompt as:

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

Engr. Sidra Shafi Lab-01 6


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

• If there is no exception in the program the output is printed on the command prompt.

Running Java Programs in Eclipse.


Install Eclipse. -> double click on Eclipse installer

Select 2nd Option.

Engr. Sidra Shafi Lab-01 7


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

Engr. Sidra Shafi Lab-01 8


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

The installation will start now.

You can change workspace later.

Engr. Sidra Shafi Lab-01 9


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

File->New->JAVA Project.

Create new Class and type the above code. Click on run icon. Eclipse will show output on
console.

Engr. Sidra Shafi Lab-01 10


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

Engr. Sidra Shafi Lab-01 11


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

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().

public static void main (String args[] )

System.out.println(" Welcome to java world ! "); //println() displays the string which is passed
to it.

Engr. Sidra Shafi Lab-01 12


3rdSemester Lab-01: Running Java Programs on CMD and in Eclipse

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!");
}
}
******************

Engr. Sidra Shafi Lab-01 13

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy