A course in Java Programming for CS Educators
description
Transcript of A course in Java Programming for CS Educators
![Page 1: A course in Java Programming for CS Educators](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/1.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/2.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/3.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/4.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/5.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/6.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/7.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/8.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/9.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/10.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/11.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/12.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/13.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/14.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/15.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/16.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/17.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/18.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/19.jpg)
Examples
Shapes and Pictures
Topic 1: An Introduction to Java
![Page 20: A course in Java Programming for CS Educators](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/20.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/21.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/22.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/23.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/24.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/25.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/26.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/27.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/28.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/29.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/30.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/31.jpg)
Example
Typical Bank example
Topic 1: An Introduction to Java
![Page 32: A course in Java Programming for CS Educators](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/32.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/33.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/34.jpg)
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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/35.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/36.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/37.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/38.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/39.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/40.jpg)
• 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](https://reader036.fdocuments.net/reader036/viewer/2022081515/56813ffe550346895dab2f81/html5/thumbnails/41.jpg)
• 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