49
Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar [email protected]

Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar [email protected]

Embed Size (px)

Citation preview

Page 1: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Pre-Sessional Java ProgrammingLecture 1a

Reyer Zwiggelaar

[email protected]

Page 2: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Aims

• To give non-programmers confidence– Particularly written for this group so no prior

knowledge expected

• Conversion from other languages to Java– Close links with C++

Page 3: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Structure

• Two weeks: 9-19/09/02

• Mornings 10:00 - 12:00 Lectures– SCI 0.31 & SCI 3.05

• Afternoons 13:00-15:00 Labs Group A/B/C– NT1, NT2, NT5

• Afternoons 15:00-17:00 Labs Group D/E– NT1, NT2

Page 4: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Who’s Doing What

• Lectures– Steve Hordley: [email protected]– Reyer Zwiggelaar: [email protected]

• Lab Sessions– Lilian Blot, Yanong Zhu, Paul Southam, Daan

Zhu, Alex Palmer, Ling Ma, Guoying Qi, Ruiting Liu, Judy Tryggvason, Min Chen

Page 5: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Week One

Day Lecture Lecturer9th September10:00-12:00

SCI 3.05

Overview of the two weeks Introduction to software engineering Intro to OO analysis, design and programming First program in JAVA

Reyer Zwiggelaar

10th September9:00-11:00SCI 3.05

Primitives in Java Variables and Constants Basic operators

Steve Hordley

11th September10:00-12:00

SCI 3.05

Arrays and String String operator null value

Steve Hordley

12th September10:00-12:00

SCI 3.05

Selections: if, if-else, switch Condition and boolean operator

Steve Hordley

Page 6: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

• These come up after important points in a lecture

• If there are no questions I will assume you all have understood it so far

• So, any questions….

Page 7: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Week Two

Day Lecture Lecturer15th September

10:00-12:00SCI 0.31

Repetitions loops: for, while, do-while Steve Hordley

16th September10:00-12:00

SCI 0.31

Objects in Java Steve Hordley

17th September10:00-12:00

SCI 0.31

Methods in Java Steve Hordley

18th September09:30-12:00

SCI 1.07

Postgraduates Registration

19th September10:00-12:00

SCI 3.05

Introduction to GUI (Graphical User Interface) Review of the two weeks into one application

Steve Hordley

19th September12:00-14:00

SCI 0.31

Deans Welcome address (SCI 0.31) Postgraduate welcome party (SCI 3.04)

Page 8: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Assessment Aspects

• Zero rated unit

• Two exercises from each lab-session– Printed on paper – Handed in to SYS Admin Office (or in mailbox

if set up)– One exercise from each lab-session selected (at

random) and marked

Page 9: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

What Will We Use

• The pre-sessional course– JDK/SDK 1.4.0– Simple text editor

• MA23/MA15– The same as above– Or an IDE (Integrated Development

Environment)

Page 10: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Books and Documentation

• There are lots of books out there– Bruce Eckell: Thinking in Java (which is freely

available on the web)– Jan Skansholm: Java From the Beginning– O’Reilly Books: Java in a Nutshell– Pooley and Stevens: Using UML

• www.java.com

• The lecture notes

Page 11: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 12: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Computers and Programs

Memory

Program

Input

Output

Computer

Page 13: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Files, Directories and Disks

• Information is stored on “Hard Disks”

• Disks contain Directories (and Files)

• Directories contain Files (and Directories)

• Tree Structure– Windows Explorer

Page 14: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Simple Software Engineering

SourceCode

Compilation MachineReadableCode

Execution

Page 15: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Simple Software Engineering

• Define the problem

• Outline the solution

• Develop the outline into an algorithm

• Test the algorithm for correctness

• Code the algorithm

• Execute the program

• Document and maintain the program

Page 16: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Simple Software Engineering

• How many students are there in this class?

Page 17: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Object Oriented SE

• An attempt to model the real world

• The data determines the object/classes

• Short introduction here– More details in second week

Page 18: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Object Oriented SE

• A class gives a description of a real world object

• Data and methods– Data describes what the object is– Methods describes what the object can do

Page 19: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Object Oriented SE

• Obtain an English language description

• The nouns indicate objects

• Associate all attributes (data) with the objects

• Operations (methods) are identified by verbs associated with the objects

Page 20: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Object Oriented SE

• How many students are there in this class?

Page 21: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 22: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

• Short break of 10 minutes

Page 23: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Hello World

• First Java program

• No input (initially)

• Output “Hello World” on the screen

Page 24: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Opening a DOS Window

• Moving about– “cd” stands for “change directory”

• “cd java” will move to a directory named “java” (that is if there is a directory named “java”)

• “cd ..” will go one directory up (if you are not already at the top directory)

– “dir” will give directory listing

Page 25: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Text Editing

• Type: edit HelloWorld.java– Within the DOS window you can now edit the

file HelloWorld.java

Page 26: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Entering Text - 1

class HelloWorld{

}

Page 27: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 28: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Entering Text - 2

class HelloWorld{

public static void main(String[] args){

}}

Page 29: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 30: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Entering Text - 3

class HelloWorld{

public static void main(String[] args){

System.out.println(“Hello …. World”);}

}

Page 31: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 32: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Entering Comments//file: HelloWorld.java

/* An application that prints the message “Hello …. World” on the screen*/class HelloWorld{

public static void main(String[] args){

System.out.println(“Hello …. World”);}

}

Page 33: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 34: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Program Layout - Not Like This

class HelloWorld{public static void main(String[] args){System.out.println(“Hello …. World”);}}

Page 35: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Program Layout - Not Like This

class HelloWorld { public static void main(String[] args) {System.out.println(“Hello …. World”); } }

Page 36: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Saving the Program

• File -> Exit– Will ask if you want to save: Yes

• File -> Save and File -> Exit

Page 37: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Compiling a Program

• Type: javac HelloWorld.java– javac is the Java compiler

• If there are no compiler errors than no messages will appear and a file called HelloWorld.class will be created– Type: dir

Page 38: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Executing a Program

• Type: java HelloWorld

• Should produce: “Hello …. World” on the screen

Page 39: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 40: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Introducing Mistakes - 1

class HelloWorld{

public static void main(String[] args)

System.out.println(“Hello …. World”);}

}

Page 41: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Introducing Mistakes - 2

class HelloWorld{

public static void main String[] args){

System.out.println(“Hello …. World”);}

}

Page 42: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Introducing Mistakes - 3

class HelloWorld{

public static void main(String[] args){

System.out.println(“Hello …. World”)}

}

Page 43: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Introducing Mistakes - 4

class HelloWorld{

public void main(String[] args){

System.out.println(“Hello …. World”);}

}

Page 44: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 45: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Hello

• Second Java program

• With input

• Output “Hello ????” on the screen– Where ???? stands for an argument when

executing the program, e.g. java Hello ????

Page 46: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Adapting First Program

class Hello{

public static void main(String[] args){

System.out.println(“Hello ”+args[0]);}

}

Page 47: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

Any Questions

Page 48: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

• Lab Groups– 13:00-15:00 A-NT1/B-NT2/C-NT5– 15:00-17:00 D-NT1/E-NT2

Page 49: Pre-Sessional Java Programming Lecture 1a Reyer Zwiggelaar rz@sys.uea.ac.uk

• End of the Lecture