What We Will Cover
Exercise 1.1
Instructions
Use the next 15 minutes to complete the following.
- Join a group of 3-4 people and prepare an answer to one of the following questions.
- Select one member from your group as a representative to describe your answer to the class.
- Start a text file named exercise1.txt.
- Prepare the exercise header as described in the HowTo on submitting exercises
- Label this exercise: Exercise 1.1
- Submit all exercises for this lesson in one file unless instructed otherwise
- Arrange for each student in your group to get a copy of your group's question and answer.
Exercise Questions
- What "burning questions" do you have about the course outline?
- What can you hope to learn by the time you complete this course?
- How do you plan to balance the work required by this course with the other activities in your life?
^ top
1.2: Succeeding in This Course
Objectives
At the end of the lesson the student will be able to:
- Describe how to study effectively for this course
- Use computers in the CTC for homework
- Install software used in this course at home
|
^ top
1.2.1: Elements of Success
- Programming requires you to know many facts and procedures
- Also, you must learn how to solve problems
- To help you master the materials, I provide you with exercises and assignments in addition to lectures
- To succeed in this course, you need to make use of this material
Attend Class
- You need to attend class and pay attention
- When asked questions, you need to respond
- When you cannot attend class for some reason, you need to catch up before the next class meeting
Complete In-Class Exercises During Class
- In-class exercises are problems you are given class-time to complete
- You should complete these problems during the allotted time in class
- However, you have about one-week to complete them after class
- See WebCT for the exact date and time
- You can discuss them with partners or the instructor
- Much easier to solve problems in the classroom than at home
- You should submit the exercises to WebCT before you leave the classroom
- Ensures that something is turned in on time
- You can always unsubmit them if you want to make changes during the week
- Graded on a best-effort basis
- You get full credit for just attempting to complete the exercise
Complete On-line Exercises On-time
- Online exercises (CodeLab) are due about a week after we discuss the topics
- CodeLab gives you a series of graduated exercises with "instant" feedback
- I suggest that you complete the on-line exercises before the homework assignment
Complete Homework Assignments
- Homework assignments have you apply and explore lecture concepts
- Homework assignments can include reading, quizzes and writing code
- If you get confused about or stuck on an assignment:
- Submit homework to WebCT at least the day before it is due
- Even if you are not done, turn it in
- You get some credit for what you did complete
- Make sure to state an accurate status in the README.txt file
- Note that homework deadlines are real -- late homework is not accepted
- Instead, most homework has extra credit possibilities
Study for Exams
- Most students do not have perfect memories
- You need to refresh your memory about programming details before an exam
- Plan on spending time studying for exams
- I will discuss study techniques before the exams
^ top
1.2.2: Time Estimates
- Students often ask how much times is needed for a course
- Estimated average course time per week:
- 1 hour reading the lecture notes and textbook before class
- 4 hours in the classroom
- 8 hours for on-line exercises and homework assignments (excluding extra credit)
- I collect time estimates from students
^ top
1.2.3: Using the CTC for Homework Assignments
- First you will need a login and password
- You can use either Linux, Macintosh or Windows computers for your assignments
- For more information, follow the link to the CTC homepage
^ top
1.2.4: Can I Run This On My Own Computer?
- All the technology we use runs on most any computer
- Instructions on How To Install Java available from the HowTo's page
- Also has instructions for installing jEdit and TextPad
^ top
1.2.5: Summary
- Elements of success in this course:
- Attend class and actively participate
- Submit the in-class exercises before you leave
- Complete on-line exercises on-time
- Do your homework assignments and turn them in on time
- Prepare for and attend exams
- You can complete homework assignments in the CTC
- Also, you can install the necessary software at home or work
^ top
Exercise 1.2
With no more than a single partner, take 5 minutes to complete the following.
- Label this exercise: Exercise 1.2
- Submit all exercises for this lesson in one file unless instructed otherwise
- Complete the following and record the answers to any questions in exercise1.txt.
Specifications
- List the elements of success for this course
- What is the average time you can expect to spend outside the classroom on this course?
- Where do you plan to work on your programming assignments?
^ top
1.3: Introduction to Java
Objectives
At the end of the lesson the student will be able to:
- Describe the programming process
- Name and describe three types of programs you can create with Java
- Describe how Java compares with C++
|
^ top
1.3.1: What Programming is About
- Programming is about solving problems using a computer program
- As such, programming requires a number of steps
- Note that the first two steps do not require a computer
Programming Process
- First step is to define the problem
- You need to describe the nature or basic properties of a problem
- In addition, you need to describe your goal
- Understanding a problem to this degree prepares you to solve it
- Next step is to define an algorithm
- Set of steps for performing a task
- Often has steps that repeat or require decisions
- Can be expressed using psuedocode
- Then you actually write the program using a programming language
- The language we use for this course is called Java
- As you write the program code, you translate human-readable source code into a language understood by the computer
- Usually with a program called a compiler
- Discuss compiling later today
- After code compiles, you test it to make sure it:
- Does what it is supposed to do
- Does not do what it is not supposed to do
- Does what it used to do
- When it works well, you document and deliver the program
More information
^ top
1.3.2: Introducing Java
- Java is a programming language
- A programming language allows a programmer to describe a computation
- Java is a high-level language
- High-level programming languages are easier to use than low-level languages
History of Java
- 1990 - "Green" project started at Sun
- Java originally called Oak
- Developed for digitally controlled consumer devices and computers
- 1991 - Java created by James Gosling, Sun Microsystems, Inc.
- 1992 - "Green" project finished
- 1992 - 1994 - Tried to turn "Green" technology into products
- Failed
- But then the Internet happened...
- 1996 - Official launch of JDK 1.0
- Primary focus was Applets
- 1997 - Sun releases JDK 1.1
- 1998 - Sun releases SDK 1.2
- Now called the Java Platform
- 2000 - Sun releases SDK 1.3
- 2002 - Sun releases SDK 1.4
- 2004 - Sun releases SDK 1.5
- Today a general-purpose programming language used extensively
More information
^ top
1.3.3: Applets, Applications and Servlets
- Java has many uses including:
Applets
- Applet: a Java program that runs in a browser
- Original impetus for Java was applets
- Two famous applets captured the attention of Netscape
- Applets can show 2D and 3D images, play sound, and show video
Desktop Applications
- Applications are programs that perform specific functions for users
- Word processors
- Spreadsheets
- Drawing programs
- Games
- One example: jEdit
- Text editor written in Java
- Most modern applications use a Graphical User Interface (GUI)
- Java provides a complete set of APIs for programming GUIs
- Will use GUIs throughout the course
Mobile Applications
- Java installed on many cell phones provides new opportunities for:
- Mobile games
- Productivity applications like expense trackers
- Messaging applications like auction tracking
- Information applications like news and stock info
- A lot of development work going on in this area
Web-Based Applications
- Web applications are programs that perform specific tasks for the Web
- Java is the dominant programming language for developing these applications
- Java provides special server-side application known as a servlet
- Examples of Web-base applications:
- May Web-based games are written in Java
More Information
^ top
1.3.4: Java Compared to C++
- Syntax intentionally similar to C++
- Easy for C++ programmers to move to Java
- Has several important advances over C++
- All programs are encapsulated in classes
- "Pure" object-oriented language
- OOP improves programmer productivity (>2X)
- Automatic memory management ("garbage" collection)
- Improves memory management and reliability
- More intelligent use of pointers (references)
- No pointer arithmetic
- Simpler model
- Less error prone and more reliable
- Build-in bounds checking of arrays
- Helps prevent buffer overflow
- Buffer overflows are one of the leading causes of computer vulnerabilities
- Built-in support for multithreading
- Large class-libraries
- Known as APIs (Application Programming Interfaces)
- Runs without recompiling on many operating systems and hardware platforms
- Fastest Java runs slower than fastest C++
- Originally about 10x slower, now about 2x with "Hotspot" compiler
- Compilers exist to translate directly to native machine code (GCJ)
- Lose portability when compiled
- Note that Java is usually faster than MS Visual C++
- Moore's law makes this issue less important every day
^ top
1.3.5: Summary
- Java used to develop many types of programs including:
- Applications: programs that perform specific functions for users
- Applets: a Java program that runs in a browser
- Servlet: server-side application
- Java often compared to C++
- Similar syntax
- Bounds-checking of arrays
- Automatic memory management (not present in C++)
- Better model for using pointers (references)
- Built-in support for multithreading
- Runs slower than C++
^ top
Exercise 1.3
- Label this exercise: Exercise 1.3
- Submit all exercises for this lesson in one file unless instructed otherwise
- Complete the following and record the answers to any questions in exercise1.txt.
Specifications
- What are three types of programs you can create with Java?/li>
- How does Java compare with C++?
- How can Java performance be improved so that it is as fast as C++?
^ top
1.4: Editing, Compiling and Running Java Programs
Objectives
At the end of the lesson the student will be able to:
- Explain how a virtual machine helps Java achieve platform independence
- Compile and run Java programs, given the source code
- Display program output to a console
|
^ top
1.4.1: Using the Windows Command Line
- Windows provides a command-line interface to the Operating System
- Sometimes known as a Console
- The command line provides direct access to the File System and allows you to run ALL types of programs
- To use the command line, you type commands at a command prompt
C:\>dir
After typing a command, you press the Enter key
Starting a Console Session
- From the Start menu, Select
Run...
- In the text box, type:
cmd for Windows NT/2000/XP
command for Windows 95/98/ME
Ending a Console Session
- At the command line, type
exit
C:\>exit
Getting Help
- Once you have a command line, you can get a list of commands by typing:
help
C:\>help
To get help for a specific command, you type help followed by the command
For example, to find out more about using the cd command:
C:\>help cd
^ top
1.4.2: Navigating Directories and Viewing Files
- When a console session starts, you may not be in the directory you want
- You can verify the current directory location by looking at the command prompt
C:\j2sdk1.5.0>
You can list the files in the current directory using dir
C:\>dir
To change to a lower subdirectory level: cd directoryName
C:\>cd "Documents and Settings"
Change up one directory level: cd .. (change directory)
C:\>cd ..
Change to the root of the file system: cd \
C:\>cd \
Change to any location in the file system: cd path
C:\>cd \Documents and Settings\YourLogin\Desktop
You can view a file using more followed by the name of the file
C:\>more exercise1.txt
An easier way to view files is to use either Notepad or TextPad
For exampe, to view a file using Notepad:
C:\>notepad exercise1.txt
More Information
^ top
1.4.3: How Java Compiles and Interprets Code
- Developing Java code consists of three steps
- Writing the source code
- Compiling the source code to bytecode
- Executing (running) the program
- This process is repeated many times during development
|
Three steps to creating a Java program:
- Editing
- Write a program's source code using any text editor
- Save the source code on file system or network
- Source code files have a
.java suffix
- Compilation
- Use a compiler to translate the source code to bytecodes
- Files with translated bytecodes have
.class suffix
- Execution
- Use the
java interpreter program to run the bytecodes
- Class Loader: moves bytecodes from file system or network into memory
- Bytecode Verifier: tests bytecodes to establish safety and security
- Interpreter (JVM): translates bytecodes into machine language
Java Virtual Machine (JVM) makes "write once, run anywhere" possible
|

