ITEC217 w1 Intro
ITEC217 w1 Intro
ITEC217
Introduction to
Computers, Programming
Programs, and Concepts
Java
TODO Checklist – LEO walkthrough
• Review LEO site (e.g. class times, deadlines, contacts, resources)
• Review the unit outline (e.g. assessments, schedule, policies)
• Locate all learning materials such as lecture slides, lab tasks, assessment guides
• Get a textbook (eBook or hard copy)
Required textbook: Liang DY, 2018. Introduction to Java Programming and Data
Structures, Comprehensive Version, Global Edition, 11th Edition, Pearson Education.
Online purchasing links:
https://www.pearson.com.au/9781292221892 (publisher e-text)
https://www.amazon.com.au/Introduction-Java-Programming-Structures-
Global/dp/1292221879 (paperback)
• Find your lab locations (on campus labs start from week 2)
• Expected study time per week: 10-15 hours
• Pre-view lecture slides, book chapters, lab tasks before each class
• Workshop recordings after each class
6
What is a Computer?
A computer consists of a CPU, memory, hard disk, monitor,
printer, and communication devices connected to the bus –
transfer paths on the motherboard.
Bus
7
What is Computer Programs?
8
Programming Languages
Machine Language Assembly Language High-Level Language
1101101010011010
9
Programming Languages
Machine Language Assembly Language High-Level Language
10
Programming Languages
Machine Language Assembly Language High-Level Language
11
Popular High-Level Languages
Languag e Description
Ada Named for Ada Lovelace, who worked on mechanical general-purpose computers. The Ada
language was developed for the Department of Defense and is us ed mainly in d efense projects.
BASIC Beginner’s All-purpose Symbolic Instruction Code. It was d esigned to be learned and used easily
by beginners.
C Developed at Bell Laboratories. C combines the power of an ass embly language with the ease of
use and portability of a high-level language.
C++ C++ is an object-oriented language, based on C.
C# Pronounced “C Sh arp.” It is a hybrid of Java and C++ and was developed by Microsoft.
COBOL COmmon Business Oriented Language. Used for business applications.
FORTRAN FORmula TRANslation. Popular for scientific and mathematical applications.
Java Developed by Sun Microsystems, now part of Oracle. It is widely used for developing platform -
independent Internet app lications.
Pascal Named for Blaise Pascal, wh o pioneered calculating machin es in the seventeenth century. It is a
simple, s tructured, general -purpose language p rimarily for teachin g programming.
Python A simple gen eral-purpose scripting language good for writing short programs .
Visual Visual Basic was developed by Microsoft and it enables the pr ogrammers to rapidly develop
Basic graphical user interfaces.
12
Interpreting/Compiling Source Code
A program written in a high-level language is called a
source program or source code. Because a computer
cannot understand a source program, 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.
13
Interpreting Source Code
An interpreter reads one statement from the source code,
translates it to the machine code or virtual machine code,
and then executes it right away, as shown in the following
figure. Note that a statement from the source code may be
translated into several machine instructions.
14
Compiling Source Code
15
Operating Systems
The operating system (OS) is a
program that manages and
controls a computer’s activities.
The popular operating
systems for general-
purpose computers are
Microsoft Windows, Mac
OS X, and Linux.
Application programs, such
as a Web browser or a
word processor, cannot run
unless an operating
system is installed and
running on the computer.
16
Why Java?
The answer is that Java enables users to develop
and deploy applications on the Internet for servers,
desktop computers, and small hand-held devices.
The future of computing is being profoundly
influenced by the Internet, and Java promises to
remain a big part of that future. Java is the Internet
programming language.
17
Java, Web, and Beyond
• Java can be used to develop standalone
applications.
• Java can be used to develop applications
running from a browser.
• Java can also be used to develop
applications for hand-held devices.
• Java can be used to develop applications
for Web servers.
18
Java’s History
• James Gosling and Sun Microsystems
• Oak – basis of Java, but a different language
• Java, May 20, 1995, Sun World
• Sun acquisition by Oracle, 2009
• HotJava
• The first Java-enabled Web browser
• Early History Website:
http://www.java.com/en/javahistory/index.jsp
19
Java DK Versions
• JDK 1.02 (1995)
• JDK 1.1 (1996)
• JDK 1.2 (1998)
• JDK 1.3 (2000)
• JDK 1.4 (2002)
• JDK 1.5 (2004) a. k. a. JDK 5 or Java 5
• JDK 1.6 (2006) a. k. a. JDK 6 or Java 6
• JDK 1.7 (2011) a. k. a. JDK 7 or Java 7
• JDK 1.8 (2014) a. k. a. JDK 8 or Java 8
• …
• The latest JDK 17 (2021)
https://www.oracle.com/java/technologies/downloads/
• JDK (Java Development Kit) contains Java Complier, JRE (Java
Runtime Environment), and other tools.
20
JDK Editions
• Java Standard Edition (Java SE)
• used to develop client-side standalone applications or
applets.
• Java Enterprise Edition (Java EE)
• used to develop server-side applications such as Java
servlets, Java ServerPages, and Java ServerFaces.
• Java Micro Edition (Java ME).
• used to develop applications for mobile devices such as
cell phones.
This book uses Java SE to introduce Java
programming.
21
Java Pipeline
• Java combines both compilation and
interpretation
• Java source code (.java) is first compiled
into byte code (.class)
• Byte code is interpreted by Java Virtual
Machine (JVM)
22
A First Java Program
Listing 1.1
// This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Welcome https://liveexample.pearsoncmg.com/html/Welcome.html
23
Creating and Editing Using NotePad
To use NotePad, type
notepad Welcome.java
from the DOS prompt.
24
Compiling and Running Java
from the Command Window
• Download and install the latest JDK
• Set path to JDK bin directory
• set path=c:\Program Files\java\jdk1.8.0\bin
• Compile
• javac Welcome.java
• Run
• java Welcome
JVM in JRE
27
Trace a Program Execution
Execute statement
28
Trace a Program Execution
29
Two More Simple Examples
https://liveexample.pearsoncmg.com/html/
WelcomeWithThreeMessages
WelcomeWithThreeMessages.html
ComputeExpression https://liveexample.pearsoncmg.com/html/
ComputeExpression.html
30
Popular Java IDEs
• Eclipse (preferred in this unit)
• IntelliJ
• NetBeans
31
Compiling and Running Java
from Eclipse
33
Anatomy of a Java Program
• Class name
• Main method
• Statements
• Statement terminator
• Reserved words
• Comments
• Blocks
34
Class Name
Every Java program must have at least one class. Each
class has a name. By convention, class names start with an
uppercase letter. In this example, the class name is
Welcome.
35
Main Method
Line 2 defines the main method. In order to run a class, the
class must contain a method named main. The program is
executed from the main method.
36
Statement
A statement represents an action or a sequence of
actions. The statement System.out.println("Welcome to
Java!") in the program in Listing 1.1 is a statement to
display the greeting "Welcome to Java!“.
37
Statement Terminator
Every statement in Java ends with a semicolon (;).
38
Reserved words
Reserved words or keywords are words that have a
specific meaning to the compiler and cannot be used for
other purposes in the program. For example, when the
compiler sees the word class, it understands that the
word after class is the name for the class.
39
Blocks
40
Special Symbols
" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.
41
{ …}
42
( … )
43
;
44
// …
45
"…"
46
Programming Style and
Documentation
• Appropriate Comments
• Naming Conventions
• Proper Indentation and Spacing Lines
• Block Styles
47
Appropriate Comments
• Block comments: a summary at the beginning of the
program to explain what the program does, its key
features, its supporting data structures, and any unique
techniques it uses.
/*Include your name, class section,
*instructor, date, and a brief description
*at the beginning of the program.
*/
public class Welcome {
}
48
Naming Conventions
• Choose meaningful and descriptive names.
• Class names:
• Capitalize the first letter of each word in the name.
For example, the class name
ComputeExpression
49
Proper Indentation and
Spacing
• Indentation
• Indent by a tab space.
• Spacing
• Use blank line to separate segments of the code.
50
Block Styles
Use end-of-line style for braces.
End-of-line
style
public class Test {
public static void main(String[] args) {
System.out.println("Block Styles");
}
}
51
Programming Errors
• Syntax/compilation Errors
• Detected by the compiler
• Runtime Errors
• Causes the program to abort, e.g., divided by 0
• Logic Errors
• Produces incorrect result
52
Syntax Errors
public class ShowSyntaxErrors {
public static main(String[] args) {
System.out.println("Welcome to Java);
}
}
https://liveexample.pearsoncmg.com/html/
ShowSyntaxErrors ShowSyntaxErrors.html
53
Runtime Errors
public class ShowRuntimeErrors {
public static void main(String[] args) {
System.out.println(1 / 0);
}
}
https://liveexample.pearsoncmg.com/html/
ShowRuntimeErrors ShowRuntimeErrors.html
54
Logic Errors
https://liveexample.pearsoncmg.com/html/
ShowLogicErrors ShowLogicErrors.html
55
Assessment 1 (50%) Brief
• Programming Studio that contains
• Fortnightly lab sessions (week 2, 4, 6, 8 10, and 12, totally 30%)
• Alternating fortnightly quizzes (week 3, 5, 7, 9, and 11, totally 20%, two attempts)
• Details in the ‘Assessment 1 Guide’ document under the ‘Assessment’ section on LEO.
• Lab protocols:
• Bring your own device
• Engagement (50%) and Task Completion (50%)
• Attend the lab on time and throughout the session until you are marked off, show you
are engaged in solving the lab tasks by communicating with lab tutor and other
students in the class
• Show tutor how your code can be run with the desirable output on your laptop
• Clearly explain to the tutor the logic and structure of your code and answer tutor’s
questions if there are any.
• Submit your documented code on LEO by the end of the lab day
56
After class TODO list:
Next week
• Review the lecture
Java Elementary • Read book chapter
Programming
• Attempt assessment
• Attend lab