Download Lesson 01 - CDNIS Community Sites

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
INTRODUCTION TO JAVA
UNIT
C
A
N
A
D
I
A
N
I
N
T
E
R
N
A
T
I
O
N
A
L
S
P1
LESSON
C
O
H
O
UNIT
L
P1
1
O
F
LESSON
H
K
O
O
N
N
G
G
1.1
INTRODUCTION
IB DP Computer science – Standard Level – ICS3U
Key Themes
• the central theme is to learn how to solve problems
by writing a program
• programming means to create or develop software
• developers create software with the help of
programming languages
– there is no “best” language
– each language has its own strengths and weaknesses
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Key Themes
• a computer is an electronic device that stores and
processes data
• a computer includes both hardware and software
– hardware comprises the visible, physical elements of the
computer
– software provides the invisible instructions that control
the hardware and make it perform specific tasks
1
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Key Themes
• a computer consists of the following major hardware
components:
–
–
–
–
–
–
central processing unit (CPU)
memory (main memory)
storage devices (such as disks and CDs)
input devices (such as the mouse and keyboard)
output devices (such as monitors and printers)
communication devices (such as network interface cards)
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Key Themes
• the components are interconnected by a subsystem
called a bus
– the bus is built into the motherboard, which is a circuit
case that connects all of the parts of a computer together
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
CPU
• retrieves instructions from memory and executes
them
• usually has two components:
– a control unit
• controls and coordinates the actions of the other components
– an arithmetic/logic unit
• performs numeric operations and logical operations
2
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
CPU
• unit of measurement of clock speed is the hertz (Hz),
with 1 hertz equalling 1 pulse per second
• these pulses are used to control and synchronize the
pace of operations
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Memory
• storing information in a computer is simply a matter
of setting a sequence of switches on or off
– the minimum storage unit in a computer is a byte
– a byte is composed of eight bits
• memory consists of an ordered sequence of bytes for
storing programs as well as data that the program is
working with
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Storage Devices
• There are three main types of storage devices:
– magnetic disk drives
– optical disc drives (CD and DVD)
– USB flash drives
3
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Input and Output Devices
• input and output devices let the user communicate
with the computer
• keyboard
• mouse
• monitor
UNIT
P1
LESSON
1.2
WHAT IS A COMPUTER?
IB DP Computer science – Standard Level – ICS3U
Communication Devices
• a dial-up modem uses a phone line and can transfer
data at a speed up to 56,000 bps (bits per second)
• a digital subscriber line (DSL) connection also uses a
standard phone line, but it can transfer data 20 times
faster than a standard dial-up modem
• a cable modem uses the cable TV line maintained by
the cable company and is generally faster than DSL
• a network interface card (NIC) is a device that
connects a computer to a local area network (LAN)
UNIT
P1
LESSON
1.3
PROGRAMMING LANGUAGES
IB DP Computer science – Standard Level – ICS3U
Key Themes
• computer programs, known as software, are
instructions that tell a computer what to do
• all programs must be converted into the instructions
the computer can execute
4
UNIT
P1
LESSON
1.3
PROGRAMMING LANGUAGES
IB DP Computer science – Standard Level – ICS3U
Key Themes
• machine language
– a set of built-in primitive instructions
– in the form of binary code
• assembly language
– uses a short descriptive word to represent each of the
machine-language instructions
– computer cannot execute assembly language, another
program (assembler) is used to translate assemblylanguage programs into machine code
UNIT
P1
LESSON
1.3
PROGRAMMING LANGUAGES
IB DP Computer science – Standard Level – ICS3U
Key Themes
high-level language
platform independent
English-like
l h l k and
d easy to llearn and
d use
program written in a high-level language is called a
source program or source code
• a source program must be translated into machine
code for execution
•
•
•
•
– the translation can be done using another programming
tool called an interpreter or a compiler
UNIT
P1
LESSON
1.4
OPERATING SYSTEMS
IB DP Computer science – Standard Level – ICS3U
Key Themes
• the operating system (OS) is the most important
program that runs on a computer
– manages and controls a computer’s activities
• The major tasks of an operating system are as follows:
– controlling and monitoring system activities
– allocating and assigning system resources
– scheduling operations
5
UNIT
P1
LESSON
1.5
JAVA, WWW, AND BEYOND
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Java is a powerful and versatile programming
language for developing software running on mobile
d
devices,
d
desktop
k
computers, and
d servers.
– simple, object oriented, distributed, interpreted, robust,
secure, architecture neutral, portable, high performance,
multithreaded, and dynamic
UNIT
P1
LESSON
1.6
THE JAVA LANGUAGE SPECS
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Java syntax is defined in the Java language
specification, and the Java library is defined in the
Java API.
• The JDK is the software for developing and running
Java programs.
• An IDE is an integrated development environment for
rapidly developing programs.
UNIT
P1
LESSON
1.6
THE JAVA LANGUAGE SPECS
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Java language specification is a technical definition of
the Java programming language’s syntax and
semantics
• application program interface (API), also known as
library, contains predefined classes and interfaces for
developing Java programs
6
UNIT
P1
LESSON
1.6
THE JAVA LANGUAGE SPECS
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Java Standard Edition (Java SE) to develop client-side
applications. The applications can run standalone or
as applets
l
running ffrom a Web
b browser
b
• Java Enterprise Edition (Java EE) to develop serverside applications, such as Java servlets, JavaServer
Pages (JSP), and JavaServer Faces (JSF)
• Java Micro Edition (Java ME) to develop applications
for mobile devices, such as cell phones
UNIT
P1
LESSON
1.7
A SIMPLE JAVA PROGRAM
IB DP Computer science – Standard Level – ICS3U
Key Themes
• a Java program is executed from the main method in
the class
• create, compile, and execute your first Java program
UNIT
P1
LESSON
1.7
A SIMPLE JAVA PROGRAM
IB DP Computer science – Standard Level – ICS3U
Key Themes
public class HelloWorld {
public static void main(String[] args) {
// Display message Welcome to Java! on the console
System.out.println(“Hello World!");
}
}
7
UNIT
P1
LESSON
1.7
A SIMPLE JAVA PROGRAM
IB DP Computer science – Standard Level – ICS3U
Key Themes
Character
Name
Description
{ }
Opening and closing braces
Denote a block to enclose
statements.
( )
Opening and closing
parentheses
Used with methods.
[ ]
Opening and closing brackets
Denote an array.
//
Double slashes
Precede a comment line.
“”
Opening and closing
quotation marks
Enclose a string
;
Semicolons
Mark the end of a statement.
UNIT
P1
LESSON
1.8
CREATE, COMPILE, EXECUTE
IB DP Computer science – Standard Level – ICS3U
Key Themes
• You save a Java program in a .java file and compile
it into a .class file. The .class file is executed by
the
h Java Virtuall Machine.
h
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Good programming style and proper documentation
make a program easy to read and help programmers
prevent errors.
– Programming style deals with what programs look like.
– Documentation is the body of explanatory remarks and
comments pertaining to a program.
8
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Java comments
– line comments (beginning with //)
– block comments (enclose with /*…*/)
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Java comments
– line comments (beginning with //)
– block comments (enclose with /*…*/)
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Expectations
• each .java file must begin with the following
comments
/**
* Class description goes here. The description must explains the
* purpose of the class.
*
* @version: 1.0
* @date:
2015 September 01
* @author: Dr. Benedict Hung
*/
9
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Expectations
• each conditional and selection statement must begin
with the following comments
/**
* pre-condition: describe the current state of the program
* post-condition: describe the expected state of the program
*/
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Expectations
• each method must begin with the following comment
// describe the purpose of the method
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Indentation
– consistent indentation style makes programs clear and
easy to read, debug, and maintain
– illustrate the structural relationships between a program’s
components
– single space should be added on both sides of a binary
operator
10
UNIT
P1
LESSON
1.9
STYLE AND DOCUMENTATION
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Block Style
– block is a group of statements surrounded by braces
Next Line Style
End-of-Line Style
public class Test
{
public static void main(String[] args)
{
System.out.println("Block Styles");
}
}
public class Test {
public static void main(String[] args) {
System.out.println("Block Styles");
}
}
UNIT
P1
LESSON
1.10
PROGRAMMING ERRORS
IB DP Computer science – Standard Level – ICS3U
Key Themes
• Programming errors can be categorized into three
types: syntax errors, runtime errors, and logic errors.
– syntax error are detected by the compiler
• errors in code construction
– runtime errors are errors that cause a program to
terminate abnormally
• input mistakes typically cause runtime errors
– logic errors occur when a program does not perform the
way it was intended to
UNIT
P1
LESSON
1.10
PROGRAMMING ERRORS
IB DP Computer science – Standard Level – ICS3U
Key Themes
• four common errors
–
–
–
–
missing braces
missing semicolons
missing quotation marks
misspelling names
11
UNIT
T1
LESSON
1
INTRODUCTION TO JAVA
IB DP Computer science – Standard Level – ICS3U
Homework
Pg. 30 # 1.1, 1.4, 1.6, 1.9
12