Road Map: Elements of The Java Platform
Road Map: Elements of The Java Platform
Road Map
Instructor: Jonathan Doughty E-mail: [email protected] Times: Monday Evenings: 7:20 - 10:00 PM Place: Classes will be held in S&T I, Room 124 Each week lecture materials will be found at: http://cs.gmu.edu/~jdoughty/cs161/ Topics this week: Course Description Grading Policy Honor Policy Expectations for This Class Textbook Syllabus Programming Assignment Road Map Program Development Environment IDEs Programming Some Keys to Java Programming What Does Java Look Like? Running a Java application A Better First Java program Do it! What the MyName Class demonstrates Assignment for Next Session
Class sessions will not be primarily hands-on lab oriented. This class will not teach
JavaScript How to create graphical interfaces, Any advanced Java topics
Grading Policy
Programming assignments - 70%
4 programming assignments Due the following Monday after the assignment is given Ill accept late submittals up to one week after their inital due date; however, all late submittals will be reduced one full letter grade. Ill accept good faith attempts on time and Ill revise those grades upwards (not to maximum credit however) with results from late submittals.
Final exam
Will be completed by the individual. Will be taken without study aids.
Textbook
Java: An Introduction to Computer Science & Programming
Walter Savitch, Prentice Hall, 1998
Getting Started
A series of lessons on getting started in Java programming; assumes a little programming background. http://developer.java.sun.com/developer/onlineTraining/Programming/
Thinking in Java
Bruce Eckels excellent book on Java programming. Printed - Prentice-Hall 1998 Softcopy You can download the entire contents in either PDF (3.6MB) or zipped HTML (1.1MB) formats from http://www.bruceeckel.com/javabook.html
Syllabus
The topics I expect to cover in this class are:
Assignment 2
Goal: Write a simple Java program from scratch; Learn how to write a Java class with fields and methods. Purpose: To start thinking in terms of breaking a problem into smaller pieces. To start getting the computer to calculate answers. To start learning to be exact when giving the computer instructions.
Assignment 3
Goal: Write a second Java class and use the two classes written so far, this weeks uses lasts. Purpose: Learn about instances of classes and calling methods on them. To start building solutions from smaller pieces: Java classes; to get those pieces to interact.
Assignment 4
Goal: Add input/output capabilities to a Java class; read data, process it, and produce some results calculated from the input using multiple classes. Purpose: To access data from an external source, To learn how to instruct the computer to process it, How to break data into pieces associated with objects. Learn about I/O principles; Building more complex programs by combining simple pieces.
10
11
(the JDK 1.1 version is a 4 MB download and requires 12 MB installed; the JDK 1.2 documentation is a 16 MB download and requires 83 MB installed.) If you are working on a machine that uses something other than Windows or Solaris, let me know.
12
IDEs
Lots of Interactive Development Environments supporting Java, some free, some commercial products, are available. You dont need an IDE to do the work in this course. You will need to be able to use a simple text editor (Notepad on Windows, PICO on Unix will do) and have access to a Java compiler and a Java Virtual machine. One free possibility for Windows environments is Javaedit. Well use Javaedit in the lab. You can download your own free copy at http://www.tiac.net/users/dchase/javaedit.htm (260K download) The CD-ROM that accompanies the text has a limited version of the Code Warrior IDE. It is useful for exploring the example programs that accompany the text. The computers in the S&T I Room 124 lab have Code Warrior installed. I dont recommend using CodeWarrior for this class.
13
Programming
Question: What are Programs? What are some examples? Question: What is Programming?
14
15
/* One of the simplest complete Java programs you can write */ public class HelloClass { // This is a "method"; notice its name
public static void main(String[] args) { System.out.println("Hello class, this is Java!"); } // this ends the method definition } // this ends the class definition
16
17
18
/** a Java class to demonstrate simple Java principles. */ public class MyName { public static void main(String[] args) { // Make a MyName object ...
MyName anObject = new MyName(); // Assign its name from the command line argument anObject.name = args[0]; // ... and ask it to to identify itself System.out.println( anObject.toString() ); // The following is only needed for running the program from // within the Javaedit application on Windows try { byte[] line = new byte[80]; System.out.println("press enter key to end"); System.in.read(line); } catch (java.io.IOException e) { // ignored } } // The rest of this relates to MyName "objects" // each MyName object will remember who you tell it is using // this "instance variable" named "name". String name; // This will allow MyName objects to identify themselves asked. public String toString() { return "Hello, Im a MyName object and my name is " + name; } }
19
Do it!
In this case, just access the already written source code and copy it into a new Javaedit window.
Notice what happens if you dont include "Your name here" Notice what happens if you dont include the quote marks Notice what happens if you just type nonsense within the quote marks
20
What the MyName Class demonstrates Java starts by finding and running the method named main
public static void main(String[] arg)
21
Programming Assignment
Decide what platform you are going to work on Windows GMU CS lab - use JavaEdit and JDK 1.2.2 At home or on some other PC - use JavaEdit and JDK 1.1.8 Unix osf1 supports JDK 1.1.8 for non-GUI applications use pico or vi and the javac and java commands Other systems you may have access to have other challenges Email me if you have questions. Using a simple text editor, (like vi, pico, javaedit, or Notepad) create a file Hello.java.
22
Write the class Hello so that it prints on four lines just: Your name Your GMU ID Your email address The date and time - you decide how to accomplish this; well discuss some possibilities next week You can get these values into the program in any way you like: from the command line or just by having "strings embedded in the source code". Do not prompt the user for the values or bother trying to read the values from the keyboard. Do not try to use SavitchIn. Hint: Make a copy of the MyName.java file; rename it Hello.java; and add what is necessary to fulfill the homework requirements. Run javac compiler Fix any errors Repeat last two steps if necessary until you have no more errors Run java interpreter on class file Turn in transcript of showing sucessful exection of javac and java as well as a copy of source file(s) On Windows copy and paste the contents of a DOS window into a JavaEdit text document window or Notepad. Or take a snapshot of the window showing the program execution using Alt PrintScreen and then paste the snapshot into Paint to print the resultant image. On Unix, use the script command to start recording. Do javac Hello.java java Hello cat Hello.java
23
to show the compiler execution with no errors, record the program running, and list the program source file. Use the exit command to end the script; print the result that is stored in the file named transcript.
24