Friday, August 28, 2009
Thursday, August 27, 2009
Tuesday, August 25, 2009
Below is my screencast for Chapter 2 of the textbook where we cover variables and keyboard and screen I/0. Pay close attention to the different variable types, including
String (note: proper capitalization is important!) You should have read Chapter 2 and watched the screencast below, as well as practiced doing what I do in the video, by Tuesday, September 1.
Also, the slides from the textbook should help you review the material after you have read the book:
Wednesday, August 19, 2009
Below is the video lecture that you must watch before coming to class on Tuesday August 25. Notice that to get the full HD resolution (1280 by 720) you have to watch the video in fullscreen mode, click on the fullscreen icon on the bottom right of the video to go to fullscreen. You should read Chapter 1 of the textbook before watching the video.
As you watch this videos, as well as all future videos I will show, make sure you stop it often and try by yourself to repeat what I did on the video. This is the only way to learn: by doing. No one can learn to program by simply watching a lecture.
If you have trouble installing eclipse or Java on your laptop, or getting the "Hello World" program to run please come to class on Tuesday (with your laptop, if needed) so we can fix it. You can also get from your fellow CSE students by visiting the ACM Student Chapter room in the second floor of Swearingen. They will be posting tutoring hours on their door.
I am also embedding the slides for this chapter below. No, I did not use these slides in my lecture and I do not recommend you read these instead of reading the book. They are only useful as reminders of what you have already read.
Use Netscape/Internet Explorer to get to the lab instructions. It is a good idea to set a bookmark at http://www.csce145.com
- The laboratory computer systems run the Microsoft Windows XP operating system. Because it is connected to a server in the College (running Windows Server), you have a login, password, and a "profile" that can follow you around to whatever computer you use within the engineering domain (ENGR). Computer labs are located in Swearingen and 300 South Main (across the street).
- Login to the computer. Your login name should be the same as you were assigned by USC when you registered. Change your password. If you've never logged in before, your password should be your Student ID. (A good password should be made up of a combination of letters, both uppercase and lowercase, and numbers.)
- Note the desktop (i.e., the appearance of the screen). Everyone’s desktop is identical now, but it’s your desktop. Take an inventory of the things on the desktop. You can change it as you wish at your convenience.
- What you need for CSCE 145 is primarily Internet Explorer, Java, Eclipse, and the textbook software.
- Double click on the My Computer icon to see what you have. In particular, there are several drives: such as C:, H:, P:, and Z:. We will concentrate on drive H:.
- Open the H: drive by double-clicking on it. Create a new folder on H: called csce145; open the csce145 directory by double-clicking on it; now create a lab01 directory.
- You are next going to place an icon on the desktop for eclipse. Locate the eclipse folder by clicking on the Start menu, then Programs, CSE Apps, and eclipse. Click on the eclipse icon using the right mouse button. From the menu that appears, choose "send to" and then "Desktop (shortcut)". This will place a shortcut to the eclipse development environment on your desktop for ease of use.
- Right click the eclipse shortcut that you just made and select properties. Go to Start in and put in the home directory that you made on your H: drive earlier (e.g.:
- Open eclipse by double-clicking on its icon on the desktop. If the "Welcome" window appears, click on the icon for the "Workbench." Eclipse will request that you "Select a workspace." Choose the default, which should be
H:\csce145\workspace. If it is not there, type it in and click OK.
- Use File/New/Project and then choose Java Project and click next. In the window that pops up, choose a project name of lab01 and click next.
- Finally click finish at the bottom.
- For the lab this week, you will write a Java program to do simple interaction with a user (you, in this case).
- Right click on lab01 in the left Package Explorer frame and choose "new class". In the window that pops up, choose a meaningful name for your class (e.g., FirstProgram) and type it in the Name box. In the "which method stubs would you like to create?" section, check the box for
public static void main(String args). Click the Finish button.
- A new class file will be created with the basic code you will need for your assignment. Include the following statement at the beginning of the class so that you can use the Scanner class:
- Then, just below the line with
public static void main(String args)type:
System.out.println("Hello out there."); //two forward slashes means the rest of the line is a comment!!!! //make a String variable with your first name -- change this to your first name String firstName = "Clint"; //make a String variable with your last name -- change this to your last name String lastName = "Fuchs"; //make a char variable that indicates the grade you want to make in this class char grade = 'A'; //note single quotes ' around characters //Finally output all of that information to the screen System.out.println("My first name is " + firstName + " and my last name is " + lastName + " and if I study hard, I will make a(n) " + grade + " in CSCE145!"); //prompt the user to input two numbers to add System.out.println("I will now add two integer values, please enter the two integer values separated by a space: "); //now we need to create and connect a Scanner object to the keyboard Scanner keyboard = new Scanner(System.in); //now we can use the keyboard object to retrieve values from the user int value1 = keyboard.nextInt(); int value2 = keyboard.nextInt(); int result = value1 + value2; System.out.println("The result of adding " + value1 + " and " + value2 + " is: " + result); System.out.println("Goodbye");If you make a typing mistake you can correct it with the backspace or delete key. If you have positioned the cursor somewhere else, then you can use the four arrow keys to get back to the correct line.
- Use the File/Save to save and compile the program. If there is an error while compiling your code it will show up in the tasks window of eclipse workbench with a red cross in the first column, description and line number where it occurs.
- Navigate to Run/Run As/Java Application menu to run your program. Run your program a few times so that you can see it work. Try to understand what each line of code is actually doing.
Congratulations! You've just written and run your first Java program (at least in CSCE 145).