Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

sent with the starter code Next, open a terminal window. On the left of each line you should see the current directory you are in.

sent with the starter code image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Next, open a terminal window. On the left of each line you should see the current directory you are in. You can type commands and execute them by hitting Enter. Let's first list the content of the current directory: On Windows, this command is instead of You will see all kinds of file and directory names. That's because you've just listed the files, this time using a command-line interface (CLI). using just your keyboard, rather than the graphical user interface (GUI) you may be used to. In particular. you executed (iie., ran) a command called which is shorthand for "list" (it's such a frequently used command that its authors called it just " to save keystrokes). Make sense? Here on out, to execute (t.e., run) a command means to type it into a terminal window and then hit Enter. Commands are "case-sensitive." so be sure not to type in uppercase when you mean lowercase or vice versa. Let's get the starter code for this lab from the Canvas page and place it in a new directory of your choice, say "COMP122-week-1" in your user's home directory. There should be two files, and called So let's move into the new directory that contains our starter code by typing Let's first list the content of the current directory: On Windows, this command is instead of You will see all kinds of file and directory names. That's because you've just listed the files, this time using a command-line interface (CLI). using just your keyboard, rather than the graphical user interface (GUI) you may be used to. In particular, you executed (i.e., ran) a command called which is shorthand for "list" lit's such a frequently used command that its authors called it just " to save keystrokes). Make sense? Here on out, to execute (i.e., run) a command means to type it into a terminal window and then hit Enter. Commands are "case-sensitive," so be sure not to type in uppercase when you mean lowercase or vice versa. Let's get the starter code for this lab from the Canvas page and place it in a new directory of your choice, 5ay "COMP122-week-1" in your user's home directory. There should be two files. and called So let's move into the new directory that contains our starter code by typing cd cospi22-neek1 If you list the contents of that directory using once more you should only see those two files that you've put into that directory. Compiling Programs Now, before we can execute the program at right, recall that we must compile it with a compiler (e.g., translating it from source code into machine executable binary code. Execute the command below to do just that: jovas Hello.java And then execute this one again: This time, you should also see a file named listed as well That's becabtse has translated the source code in into java bytecode in Bytecode can be interpreted by the Java Virtual Machine (JVM). Now run the program by executing the below. Notice that the parameter is just the name of the class, so not java Hello Hello world, indeed On windows, the command is called dir. This will remove the bytecode file. Alternatively you can also delete that file in your usual graphical user interface. Now compile the code again like this. Javac - d butld Hello, jova On windows this command may complain about the "build" directory not existing, so create it using first. Take care not to overlook any of those spaces therein! Then execute this one again: 15 You should now see a directory listed as well? That's because is a command-line argument, sometimes known as a flag or a switch, that tells where to output its result. In this case we gave it the parameter causing it to create that directory and the bytecode file Let's try to execute our program once more. Java Hello Error: Could not find or load tratn class Hello Caused by: jova, Lang. ClassNotFoundException: Hello What happened? We started the java interpreter and told it to execute a class called "Hello". By default, it will only look for classes in the current folder, so does not find our class. Execute the below to tell it where to look for class files. This uses the "classpath") and passes it the name of the directory containing our byte code. jova - cp build Helto Getting User Input Suffice it to say, our program is boring because it only ever prints Let's personalize it a bit. Modify this program in such a way that it first prompts the user for their name and then prints where "50-and50 is their actual name. To do this we can use the Comp122 class which has been given in the current folder as so. Systen, out.,println("Please enter your name"); String name - Compiz2, getString(): System, out, println("Hello " + name + "1"); As before, be sure to compile your program with: different inputs, with Just FYI, the and execute your program, testing it a few times with class is not the standard way to get user input in Java but a utility we made for COMP122 so that you don't yet have to see all the "scary" details in week 1. We will look into input and output (I/O) later in the semester. Notice that you are using this class although you do not have it's source code file. This is an early example of the information hiding principle: You can use this piece of code without knowing it's internals. This is the end of our first lab. Submit your code to Codegrade now to see how that triggers auto-marking and generates some feedback. public class Hello \{ public static void main(String [] args) \{ 3 System.out.println("hello world!")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

5. Discuss the role of the Web in career management.

Answered: 1 week ago

Question

4. Design a career management system.

Answered: 1 week ago