Chapter 1
Chapter 1
Programming
PROGRAMMING 1
COS 011
Textbook:
Think Java: How to Think Like a Computer Scientist
By Allen B. Downey
Reference book:
Savitch, W. J. (2008).Absolute Java. Boston, Mass: Addison-Wesley.
Mark Distribution
3
problem-solving.
As we go further, this skill will become clearer.
Chapter 1, cont.
6
computer.
However, computer understand only 0 and 1
Compiler
Java code -------- Java byte-code
Interpreter
Java byte-code --- Machine code
9
Program
10
What is a program?
input:
Get data from the keyboard, or a file, or some other device.
output:
Display data on the screen or send data to a file or other
device.
math:
Perform basic mathematical operations like addition and
multiplication.
testing:
Check for certain conditions and run the appropriate
sequence of statements.
repetition:
Perform some action repeatedly, usually with some variation.
Syntax and Semantics
12
1) Syntax errors:
A grammatical mistake in a program
System.out.println(Hello, world.);
System.out.println("Hello, world.");
14
2. Run-time errors
Does not appear until you run the program and it
appears as windows or dialog boxes that contain
information about what happened and what the program
was doing when it happened.
The compiler cannot detect these errors: an error message is not
generated after compilation, but after execution.
Redundancy
Redundancy To make up for ambiguity and
Formal languages are more reduce misunderstandings,
concise. natural languages are often
redundant.
Literalness Literalness
Formal languages mean exactly
Natural languages are full of
what they say. idiom and metaphor.
Java Program
18
//System.out.println("*****");
//System.out.println("*****");
//System.out.println("*****");
//System.out.println("*****");
//System.out.println("*****");
}
Knowledge Check
33
class Hello
{
/ main: generate some simple output
public static void main(String[] args)
{
System.out.println("Hello, world.”)
}
}
34
Questions ?!