CSC111 Chap 01 PDF
CSC111 Chap 01 PDF
Introduction
2
Content
• Chapter 1: Intro to computers and Java
• Chapter 2: Basic computation
• Chapter 3: Flow of control: Branching
• Chapter 4: Flow of control: Loops
• Chapter 5: Defining classes and objects
• Chapter 6: More about objects and methods
• Chapter 7: Arrays
3
Assessment Methods & Policy
4
Homework Assignments & Quizzes
• Homework will be assigned and graded
• All homework assignments will be given with a strict deadline, and
students are required to submit assignments on or before the
deadline.
• Cheating will not be tolerated.
• All homework assignments or project documents should be
submitted using MS-Word and/or appropriate computer software.
• No hand written submission will be accepted.
• In-class quizzes will be given throughout the semester
5
Chapter Outline
• What a computer is
• What a computer program is
• The Programmer’s Algorithm
• How a program that you write in Java is changed into
a form that your computer can understand
• Characteristics of Java
6
Hardware & Software
• Computer systems consist of hardware and software.
• Familiarity with hardware basics helps us understand
software.
7
Components of computer system
• Most modern computers have similar components
including
‒ Input devices (keyboard, mouse, etc.)
‒ Output devices (display screen, printer, etc.)
‒ A processor (CPU): processes a program’s
instructions
‒ Two kinds of memory:
1) Main memory (RAM): temporary storage
2) Secondary Memory: persistent storage
8
Components of computer system
9
Programs
• A program is a set of instructions for a computer to
follow.
• We use programs almost daily (email, word
processors, video games, bank ATMs, etc.).
• Programs are stored in files.
• Programs files are copied from secondary memory to
main memory in order to be run.
How to write a program 10
Levels of Abstraction
• Human thought
• Pseudo-Natural Language (Arabic, English)
• High-level Programming Language (C, C++, Java, …)
• Machine Code
11
The Programmer’s Algorithm
• An algorithm is a finite sequence of instructions that
produces a solution to a problem.
13
Example: sum and average of 5 numbers
• Input:
‒ Five numbers: x1, x2, x3, x4, x5
• Processing:
‒ Sum = x1 + x2 + x3 + x4 + x5
‒ Average = Sum/5
• Output:
‒ Sum
‒ Average
14
Planning the solution
• When planning, algorithms are used to outline the solution
steps using Englishlike statements, called pseudocode
• Simple pseudocode:
1. Start program
2. Get five numbers (x1, x2, x3, x4, x5)
3. Add them (sum = x1 + x2 + x3 + x4 + x5)
4. Compute average (avg
(avg = sum / 5)
5. Print sum & avg
6. End program 15
Coding the program
• Coding is writing the program in a formal language called
programming language.
• The program is written by translating the algorithm steps
into a programming language statements
• The written program is called source code and it is save in a
file with “.java” extension.
• The compiler
checks correctness of the source code (syntax errors)
translates the source code into a machine code if no errors were
found
18
Platform dependent compiling
• Most high-level languages need a different compiler for each type of
computer and for each operating system.
• Most compilers are very large programs that are expensive to
produce.
program
computer.
• Instead, it translates a Java
program into bytecode. java
Class
Loader
• The Java Virtual Machine (JVM):
‒ Class Loader Bytecode
Verifier
‒ stores bytecodes in memory
Bytecode
‒ Bytecode Verifier Interpreter
‒ ensures bytecodes don’t violate JVM
security requirements
‒ Bytecode Interpreter: OS
26
Run Java program – command line
public class HelloWorld {
System.out.println("Hello");
27
Run Java program – Eclipse
public class HelloWorld {
System.out.println("Hello");
28
Print triangle of symbols
System.out.println("*");
System.out.println("**");
System.out.println("***");
System.out.println("****");
System.out.println("*****");
System.out.println("******");
System.out.println("*******");
}
}
29
println()
println() vs. print()
System.out.print("My name is "); System.out.print("Student name:\t");
System.out.print("Mejdl"); System.out.print("Saad");
My name is
Syntax error
Mejdl
My name is
Syntax error
Mejdl
30