a course in java programming for cs educators

41
CSA 3210 Agent Technology A course in Java Programming for CS Educators Dr Matthew Montebello Depratment of Artificial Departent Faculty of ICT – University of Malta [email protected]

Upload: vilina

Post on 09-Jan-2016

21 views

Category:

Documents


1 download

DESCRIPTION

A course in Java Programming for CS Educators. Dr Matthew Montebello Depratment of Artificial Departent Faculty of ICT – University of Malta [email protected]. Schedule. An I ntroduction to Java. Java Basic Building Blocks . Java Advanced Building Blocks . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: A course in Java Programming  for  CS Educators

CSA 3210 Agent Technology

A course inJava Programming

for CS Educators

Dr Matthew MontebelloDepratment of Artificial DepartentFaculty of ICT – University of [email protected]

Page 2: A course in Java Programming  for  CS Educators

Schedule1. An Introduction to Java.2. Java Basic Building Blocks.3. Java Advanced Building Blocks.4. Conditional Statements.5. Iterative Statements.6. The Class and Objects.7. Methods, encapsulation and static methods.8. Arrays and Strings.9. Inheritance and Polymorphism.10. Exceptions.11. Streams and Files.12. Collections, DataStructures and Algorithms.13. The Graphical User Interface.

Java Programming for CS Educators

Page 3: A course in Java Programming  for  CS Educators

What is this course about …

• A thorough induction into the Java Programming Language … short history, philosophy, methodology.

• Techniques and approaches on how to best introduce the Java Programming Language to CS students.

• To build a network of Java resources for CS teachers in order to share experiences, share resources and assist each other’s pedagogical needs.

Java Programming for CS Educators

Page 4: A course in Java Programming  for  CS Educators

Java Programming for CS Educators

Course Textbooks

Herbert Schildt,

Java 2: Complete Reference, Fifth Edition,McGraw Hill / Osborne,

ISBN: 0-07-222420-7

David Barnes & Michael Kölling,

Objects First with Java 2A Practical Introduction Using BlueJ, Fourth Edition,

Pearson International Edition,

ISBN: 0-13-700562-8

Page 5: A course in Java Programming  for  CS Educators

Topic 1: An Introduction to Java

In this session:

• Introductions & few thoughts;

• Insight into Java Dynamics;

• Fundamentals of Object-Oriented Principles;

• A Development Kit for Java – JDK;

• An Environment to Integrate Development – IDE;

• Interfaces for Application Programs – API;

• Introduction to the resource network – J4T;

• First Java steps;

• Start practicing … and do not STOP.

Java Programming for CS Educators

Page 6: A course in Java Programming  for  CS Educators

Introductions

• Who are you?

• What/where do you teach?

• What is your experience with Java teaching?

• What do you expect from these lectures?

• What problems do you experience in your teaching?

Topic 1: An Introduction to Java

Page 7: A course in Java Programming  for  CS Educators

Some insights …

public class Hello

{

public static void main(String[] args){ System.out.println(“Hello, world”);}

}

Topic 1: An Introduction to Java

Page 8: A course in Java Programming  for  CS Educators

public class OldMacDonald {

public static void main(String[] args) {

System.out.println(“Old MacDonald had a farm”);

System.out.println(“E I E I O”);

System.out.println(“and on his farm he had a duck”);

System.out.println(“E I E I O”);

System.out.println(“With a quak quak here”);

System.out.println(“And a quak quak there”);

System.out.println(“Here a quak, there a quak”); System.out.println(“Everywhere a quak quak”);

System.out.println(“Old MacDonald had a farm”);

System.out.println(“E I E I O”);

} }

1. Write a Java class that prints the second verse2. Write a Java class that prints the following design...

… and printing text

Topic 1: An Introduction to Java

Page 9: A course in Java Programming  for  CS Educators

import java.awt.*;

public class Message2 extends Frame {

Font f;

public Message2() {

f = new Font(“SansSerif”, Font.BOLD, 24);

setBackground(Color.yellow);

setSize(400, 150);

}

public void paint(Graphics g) {

g.setFont(f); g.setColor(Color.blue);

g.drawString(“Welcome to Java”, 100, 100);

}

public static void main(String[] args) {

Message2 m2 = new Message2();

m2.setVisible(true);

}

}

… and nice GUIs

Topic 1: An Introduction to Java

Page 10: A course in Java Programming  for  CS Educators

import java.io.*;

public class Square

{

public static void main(String[] args) throws Exception

{

BufferedReader reader =

new BufferedReader(

new InputStreamReader(System.in));

System.out.println(“Input a number”);

int number = Integer.parseInt(reader.readline());

System.out.println(number + “ squared is “ +

(number * number));

}

}

