0% found this document useful (0 votes)
4 views

ITEC217 w1 Intro

This document outlines the introductory lecture for ITEC217, covering essential course information such as required materials, academic integrity modules, and objectives for learning Java programming. It details the structure of computers, programming languages, and the Java development environment, including compiling and running Java programs. Additionally, it highlights the importance of Java in internet applications and provides resources for further learning.

Uploaded by

Junaid Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ITEC217 w1 Intro

This document outlines the introductory lecture for ITEC217, covering essential course information such as required materials, academic integrity modules, and objectives for learning Java programming. It details the structure of computers, programming languages, and the Java development environment, including compiling and running Java programs. Additionally, it highlights the importance of Java in internet applications and provides resources for further learning.

Uploaded by

Junaid Akram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Lecture 1

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

2 | Directorate | Office | Faculty | School


Student Academic Integrity
Module (AIM)

• Explains the importance of acting with Academic Integrity


• Provides information to assist you to act with Academic Integrity
• Accessed through LMS: https://www.acu.edu.au/StudentAIM
• Must get 100% on a short quiz; UNLIMITED attempts to pass
• Must complete by start of Examinations For further information and links
• Final results withheld until completion to the modules, please scan the
QR code:

• Queries? email: academic.integrity@acu.edu.au

Important: The module must be completed before the


start of the Examinations period or final results will be
withheld until successful completion
Respectful Relationships
Module (RRM)
• Explains the importance of respect, safety and consent in
relationships to contribute to students feeling safe on
campus and in the community
• Compulsory for commencing students in 2023
• Students will be automatically enrolled For further information
and links to the modules,
please scan the QR code:
• Queries? email: respectandsafety@acu.edu.au

Important: The module must be completed before the


start of the Examinations period or final results will be
withheld until successful completion
Acknowledgements
The slides used in this unit are adapted from the publisher’s slides of
the textbook:
Daniel Liang 2018, Introduction to Java Programming and Data
Structures, 11th edn, Pearson Education

5 | Directorate | Office | Faculty | School


Objectives
• To understand computer basics, programs, and operating systems
(§1.2–1.4).
• To understand the meaning of Java language specification, API, JDK,
and IDE (§1.6).
• To write a simple Java program (§1.7).
• To display the Java program output (§1.7).
• To explain the basic syntax of a Java program (§1.7).
• To create, compile, and run Java programs (§1.8).
• To use sound Java programming style and document programs properly
(§1.9).
• To explain the differences between syntax errors, runtime errors, and
logic errors (§1.10).

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

Storage Communication Input Output


Devices Memory CPU Devices Devices Devices

e.g., Disk, CD, e.g., Modem, e.g., Keyboard, e.g., Monitor,


and Tape and NIC Mouse Printer

7
What is Computer Programs?

Computer programs, known as software, are


instructions to the computer.

You tell a computer what to do through programs.


Without programs, a computer is an empty machine.
Computers do not understand human languages, so
you need to use computer languages to communicate
with them.

Programs are written using programming languages.

8
Programming Languages
Machine Language Assembly Language High-Level Language

Machine language is a set of primitive instructions


built into every computer. The instructions are in
the form of binary code, so you have to enter binary
codes for various instructions. Programming with
native machine language is a tedious process.
Moreover the programs are highly difficult to read
and modify. For example, to add two numbers, you
might write an instruction in binary like this:

1101101010011010

9
Programming Languages
Machine Language Assembly Language High-Level Language

Assembly languages were developed to make programming


easy. Since the computer cannot understand assembly
language, however, a program called assembler is used to
convert assembly language programs into machine code.
For example, to add two numbers, you might write an
instruction in assembly code like this:
ADDF3 R1, R2, R3

10
Programming Languages
Machine Language Assembly Language High-Level Language

The high-level languages are English-like and easy to learn


and program. For example, the following is a high-level
language statement that computes the area of a circle with
radius 5:
area = 5 * 5 * 3.1415;

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

A compiler translates the entire source code into a


machine-code file, and the machine-code file is then
executed, as shown in the following figure.

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.

Java is a general-purpose programming language.


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)

source code javac byte code java machine code


(.java) compiler (.class) interpreter

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

Note: Clicking the green button displays the source code


with interactive animation. You can also run the code in
a browser. Internet connection is needed for this button.

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

Note: external tutorial videos are available on LEO


25
Bytecode?

JVM in JRE

Creating, Compiling, and


26 Running Programs
Trace a Program Execution
Enter main method

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

27
Trace a Program Execution
Execute statement

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

28
Trace a Program Execution

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

print a message to the


console

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

IDE = Integrated Development Environment


Also remember to correctly download and
install JDK before you can use IDEs!

31
Compiling and Running Java
from Eclipse

Note: external Eclipse tutorial video are available on LEO


32
Visual Studio Code (VSC)
• Similar to an IDE
(with less functions), but it is
more lightweight and easier to use
• Suitable for small projects
• Can edit, run, and debug codes
• For Java, need to install Extension Pack for
Java
• Download from https://code.visualstudio.com

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.

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

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.

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

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!“.

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

37
Statement Terminator
Every statement in Java ends with a semicolon (;).

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

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.

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

39
Blocks

A pair of braces in a program forms a block that groups


components of a program.

public class Test {


Class block
public static void main(String[] args) {
System.out.println("Welcome to Java!"); Method block
}
}

40
Special Symbols

Character Name Description

{} Opening and closing Denotes a block to enclose statements.


braces
() Opening and closing Used with methods.
parentheses
[] Opening and closing Denotes an array.
brackets
// Double slashes Precedes a comment line.

" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.

41
{ …}

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

42
( … )

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

43
;

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

44
// …

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

45
"…"

// This program prints Welcome to Java!


public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

46
Programming Style and
Documentation
• Appropriate Comments
• Naming Conventions
• Proper Indentation and Spacing Lines
• Block Styles

• Your code will be assessed based on these!

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 {
}

• Inline comments: comments on a specific statement


public static void main(String[] args) {
// Print a message to the console
System.out.println("Welcome to Java!");
}

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.

Next-line public class Test


style {
public static void main(String[] args)
{
System.out.println("Block Styles");
}
}

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

public class ShowLogicErrors {


public static void main(String[] args) {
System.out.println("Celsius 35 is Fahrenheit degree ");
System.out.println((9 / 5) * 35 + 32);
}
}

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 1 starting today and due in the lab next week


• Get Java and programming environments correctly installed.
• Write your first Java programs.
• Hint: Try to complete most of the tasks at home (by spending at least 10 hours per
week on this subject after class) before coming to lab sessions.

• 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy