Programming for Engineers- lab 1
Programming for Engineers
Lab (1) – Java start up
This lab sheet guides you through writing simple Java programs using the NetBeans
IDE, introducing fundamental concepts.
Before you begin:
Install and configure Java Development Kit (JDK)
from https://www.oracle.com/java/technologies/downloads/.
Download and install NetBeans IDE
from https://netbeans.apache.org/downloads/.
Exercise 1: Hello, World! in NetBeans
1. Open NetBeans and create a new project:
o Select "Java" -> "Java Application"
o Name your project "HelloWorld" and choose a location.
o Click "Finish".
2. In the "Projects" tab, right-click your project and select "New" -> "Java Class".
o Name the class "HelloWorld" and click "Finish".
3. The generated class file opens in the editor. Replace the existing code with:
4. Run the program:
o Click the "Run" button (green triangle) on the toolbar.
o Alternatively, right-click on the "HelloWorld" class and select "Run File".
5. You should see the output "Hello, World!" in the "Output" window.
Page 1 of 2
Programming for Engineers- lab 1
Congratulations! You've created your first Java program in NetBeans!
Exercise 2: Printing Multiple lines
1. In the "Projects" tab, right-click your project and select "New" -> "Java Class".
o Name the class " SimpleJavaProgram " and click "Finish".
public class SimpleJavaProgram
{
public static void main(String[] args)
{
System.out.println("My first Java program.");
System.out.println("The sum of 2 and 3 = " + 5);
System.out.println("7 + 8 = " + (7 + 8));
}
}
2. Run the program:
o Click the "Run" button (green triangle) on the toolbar.
o Alternatively, right-click on the "HelloWorld" class and select "Run File".
Screenshot the screen and save in a Word
document. Send them to the given Email.
Page 2 of 2