0% found this document useful (0 votes)
19 views3 pages

Lab 1 BSCS 13C

This document provides instructions for an introductory lab assignment on basic Java programming. Students will [1] create a simple "Hello World" Java program to print text, [2] purposefully break the code in various ways to learn about compiler errors, and [3] get help from teaching assistants as needed. The goal is for students to get their first experience with compiling and running a Java program and understanding basic syntax requirements.

Uploaded by

tayyabrockstar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Lab 1 BSCS 13C

This document provides instructions for an introductory lab assignment on basic Java programming. Students will [1] create a simple "Hello World" Java program to print text, [2] purposefully break the code in various ways to learn about compiler errors, and [3] get help from teaching assistants as needed. The goal is for students to get their first experience with compiling and running a Java program and understanding basic syntax requirements.

Uploaded by

tayyabrockstar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Computing

CS 212: Object Oriented Programming


Class: BSCS-13C
Lab 1: Basic Programming in Java

Date: 01-02-2024
Time: 2:00pm- 5:00 pm
Instructor: Mr. Jaudat Mamoon
Lab Engineer: Mr. Danyal Sadiq

CS 212: Object Oriented Programming Page 1


Lab 1: Basic Programming in Java
Introduction

After completing this lab students will be able to do some printing task in Java.

Objectives

Your first activity will be creating the "Hello World" program using Java.

Tools/Software Requirement

NetBeans. Eclipse

Description

Basic Lab Instructions!

 Talk to your classmates for help.

 Stuck? Confused? Have a question? Ask a TA/Lab Engineer for help, or look at the book
or past lecture slides.

 Before you leave today, make sure to check in with one of the Lab Engineers/TAs in the
lab to get credit for your work.

Activity #1.

Your first task will be creating the "Hello World" program using java. Create a new directory
CS-212, and navigate into it. Using notepad or the editor of your choice (preferably NetBeans),
create a file called ActivityOne.java and enter the following code:

// This program outputs the message "Hello World"


public class ActivityOne
{
public static void main (String args [])
{
System.out.println ("Hello World");
}
}

CS 212: Object Oriented Programming Page 2


Save the file, and open command window to use for compiling and running your program. In the
new window, navigate into your CS-212 directory and issue the following command to compile
the program, if you are working on a Linux like environment (In case you are using NetBeans,
just Build and Execute the project).

javac ActivityOne.java

If you get any compiler messages, then the learning process has already started! Make sure the
name of the file and the name of the class are identical, that you're in the right place in the
directory structure, and the code is exactly as shown above.

Once the program compiles, enter the command to run it.

java ActivityOne

You will see the output in the console window.

After getting the program to work, let's see what happens if we deliberately break it. We'll try
several variations that violate java syntax to learn what happens. Watch carefully to see what
message the compiler generates for each of these small errors—they are mistakes every
programmer makes on a regular basis.

1) Start by changing the name of the class in the first line, saving the file, and then attempt
to re-compile it with the javac/NetBeans Build command. Observe what happens.
2) Now restore the name in the class header and try removing one of the opening braces,
then save and compile again. Put the brace back and remove the closing brace that
matched it, and save and compile again. Make a note of the messages the compiler
generates for each change.
3) Try a version with a lowercase "s" at the beginning of the output statement instead of the
uppercase "S."
4) Finally, try a version where the only change is the removal of the semicolon at the end of
the print statement. This is a mistake every programmer makes more than once—it's good
to see how the compiler responds.

"Hello World!" for the NetBeans IDE


https://docs.oracle.com/javase/tutorial/getStarted/cupojava/netbeans.html

"Hello World!" for Microsoft Windows


https://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html

CS 212: Object Oriented Programming Page 3

You might also like