xena@loin ~$> pwd /home/xenaHere the xena@loin ~$> is the Unix "prompt" which shows that you are logged in as "xena" on a machine named "loin". (Your machine name will differ.) The response to the pwd command is /home/xena which is your home directory. pwd is short for "present working directory".
Now make a new subdirectory for all of your work in this course. Call this directory "CS113". (I usually use capital letters to start directory names. This is not required, it is just convenient.) To do so, use the Unix mkdir command as shown
xena@loin ~$> mkdir CS113Suggestion, never put spaces into either directory or file names. They are a pain in Unix and in Java. You can see this is successful by getting a listing of the contents of the current directory using the Unix ls command as follows.
xena@loin:~$ ls CS113 Documents local mpub Music Pictures public_html tmp Desktop Downloads mail mpublic_html Node Public Templates Videosls is short for "list". What you see will be slightly different, but you should certainly see CS113
Now go into the CS113 directory and make a new directory there to hold things you will do today. Then switch into the directory you just made
xena@loin:~$ cd CS113 xena@loin:~/CS113$ mkdir Lab01 xena@loin:~/CS113$ cd Lab01 xena@loin:~/CS113/Lab01$ ls xena@loin:~/CS113/Lab01$ pwd /home/xena/CS113/Lab01 xena@loin:~/CS113$ cd xena@loin:~/CS113/Lab01$ pwd /home/xena/ xena@loin:~/CS113$ cd CS113/Lab01 xena@loin:~/CS113/Lab01$ pwd /home/xena/CS113/Lab01cd is short for "change directory". It is almost always a good idea to use ls after cd to look at the files in the place you just moved to. In this case there are none, which is as expected since you just created the directory.
For each homework and lab, you should do something like the above to create a new clean place for the work you are about to do. That is, create a HW01 directory, a LAB02 directory, etc.
Now lets do something using Visual Studio Code (VSC).
Leave the terminal open, we will return to it
Start VSC. You can do this either from the terminal by entering code or from the dots gird in the lower left (as you did for starting a terminal).
Within VSC, select File Menu / "Open Folder"; then navigate to the Lab01 directory you just created and open that folder. Hint, always select the exact folder you want, not one of its parents.
On the left, click on the extensions button (3 squares together and one slightly apart (usually at the bottom)) and confirm in the list of installed extensions that "Extension Pack for Java" is installed.
On the left, click of the top icon -- a document on top of a document.
Put the mouse over "CS113". Just to the right you should get a set of icons. Click on the leftmost -- a document with a plus in the lower left.
Just below a box should appear with a blinking cursor waiting for you to type. Enter "HelloWorld.java" then hit return
Now on the right, start entering the hello world program given below
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
xena@loin:~/CS113/Lab01$ ls HelloWorld.java xena@loin:~/CS113/Lab01$ javac HelloWorld.java xena@loin:~/CS113/Lab01$ ls HelloWorld.class HelloWorld.java xena@loin:~/CS113/Lab01$ java HelloWorld Hello WorldNote that the program you wrote in VSC shows up in the terminal. The we compile the file using the javac command. If successful, this creates a new file "HelloWorld.class". Finally, we run the program using the java command.
Once your Hello World program works, modify it to print "hello world" at least 5 times.
Command | Description |
---|---|
cd | When used with no arguments (as here), return to the home directory |
cd xxxx | Switch from the current directory to a subdirectory named xxxx. |
cd .. | (This is literally "cd" followed by a space then 2 periods.) Switch from the current directory to the parent of the current directory. |
cd xxx/yyy | switch from the current directory to the subdirectory yyy which is contained in the the directory xxx. xxx must be a subdirectory of the current directory |
ls | LIst the contents of the current directory |
pwd | Show the full path of the current directory |
javac Xxx.java | Compile the java program Xxx.java (Xxx.java must be in the current directory |
javac Xxx | Run the java program Xxx. The file Xxx.class must be in the current directory. Do not include ".class" -- that is "java Xxx.class" will not work. |