Sie sind auf Seite 1von 6

Lab Work 1 : Welcome To Java, The fascinating world of

Programming.

Objective: Writing, compiling, and executing your first java program.

Task 1.

1. In a Window® operating system, open the Notepad, a text writer.


a. Use the following sequence to open notepad.
Clicks on
Window START button  Run
b. Type in Notepad and press enter

2. Write the following code into the opened Notepad.

public class MyFirstJavaProgram {


public static void main(String[] args){
System.out.println(“Hi, Welcome to Java”);
}
}

3. Save your work.


a. In the notepad, clicks on
File->Save as
b. Dialog Box appears
Lab Work 1 : Welcome To Java, The fascinating world of
Programming.

c. After satisfy, clicks on Save Button


4. Compile your java program
a. Open the command prompt window by clicks on
Windows Start Button  Run
b. Type in cmd and press enter
c. The Command Prompt Windows appears as shown.

d. Using the command cd, change the command prompt current


folder to your working folder (the folder where you save your java
file above). For Example, I’m store the java program into the
JavaProgram folder and JavaProgram folder is in the My
Documents folder. Therefore, from current folders , the cd
command is as shown in the figure below

e. To compile your MyFirstJavaProgram.java program, type in javac


MyFirstJavaProgram.java (general use : javac
<javaprogramname.java>) in the command prompt and press
enter.
5. Executes your program
a. If you type the codes correctly, you will get no error message, and
then you can execute your first java program. To execute the
program, type in java MyFirstJavaProgram (general use : java
<javaprogramname>) and press enter.
b. Both step 4e and 5a and the results of the program execution is
shown in the following figure.

What the program did is displaying the message


Lab Work 1 : Welcome To Java, The fascinating world of
Programming.

Hi!! Welcome to Java onto screen.

Questions for Task 1.

a. What is the file name of the above program?

b. What is the name of the above java class?

c. In your opinion, what is the relationship of both java class name and java file
name above?

d. Print the command prompt window by pressing button ctrl + print screen
simultaneously, and attach here
Lab Work 1 : Welcome To Java, The fascinating world of
Programming.

Task 2.

By using the step in task 1, write, compile and execute the following java
program and answer the question given.

import javax.swing.JOptionPane;
public class HelloGraphic {
public static void main(String[] args){
JOptionPane.showMessageDialog(null,"Hi!! Hello World");
}
}

a. What is the name of the above java class?

b. What is the file name should be given to the above java program?

c. In your opinion, what will happen if the filename and the class name are
not identical?

d. Attach here the result/windows when executing the above java program
Lab Work 1 : Welcome To Java, The fascinating world of
Programming.

Task 3.

By referring to Task 1, write a java program that display the message

Hello World!!!

onto screen.

Attach your program here:

Task 4.

By referring to Task 2, write a java program that displays the following window
message onto screen.

Attach your program here:


Lab Work 1 : Welcome To Java, The fascinating world of
Programming.

Das könnte Ihnen auch gefallen