Professional Documents
Culture Documents
Computer Systems and Java Programming
Computer Systems and Java Programming
2
Computer Hardware
Components CPU
- interprets and executes
Input Device instructions
Central Processing Unit
Main Memory
Arithmetic Control
Logic Unit
`
Unit - store data and
Output Device instructions
- 1 byte = 8 bits
`
Registers
Input Device
Secondary Storage - mouse, keyboard, etc.
`
Output Device
Main Memory
- printer, monitor, etc.
Secondary Storage
- permanent
- floppy disks, hard disks,
3
CDs
Computer Software
Utility Programs
Language Translators Application Software Application
(E.g. Assemblers, (E.g. Word Processors,
(E.g. Editors)
Compilers, Interpreters) Database Systems, etc.) Software
System Software
Operating Systems
(E.g. Unix, MS-DOS, Windows 95, etc.)
-Operating
Systems
-Utility Programs
-Language
Hardware Translators
4
Computer Memory
Memory
Address
Memory Cells
1000 0 1 0 1 0 1 1 0
1001 Content of
1 0 1 0 0 1 0 1
1002
memory
0 1 0 1 1 0 1 0
1003
1004
To store program
1005
instructions and
1006
1007
data
1008
1009
5
Chapter 1
Computer Systems and
Java Programming
• Computer Systems
• Operating Systems and Linux
• Computer Programming
• Object-Oriented Programming
• Java Programming
• Development of a Java Program
• Writing My First Java Program
6
Operating Systems and Linux
• An operating system is a collection of programs
that coordinates the operation of computer
hardware and software.
• The Linux operating system is Unix-like and is
one of the most popular operating systems
nowadays.
• Creator: Linus Torvalds in 1991
• Linux Online:
– http://www.linux.org/
• Also look at the faq (frequently asked questions)
– http://www.linux.org/info/faq1.html#faq.q1
• Lab 1 will give you some practices on using Linux.
7
The Linux File System
• A file system is a collection of files.
9
• To make a copy of a file:
$cp file1 file1.backup
• To rename a file:
$mv file1 newFile1
• To remove a file:
$rm rubbish
10
Working with Directories
• To display your working directory:
$pwd
• To create a directory:
$mkdir lab1
• To change directory:
$cd lab1
$cd /home/user1/hp123456/lab2
$cd ..
11
• To copy a file from one directory to another:
$cp program.java lab1
• To move a file from one directory to another:
$mv program.java lab1
• To remove a directory:
$rmdir dir1
12
Chapter 1
Computer Systems and
Java Programming
• Computer Systems
• Operating Systems and Linux
• Computer Programming
• Object-Oriented Programming
• Java Programming
• Development of a Java Program
• Writing My First Java Program
13
Computer Programming
• Computer Programs
– Set of step-by-step instructions
– Perform a specific task to solve a problem
public class HelloStudents {
public static void main(String[] args){
System.out.println(“Hello Students”);
}
}
O
Execute the
object code
Interpreters
S Compiler
- translation is on-line
Source Code Object Code - HLL programs can
be executed directly
S Interpreter Execute the
interpreted
Source Code
code NB: compiled code
can be executed
faster 17
Chapter 1
Computer Systems and
Java Programming
• Computer Systems
• Operating Systems and Linux
• Computer Programming
• Object-Oriented Programming
• Java Programming
• Development of a Java Program
• Writing My First Java Program
18
High-Level Programming
• Procedural or Structured Programming
- COBOL, Pascal, C, etc.
- Algorithm, task driven – “How does?”
Characteristics:
– Identity
– State
– Behaviour
20
OOP: Classes
Identity
• machine serial number
State/Properties
• color, max speed, etc.
Behavior/Methods
• turn, brake, accelerate
21
OOP: Encapsulation
OBJECT
Brake Method
Apply Brake
Colour
Max Speed
….
Accelerate
Method
Apply Accelerate
22
OOP: Composite Objects
• Easier debugging
- Classes can be tested independently
- Reused objects have already been tested
24
Chapter 1
Computer Systems and
Java Programming
• Computer Systems
• Operating Systems and Linux
• Computer Programming
• Object-Oriented Programming
• Java Programming
• Development of a Java Program
• Writing My First Java Program
25
Take a break…want a cup of
coffee?
26
Java – A Brief History
• James Gosling, Sun Microsystems
Inc., 1991
• Originally a language for
programming embedded consumer
electronic applications
• Initially named as Oak. Then
changed to Java after visiting a
local coffee shop Why OAK?
Because, while trying to think
• In 1995 – Java is a language for of a name, James Gosling
developing Internet applications looked out of his office
window and saw an oak tree!
• Now – one of the most important
general-purpose programming
languages
27
Java 2 Platform
• Java 2 Platform, Standard Edition (J2SE)
– for developing client side standalone applications or
applets
• Java 2 Platform, Enterprise Edition (J2EE)
– for developing client side applications or servlets
• Java 2 Platform, Micro Edition (J2ME)
– for developing applications for mobile devices such as
smart phones
• Java is object-oriented
• Java is simple
• Java is robust and readable
• Java is portable
• Java is secure and distributed
• Java is easy to learn
• Java has many useful features
29
Java Program Translation
Source Code
c
Compiler
Interpreter translates
from byte code into
hardware-specific
IBM PC UNIX/Linux Macintosh
machine code
30
Applets vs Java Applications
• Java Applets
• Java programs to be downloaded via the Internet
• Relatively small programs
• Need a web browser
• Java Applications
• Standalone programs
• Generally larger applications
• Only slight difference in programming, this
course focuses on Java applications
31
Chapter 1
Computer Systems and
Java Programming
• Computer Systems
• Operating Systems and Linux
• Computer Programming
• Object-Oriented Programming
• Java Programming
• Development of a Java Program
• Writing My First Java Program
32
Development of a Java Program
Keyboard
Compiler
Java Virtual
Machine
Execute the
Step3: Run the compiled Java code or class file
interpreted
codes
33
Java Development Environment (JDE)
(1) Use Java Development Kit (JDK) from Sun
Microsystems (Version 1.5)
/*
Purpose: A sample program to print a message “Hello
Students!” On the screen.
Author: S.C. Hui
Date: 30 July 2006
*/
public class HelloStudents { // begin class
public static void main(String[] args) { // main method
System.out.println("Hello Students!"); // statement
} // end method
36
} // end class
Comments
Three ways to write comments:
(1)
/* multiple line comment
This is the first comment
This is the second comment
Will manly use these
This is the third comment
two types of
*/
comments
(2)
// single line comment
Mainly used for
(3)
documentation
/** javadoc comment */
purpose 37
Class Definition
38
The main() Method
For every Java application, it must contain a main() method.
Java applications start execution from the main() method.
41
Compiling My First Java Program
Step 2: To compile your program
Type:
$javac HelloStudents.java
where javac is JDK Java compiler
42
Executing My First Java Program
Step 3: To run the byte code with the Java
interpreter
Type: $java HelloStudents
Memory
44
Hello Students using Message Dialog Box
Using
JOptionPane
45
Key Terms
• Central Processing Unit (CPU)
• main memory
• hardware, software
• Assembly language vs High-level language
• Compiler vs Interpreter
• Java Virtual Machine (JVM)
• Java Byte code instructions
• Java Development Environment (JDE)
• Java Development Toolkit (JDK)
• .java file, .class file
• java command, javac command
• Class definition
• main method
• comment
• statement 46
Review Question
47
Further Reading
http://www.jGRASP.com/
48