… and inputting text

Topic 1: An Introduction to Java

Page 11: A course in Java Programming  for  CS Educators

• It has a lot to do with the Pascal (etc.) heritage.

• Just using a class doesn’t make an OO program.

• Using an OO language requires a proper OO approach.

• So how to get started?

So why are things like this?

Topic 1: An Introduction to Java

Page 12: A course in Java Programming  for  CS Educators

a. Objects firstb. Jump startc. Don’t use “main”d. Don’t start with I/O (GUIs, applets, text

I/O)e. Don’t convert old examplesf. Teach programming, not a programming

language

Initial suggestions …

Topic 1: An Introduction to Java

Page 13: A course in Java Programming  for  CS Educators

• Start with key issues:Objects, classes, methods

• State and behaviour

• Almost universally accepted, but: not easy

a) Objects first …

Topic 1: An Introduction to Java

Page 14: A course in Java Programming  for  CS Educators

• Don’t get students bored with detail at the start

• Start doing something!

• Experiment with objects before writing objects.

b) Jump start

Topic 1: An Introduction to Java

Page 15: A course in Java Programming  for  CS Educators

• What has main got to do with objects? - Nothing!

public class Hello

{

public static void main(String[] args){ System.out.println(“Hello, world”);}

}

c) Don’t use “main”

Topic 1: An Introduction to Java

Page 16: A course in Java Programming  for  CS Educators

• I/O is an undesirable distraction from programming principles

• Text I/O (especially input) is not easy

• Applets are mysterious

• GUIs are complicated

• Custom made libraries…?

d) Don’t start with I/O

Topic 1: An Introduction to Java

Page 17: A course in Java Programming  for  CS Educators

• Examples are (or should be) handpicked to illustrate key points

• Examples from procedural languages do not illustrate concepts of object orientation

e) Don’t convert your old examples

Topic 1: An Introduction to Java

Page 18: A course in Java Programming  for  CS Educators

• Don’t teach Java, teach OOP!

• Don’t teach OOP, teach programming!

• Don’t teach programming, teach problem solving!

f) Teach programming, not

a programming language

Topic 1: An Introduction to Java

Page 19: A course in Java Programming  for  CS Educators

Examples

Shapes and Pictures

Topic 1: An Introduction to Java

Page 20: A course in Java Programming  for  CS Educators

• It derives its syntax from C and the OOP concepts from C++

• C++ was the predominant language until early 90s but lacked:

• Simplicity

• No support for web applications

• Java was conceived by Sun Microsystems in 1991 and called it Oak when created in 1992 … but changed to Java in 1995

• The main idea of Java was to be an OOP independent of the platform … how?

Let’s talk Java

Topic 1: An Introduction to Java

Page 21: A course in Java Programming  for  CS Educators

Java dynamics

Topic 1: An Introduction to Java

Source javac bytecode java

Traditional compilation consisted of:

Source code

Object code

Executable code

compiler

linker

Page 22: A course in Java Programming  for  CS Educators

• Get started quickly: Although the Java programming language is a powerful object-oriented language, it's easy to learn, especially for programmers already familiar with C or C++.

• Write less code: Comparisons of program metrics (class counts, method counts, and so on) suggest that a program written in the Java programming language can be four times smaller than the same program written in C++.

• Write better code: The Java programming language encourages good coding practices, and automatic garbage collection helps you avoid memory leaks. Its object orientation, its JavaBeansTM component architecture, and its wide-ranging, easily extendible API let you reuse existing, tested code and introduce fewer bugs.

So what’s cool about Java?

Topic 1: An Introduction to Java

Page 23: A course in Java Programming  for  CS Educators

• Develop programs more quickly: The Java programming language is simpler than C++, and as such, your development time could be up to twice as fast when writing in it. Your programs will also require fewer lines of code.

• Avoid platform dependencies: You can keep your program portable by avoiding the use of libraries written in other languages.

• Write once, run anywhere: Because applications written in the Java programming language are compiled into machine-independent bytecodes, they run consistently on any Java platform.

• Distribute software more easily: With Java Web Start software, users will be able to launch your applications with a single click of the mouse.

More cool Java stuff…

Topic 1: An Introduction to Java

Page 24: A course in Java Programming  for  CS Educators

a. Key issues first

b. Read code

c. Use “large” projects

d. Don’t start with a blank screen

e. Do sensible things

f. Prepare for maintenance

Back to Java education……and some more suggestions…

Topic 1: An Introduction to Java

Page 25: A course in Java Programming  for  CS Educators

