![]() ![]() Recognize and correct syntax errors in a Java program. Use an IDE (Integrated Development Environment).Įdit, save, compile, and run a simple Java program. This program takes a single command-line argument specifying the name of the person who should be welcomed:Īcknowledgements This lab is based on a lab designed by Nathan Sprague. Fix the errors and try out the resulting program.Read the error messages carefully. The text of the error messages can be confusing, but they often contain useful information if you take the time to read them.In many cases the later errors aren't really errors at all they occur because the compiler was confused by an earlier error. Address errors in the order they appear. Fix the first error, then re-compile.Compiler-generated error messages often seem overwhelming and difficult to understand.Personal.java:7: error: illegal start of expression Personal.java:6: error: unclosed string literal You should see several error messages printed to the terminal:.Copy the file /cs/shr/cs149/code/Personal.java into your lab02 directory.You will submit this file at the end of the day in Canvas. Recompile then Execute your modified Java program:.You need to use javac to re-compile Welcome.java. Changing Welcome.java doesn't automatically change Welcome.class. Save your changes and exit.ĭoes the output reflect your changes? Why not?Įditing and compiling are separate steps. Edit the file so that the welcome message says "It's REALLY fun." instead of "It's fun.".For example, pressing Ctrl-O will "WriteOut" (save) any changes you have made to the file. The two lines of text at the bottom show the set of actions available in the editor. You should see something like the following: Today we'll try nano because it is easy to use for beginners. However, it can sometimes be convenient to edit a file directly in the terminal. Normally, we will be using an Integrated Development Environment (IDE) to edit and compile Java programs. Congratulations! You've successfully compiled and executed your first Java program.Now that Welcome.java has been compiled, it can be executed:. ![]() class files are not intended to be read or edited by humans. These are "machine language" instructions written in the language of the Java Virtual Machine. The file Welcome.class contains Java byte code. Examine the contents of Welcome.class using the cat command.ĭon't worry! The contents shouldn't make sense to you.If all goes well, this command should not produce any output to the terminal window, but it should create a new file named Welcome.class.Examine the contents of Welcome.java using the cat command.Confirm that you completed the last two steps correctly by using the pwd command (to confirm that you are in the lab02 directory) and the ls command (to confirm that you successfully copied Welcome.java). ![]()
0 Comments
Leave a Reply. |