Java Notes
Java Notes
Introduction
This page describes how much you remember with different modes of interaction, problem solving, giving precise instructions
The Basics:
Example programs to find out how much you weigh on other planets. See a handout [doc] of the first few examples all in one file:
Version 1: A simple program, comments, semicolon, output
Version 2: Variables, assignment, arithmetic, string concatenation
Version 3: Precedence, parenthesis, type cast, named constants
Scanner Class: Simple form of Input/Output (I/O)
Output using Strings. (For more see also the CFX Strings examples)
Other [you can skip this - it is included for historical reasons]
Before the Scanner class you used to have to use Console IO
Alternate kinds of input for the Planet weights program
- Input using JOptionPane, including number formatting. Also see CFX examples of JOptionPane and number formatting
-Input using BufferedReader for console input. Also see CFX example
Decisions and Looping
The if statement, the switch statement
Loops: while, do-while, and for
Objects and Classes
Objects and Classes (has link to BlueJ shapes example)
Development of Date examples class handout.doc; also see the directory of code for Date class versions, and some further notes on static methods and variables.
Example of variable and parameter scope in Confuse.java (and the Word version)
(See directory of the source code)
See also a few diagrams illustrating object references and how they change
Arrays, Recursion, Linked Lists
Arrays: grouping data
Recursion: a method directly or indirectly calling itself
ArrayList and LinkedList: dynamically created a list
Advanced Topics
Inheritance: Creating a hierarchy of classes that selectively share date and operations
Interfaces: A "contract" with the outside world for a class to have certain methods defined.
Mouse Input requires us to implement a Java Interface.
Java Reference
Download Java
Download Java first before trying to download Eclipse in the step below. As a Java developer, you will want the latest version of the Java Development Kit (JDK), which includes the Java Run-Time Environment (JRE) version.
As of 1/9/2012, the Java downloads page looks like:
Select the JDK version shown highlighted in green above. This will take you to the downloads page for the JDK:
Mac users you may already have Java installed on your computer. If not, follow the link highlighted in blue above. For windows users, choose the appropriate version highlighted in green above.
Download Eclipse
This is a nice Integrated Development Environment (IDE). For Eclipse, download the latest version from:
http://www.eclipse.org/downloads/
As of 1/9/2012, selecting "Eclipse IDE for Java Developers" will take you to the following window:
Select the version (shown in the red box above) that is appropriate for your environment.
Online Java Books and Tutorials
See the online free book Introduction to Programming Using Java, by David Eck, which includes a downloadable pdf version. See a local copy (Aug. 2009)
Online free book Thinking in Java, 3rd Edition, by Bruce Eckel. You may also browse the source code for the book. See the original download site.
Javabat.com has live Java coding exercises that you can try for free, developed by Nick Parlante at Stanford. You need to understand methods to fully enjoy this material.
UIC's library has free access to the online Safari CS books which includes Java programming books.
Bradley Kjell gives an online beginner's Introduction to Java, along with review questions.
Fred Swartz has an online tutorial for Java Basics
Explanation and many examples are given at Dick Baldwin's Programming Tutorials
Other Java links
Java 1.6 (aka Java 6) API Documentation, Operator Precedence
Fred Swartz has many detailed examples (including more advanced topics) in his Java Notes
Sun's tutorial trail on learning Java, though not particularly accessible for beginners
See further non-beginner examples at the CS 340 site