• Choose examples to illustrate key issues first

• Don’t get stuck in detail

• Avoid the completeness trap!

a) Key issues first

Topic 1: An Introduction to Java

Page 26: A course in Java Programming  for  CS Educators

• Make students read code! (read before write)

• Show many examples

• Make sure all examples are well written (and worth reading)

b) Read code

Topic 1: An Introduction to Java

Page 27: A course in Java Programming  for  CS Educators

• Don’t start with small examples - they don’t have structure

• Use realistic context

• Concentrate on object interaction

c) Use “large” projects

Topic 1: An Introduction to Java

Page 28: A course in Java Programming  for  CS Educators

• Starting with a blank screen requires design (or the example is too trivial)

• Design is hard

• Designing a complete application is an advanced exercise

d) Don’t start with a blank screen

Topic 1: An Introduction to Java

Page 29: A course in Java Programming  for  CS Educators

• Choose examples that make sense

• Don’t make students do things that you wouldn’t do yourself

e) Do sensible things

Topic 1: An Introduction to Java

Page 30: A course in Java Programming  for  CS Educators

• Prepare students for real-life situations:– code maintenance

– modification, extension

– documentation

– using class libraries

– reuse

f) Prepare for maintenance

Topic 1: An Introduction to Java

Page 31: A course in Java Programming  for  CS Educators

Example

Typical Bank example

Topic 1: An Introduction to Java

Page 32: A course in Java Programming  for  CS Educators

• Java source can be compiled directly from the CMD window

• By accessing the Java Development Kit (JDK) directly … namely “javac” & “java”

• Even better and friendly …

More Java talk

Topic 1: An Introduction to Java

The JDK is the collection of

Java packages and utilities

to develop programs

Page 33: A course in Java Programming  for  CS Educators

• An IDE is an Integrated Development Environment to assist the developer focus on the application itself rather than the Java dynamics.

• Some notorious Java IDEs are:– BlueJ– NetBeans– TextPad– Eclipse– JCreator– Others …

Java IDE

Topic 1: An Introduction to Java

Page 34: A course in Java Programming  for  CS Educators

a. Stick to 1 IDE

b. Discuss application structure

c. Open/closed exercises

d. Create ownership

e. Apprentice approach

f. Eliminate misconceptions

Topic 1: An Introduction to Java

Implications to Java education… …final suggestions

Page 35: A course in Java Programming  for  CS Educators

• Most IDEs are free and when students comprehend the use of IDEs they can venture to

• You can use Editors like JCreator and TextPad for the first lessons that deal with language structures and variables

• Editors like BlueJ give the OOP view of Java for advanced lessons that deal with advanced concepts like inheritance

• Advanced editors like NetBeans and Eclipse can be used in projects for creating user interfaces and interactive debugging

Topic 1: An Introduction to Java

a) There shall be only 1 … IDE

Page 36: A course in Java Programming  for  CS Educators

• OO-modelling

• Relationships of classes

• Coupling and cohesion

• Patterns and inheritance

• Reusability issues

Topic 1: An Introduction to Java

b) Discuss structure

Page 37: A course in Java Programming  for  CS Educators

• Make exercises that are closed so students know exactly what is expected of them (and when they are done), and

• Make exercises that are open so each student can adapt them to his/her own level of knowledge, expertise and ambition

Topic 1: An Introduction to Java

c) Open/closed exercises

Page 38: A course in Java Programming  for  CS Educators

• Create your exercises and programming projects in such a way that the students take ownership

• Students then will– work harder

– have more fun

– learn much, much more...

Topic 1: An Introduction to Java

d) Create ownership

Page 39: A course in Java Programming  for  CS Educators

• Let students observe what you are doing

• See teacher in action

• Learn by imitation

Topic 1: An Introduction to Java

e) Apprentice approach

Page 40: A course in Java Programming  for  CS Educators

• Java is a language for writing web pages, just like HTML

• Java and Javascript (JS) are the same

• Java is the language of the future and will solve all the problems

• Java is the fastest language

• Java produces a .exe file– Apart from the .java and .class it uses compressed

package file .jar that is executable– Additionally Webstart allows users to launch and

manage the application from their browser, email, or desktop.

Topic 1: An Introduction to Java

f) Eliminate Misconceptions

Page 41: A course in Java Programming  for  CS Educators

• Go through the course WIKI• Download the JDK and install• Download and install an IDE• Create a program to test both installations • Venture into different tutorials• Experiment with different IDEs• Search for answers if in difficulty• Post queries on the Wiki• Discuss common problems• Share ideas, resources, etc …

Topic 1: An Introduction to Java

Tasks for this week