You are on page 1of 16

Lab 04

Create Your own package

1 – Add statement “package APC.lab1;” as first line of your code

2 – Compile with javac –d. yourProgram.java

3 – This will create your yourProgram.class file in the <workingDir>\ APC\lab1


4 – Make a class to call yourProgram from step3
5 – create a jar file by following command
jar cf myapi.jar. C:\home\html\jdk-13.0.2\bin\APC\lab1\HelloPrg.class

// bold text is the path where your class file exists; gives that path in above command
6 – Add this jar file in the lib folder of classpath and change the class path
(CLASSPATH= C:\Program Files \ Java \ jdk1.5.0 \ lib \ myapi . jar; ;)
7 –Your API is added in the classpath and now you are able to make your program calling your own api
from the lib folder.
Java Application

1 – Write a simple Application to show a message “Hello world”


2 – Write an application using swing package to accept two integers from the user and display a result of

addition of input integers.


3 – Try a program with
o System.exit(0);
o System.exit(1);

Explain the differences in the two tried exercises.


System.exit(0);
normal termination - Successful – zero. Generally used to indicate successful termination.

System.exit(1);
Any nonzero value indicates unsuccessful termination.
For Compilation:
1- Goto your working directory.
2- Compile your application by command javac filename.java
3- Execute your application by command java filename

Java Applet

1 – Write a simple applet displaying “Hello world” with import java.applet.Applet;


2 – Write a simple applet displaying “Hello world” with import java.swing.JApplet;
Note (for 1 & 2):
Run the both applets with appletviewer and Internet browsers.
3 – Write an applet to show the addition of two integers entered by user.
Web Resources:
http://www.skylit.com/javamethods/faqs/createjar.html

https://docs.oracle.com/javase/tutorial/deployment/jar/build.html

https://www.thoughtco.com/building-your-first-java-applet-2034332

You might also like