Chapter 1
Introduction
1.1 Programs
A program is a set of instructions for processing data.
class sum {
public static void main (String[] args) {
System.out.println( "Type 2 integer values: ");
System.out.println( readInt() + readInt() );
}
static int readInt(){
int digit, num;
digit = readCh();
while( (digit < '0') || (digit>'9') ){
digit = readCh();
}
num = digit - '0'; digit = readCh();
while( (digit>='0') && (digit<='9') ){
num = num * 10 + digit - '0';
digit = readCh();
}
return num;
}
static int readCh(){
int ch;
try{ ch = System.in.read(); }
catch ( java.io.IOException e ){
System.out.println("input error");
}
return ch;
}
}
1.2 Programming Languages
A programming language consists of
- Predefined tokens
- Syntax-rules for defining tokens and structures of tokens
- Semantics-conventions on how tokens and structures should be interpreted.
class hello {
public static void main (String[] args) {
System.out.println("Hello, world!");
}
}
1.3 Why Java?
- Small simple core
- Comprehensive set of features provided in easy to use libraries
- Available for large array of platforms
1.4 Programming
- Analysis of the problem
- Design of a solution
- Coding
With good designs, coding turns out to be a straightforward task.
1.5 Course Objectives
Learn
- Basic paradigms of analysis and design
- The programming language Java
1.6 The Life of Programmers
1.7 Assignment #1: APIs
Due: We, Apr 2, at class
- Open the web page http://java.sun.com/j2se/1.4.1/docs/api/overview-summary.html
- Locate the entry ‘java.io’ and move into its web page.
- Locate the entry ‘PrintStream’ and move into its web page.
- Print out the content of the web page, until the ‘Constructor Detail’ part.
- Write a report (of up to about one page) describing your understanding of the content of the web page.
- You should hand in your report, together with the print out of the web page.
- Write your name clearly on the report, and provide a code under which your grades should be posted. The code
should consist only of letters and digits.
Q&A