Starting from:
$35

$29

Lab 1: Java from CLI Solution


In this lab, you will prac ce compiling and execu ng Java programs from the command line interface (CLI), also known as the terminal or command prompt. It is important that you test your assignment submissions from the CLI, as this will be the environment that will be used to grade your submissions.

In some assignments, you may also be required to organize your code in packages. This is a standard way of organizing large collec ons of code that comprise different components of different projects. Packages also allow you more fine-grained control over access of member variables and methods in your classes, as we discussed in lecture. This technique of modulariza on is very important for large-scale programming projects, and is ubiquitous in both industry and open source development.

Your TA will give a brief lesson on CLI compila on and execu on, as well as package directory organiza on.


Java CLI




    • er the TA’s lesson, complete the following steps:

        1. Download the lab code from the course website:

Lab1Pt1.java demonstrates basic CLI input and output.


Lab1Pt2.java demonstrates command line arguments.


Lab1Pt3.java demonstrates a class in a package.


    2. To ensure you are able to compile and run Java programs from the CLI, compile and run Lab1Pt1 . Ensure that your input is accepted and the output reflects your input.

    3. To ensure you understand command line arguments, compile and run Lab1Pt2 . Try running it with different numbers of command line arguments. Try wrapping mul ple
words in quotes, and note the difference in the output of the program.

    4. To ensure you understand Java packages, first create the package directory hierarchy for Lab1Pt3 , based on the package line at the top of the file. Then, compile and run the

program.



Conclusion




More importantly than just following these steps, the goal of these exercises is to prepare you for your assignments. If you have trouble comple ng these steps, or you do not understand them, ask your TA or come to office hours! Understanding these concepts will be crucial to success in your assignments!

More products