|
More Information
^ top
1.4.4: Writing, Editing and Saving Source Code
- You can use almost any text editor to write and save Java source code
- Windows: jEdit, Notepad, WordPad, TextPad, ...
- Linux/UNIX: jEdit, VIM, gedit, pico, ...
- Mac: jEdit, SimpleCap, ...
- Make sure you save the file using the four-letter extension:
java
About Using IDEs
- There are many Integrated Development Environments (IDEs) available for Java
- Typically provide visual tools for designing forms and debugging code
- I do not recommend using an IDE while learning Java
- An IDE will generate code for you, which does not help you learn
- IDEs are complex tools that themselves are difficult to learn
- Learning the tool can distract you from your goal of learning Java
- I do recommend using IDEs once you have a good understanding of Java
- Easier to develop user interfaces
- Improves programmer productivity
- Any program you submit must run from the command line
Sample Program: Hello World
- Here is an example program you can save as a source code file
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Copy this into a text editor and then save it
The next step is to compile and run the program
^ top
1.4.5: Compiling and Running Programs
Compiling Source Code
- Open a window with a command prompt
- Change the directory (
cd) to where program source code is stored
- Type:
javac HelloWorld.java
- If no errors, the compiler creates
HelloWorld.class
- You can verify the
HelloWorld.class file exists using the dir command
Running a Program
- Type:
java HelloWorld
- Interpreter loads
.class file for HelloWorld
- Note that
.class suffix is not typed
- Interpreter calls the
main method by default
Using Text Editors
- Many text editors have provision for compiling within the editor
- TextPad: Tools menu
- jEdit: Press the java and javac folder tabs
- Programming style: Lines no longer than 80 characters
- Programming style: Do not use tabs
More Information
^ top
1.4.6: Summary
- Java programs require three steps:
- Create source code with an editor (or IDE)
- Compile to bytecode using a compiler (
javac FileName.java)
- Execute using a JVM (
java FileName)
- You can use most any text editor for writing and editing source code
- Many text editors provide features to make it easier to compile and run programs
- Once you have mastered the basics of Java, you should use an IDE
- While you are learning, it is better to use a text editor
^ top
Exercise 1.4
- Label this exercise: Exercise 1.4
- Complete Exercise 1-2 on page 33 of the textbook. Include the
NotepadTest.java and NotepadTest.class files when submitting the exercises for this week.
- Record answers to the following questions in your
exercise1.txt file.
Questions
- How does the Java Virtual Machine help Java achieve platform independence?
- Assume that the code you want to compile from the command line is in the directory:
C:\code. What command to you type at the command line to move the console window to this directory?
Note: do not forget to turn in your exercises following the instructions on How To Submit In-Class Exercises.
^ top
Wrap Up
Due Next: A1: Information Please! (9/8/04) Exercise 1 and CodeLab Lesson 1 (9/8/04)
^ top
Home
| WebCT
| Announcements
| Schedule
| Expectations
| Course info
Help
| FAQ's
| HowTo's
| Links
Last Updated: July 07 2004 @18:16:36
|