420 likes | 508 Views
A course in Java Programming for CS Educators. Dr Matthew Montebello Depratment of Artificial Departent Faculty of ICT – University of Malta matthew.montebello@um.edu.mt. Schedule. An I ntroduction to Java. Java Basic Building Blocks . Java Advanced Building Blocks .
E N D
A course inJava Programming for CS Educators CSA 3210 Agent Technology Dr Matthew Montebello Depratment of Artificial Departent Faculty of ICT – University of Malta matthew.montebello@um.edu.mt
Schedule • An Introduction to Java. • Java Basic Building Blocks. • Java Advanced Building Blocks. • Conditional Statements. • Iterative Statements. • The Class and Objects. • Methods, encapsulation and static methods. • Arrays and Strings. • Inheritance and Polymorphism. • Exceptions. • Streams and Files. • Collections, DataStructures and Algorithms. • The Graphical User Interface. 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
Course Textbooks Java Programming for CS Educators 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 2 A Practical Introduction Using BlueJ, Fourth Edition, Pearson International Edition, ISBN: 0-13-700562-8
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
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
Some insights … public class Hello { public static void main(String[] args){System.out.println(“Hello, world”);} } Topic 1: An Introduction to Java
… and printing text 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 verse 2. Write a Java class that prints the following design... Topic 1: An Introduction to Java
… and nice GUIs 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); } } Topic 1: An Introduction to Java
… and inputting text 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)); } } Topic 1: An Introduction to Java
So why are things like this? • 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? Topic 1: An Introduction to Java
Initial suggestions … • Objects first • Jump start • Don’t use “main” • Don’t start with I/O (GUIs, applets, text I/O) • Don’t convert old examples • Teach programming, not a programming language Topic 1: An Introduction to Java
a) Objects first … • Start with key issues:Objects, classes, methods • State and behaviour • Almost universally accepted, but: not easy Topic 1: An Introduction to Java
b) Jump start • Don’t get students bored with detail at the start • Start doing something! • Experiment with objects before writing objects. Topic 1: An Introduction to Java
c) Don’t use “main” • What has main got to do with objects? - Nothing! public class Hello { public static void main(String[] args){ System.out.println(“Hello, world”);} } Topic 1: An Introduction to Java
d) Don’t start with I/O • 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…? Topic 1: An Introduction to Java
e) Don’t convert your old examples • Examples are (or should be) handpicked to illustrate key points • Examples from procedural languages do not illustrate concepts of object orientation Topic 1: An Introduction to Java
f) Teach programming, not a programming language • Don’t teach Java, teach OOP! • Don’t teach OOP, teach programming! • Don’t teach programming, teach problem solving! Topic 1: An Introduction to Java
Examples Shapes and Pictures Topic 1: An Introduction to Java
Let’s talk Java • 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? Topic 1: An Introduction to Java
Java dynamics Source javac bytecode java Traditional compilation consisted of: Source code Object code Executable code compiler linker Topic 1: An Introduction to Java
So what’s cool about Java? • 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. Topic 1: An Introduction to Java
More cool Java stuff… • 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. Topic 1: An Introduction to Java
Back to Java education… …and some more suggestions… • Key issues first • Read code • Use “large” projects • Don’t start with a blank screen • Do sensible things • Prepare for maintenance Topic 1: An Introduction to Java
a) Key issues first • Choose examples to illustrate key issues first • Don’t get stuck in detail • Avoid the completeness trap! Topic 1: An Introduction to Java
b) Read code • Make students read code! (read before write) • Show many examples • Make sure all examples are well written (and worth reading) Topic 1: An Introduction to Java
c) Use “large” projects • Don’t start with small examples - they don’t have structure • Use realistic context • Concentrate on object interaction Topic 1: An Introduction to Java
d) Don’t start with a blank screen • Starting with a blank screen requires design (or the example is too trivial) • Design is hard • Designing a complete application is an advanced exercise Topic 1: An Introduction to Java
e) Do sensible things • Choose examples that make sense • Don’t make students do things that you wouldn’t do yourself Topic 1: An Introduction to Java
f) Prepare for maintenance • Prepare students for real-life situations: • code maintenance • modification, extension • documentation • using class libraries • reuse Topic 1: An Introduction to Java
Example Typical Bank example Topic 1: An Introduction to Java
More Java talk The JDK is the collection of Java packages and utilities to develop programs • 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 … Topic 1: An Introduction to Java
Java IDE • 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 … Topic 1: An Introduction to Java
Implications to Java education… …final suggestions • Stick to 1 IDE • Discuss application structure • Open/closed exercises • Create ownership • Apprentice approach • Eliminate misconceptions Topic 1: An Introduction to Java
a) There shall be only 1 … IDE • 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
b) Discuss structure • OO-modelling • Relationships of classes • Coupling and cohesion • Patterns and inheritance • Reusability issues Topic 1: An Introduction to Java
c) Open/closed exercises • 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
d) Create ownership • 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
e) Apprentice approach • Let students observe what you are doing • See teacher in action • Learn by imitation Topic 1: An Introduction to Java
f) Eliminate Misconceptions • 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
Tasks for this week • 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