CS-151 Labs > Lab 0. Setup


Part 2. Your First Java program

In this part of the lab, you will add a brand-new class to your lab0 project.

Adding a new class

Add a new file to your project by selecting (default package), then right-click and New class. Name the class HelloAll. You can also ask Eclipse to generate the main method stub for you.

New Java Class

Coding!

You can use the code in Hello2.java to create a new Java program in HelloAll.java. Your program should print a personal greeting for every name passed as a command-line prameter, no matter how many names are passed.

Here is a sample program run:

java HelloAll Alice Bob "Bill Gates" "Joan Doe"
Hello, Alice!
Hello, Bob!
Hello, Bill Gates!
Hello, Joan Doe!

Welcome to CS-151!

Inside the main, implement this program.

Test that the program works as expected by passing different number of program arguments: no arguments, one argument, four arguments. This can be done from Eclipse by changing the Run Configuration, as explained in Part 1.

Tabs and spaces

Eclipse is a powerful IDE with many useful features. You will explore and use many of them in these labs.

Tabs

For now we want the code created in Eclipse to have a consistent indentation across multiple text editors. For this we are going to update the tab behavior. Go to Window->Preferences->Java->Code Style->Formatter. Create a new formatter profile, and update the Tab policy to Spaces only. This will ensure that when you press Tab in Eclipse, exactly four spaces are added to the source code instead of a special tab character. This will help to display the code indentation properly in any editor and on any operating system.

Readme

Add a new file to your project caller readme.txt. Each lab submission should have a readme file inside it. In this file, please describe what was difficult and what was (too) easy in this lab.

In addition, if you attended the lab session for the week, please list the name of your partner, and describe the part of the warmup you and your partner found most challenging. You must do this to get the credit for the warmup.

At the end of the file type:

I have adhered to the Honor Code in this assignment.

Save all your changes and go to the submission.