lecture01a_03_04

Download Report

Transcript lecture01a_03_04

Pre-Sessional Java Programming
Lecture 1a
Reyer Zwiggelaar
[email protected]
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++
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
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
Week One
Day
th
9 September
10:00-12:00
SCI 3.05
th
10 September
9:00-11:00
SCI 3.05
th
11 September
10:00-12:00
SCI 3.05
th
12 September
10:00-12:00
SCI 3.05
Lecture












Overview of the two weeks
Introduction to software engineering
Intro to OO analysis, design and programming
First program in JAVA
Primitives in Java
Variables and Constants
Basic operators
Arrays and String
String operator
null value
Selections: if, if-else, switch
Condition and boolean operator
Lecturer
Reyer Zwiggelaar
Steve Hordley
Steve Hordley
Steve Hordley
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….
Week Two
Day
th
15 September
10:00-12:00
SCI 0.31
th
16 September
10:00-12:00
SCI 0.31
th
17 September
10:00-12:00
SCI 0.31
th
18 September
09:30-12:00
SCI 1.07
th
19 September
10:00-12:00
SCI 3.05
th
19 September
12:00-14:00
SCI 0.31
Lecture
Lecturer

Repetitions loops: for, while, do-while
Steve Hordley

Objects in Java
Steve Hordley

Methods in Java
Steve Hordley

Postgraduates Registration


Introduction to GUI (Graphical User Interface)
Review of the two weeks into one application


Deans Welcome address (SCI 0.31)
Postgraduate welcome party (SCI 3.04)
Steve Hordley
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
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)
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
Any Questions
Computers and Programs
Input
Memory
Program
Computer
Output
Files, Directories and Disks
•
•
•
•
Information is stored on “Hard Disks”
Disks contain Directories (and Files)
Directories contain Files (and Directories)
Tree Structure
– Windows Explorer
Simple Software Engineering
Source
Code
Compilation
Machine
Readable
Code
Execution
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
Simple Software Engineering
• How many students are there in this class?
Object Oriented SE
• An attempt to model the real world
• The data determines the object/classes
• Short introduction here
– More details in second week
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
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
Object Oriented SE
• How many students are there in this class?
Any Questions
• Short break of 10 minutes
Hello World
• First Java program
• No input (initially)
• Output “Hello World” on the screen
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
Text Editing
• Type: edit HelloWorld.java
– Within the DOS window you can now edit the
file HelloWorld.java
Entering Text - 1
class HelloWorld
{
}
Any Questions
Entering Text - 2
class HelloWorld
{
public static void main(String[] args)
{
}
}
Any Questions
Entering Text - 3
class HelloWorld
{
public static void main(String[] args)
{
System.out.println(“Hello …. World”);
}
}
Any Questions
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”);
}
}
Any Questions
Program Layout - Not Like This
class HelloWorld
{
public static void main(String[] args)
{
System.out.println(“Hello …. World”);
}
}
Program Layout - Not Like This
class HelloWorld { public static void main(String[] args) {
System.out.println(“Hello …. World”); } }
Saving the Program
• File -> Exit
– Will ask if you want to save: Yes
• File -> Save and File -> Exit
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
Executing a Program
• Type: java HelloWorld
• Should produce: “Hello …. World” on the
screen
Any Questions
Introducing Mistakes - 1
class HelloWorld
{
public static void main(String[] args)
System.out.println(“Hello …. World”);
}
}
Introducing Mistakes - 2
class HelloWorld
{
public static void main String[] args)
{
System.out.println(“Hello …. World”);
}
}
Introducing Mistakes - 3
class HelloWorld
{
public static void main(String[] args)
{
System.out.println(“Hello …. World”)
}
}
Introducing Mistakes - 4
class HelloWorld
{
public void main(String[] args)
{
System.out.println(“Hello …. World”);
}
}
Any Questions
Hello
• Second Java program
• With input
• Output “Hello ????” on the screen
– Where ???? stands for an argument when
executing the program, e.g. java Hello ????
Adapting First Program
class Hello
{
public static void main(String[] args)
{
System.out.println(“Hello ”+args[0]);
}
}
Any Questions
• Lab Groups
– 13:00-15:00 A-NT1/B-NT2/C-NT5
– 15:00-17:00 D-NT1/E-NT2
• End of the Lecture