180 likes | 314 Views
First BlueJ Day Houston, 2006. David J. Barnes University of Kent. Getting started with BlueJ. My personal route to using BlueJ Traditional approaches to teaching Java and OOP The problems How BlueJ addresses the problems. My personal route. Looking for an OO language Blue at SIGCSE 1997
E N D
First BlueJ DayHouston, 2006 David J. Barnes University of Kent
Getting started with BlueJ • My personal route to using BlueJ • Traditional approaches to teaching Java and OOP • The problems • How BlueJ addresses the problems First BlueJ Day, Houston, Texas, 1st March 2006
My personal route • Looking for an OO language • Blue at SIGCSE 1997 • Java by decree • Objects early via the command line. • Prentice-Hall textbook in 2000 First BlueJ Day, Houston, Texas, 1st March 2006
Traditional approaches to teaching Java • Strong influence of procedural programming • Heavy dependence on textbooks. • ‘Hello world’ • GUI-based First BlueJ Day, Houston, Texas, 1st March 2006
Hello World A necessary starting point? public class Hello { public static void main(String[] args){ System.out.println("Hello, world");} } First BlueJ Day, Houston, Texas, 1st March 2006
Text output 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"); } } First BlueJ Day, Houston, Texas, 1st March 2006
Text input and output import java.util.Scanner; public class Square { public static void main(String[] args) { Scanner reader = new Scanner(System.in); System.out.print("Input a number: "); int number = reader.nextInt(); System.out.println(number + " squared is " + (number * number)); } } First BlueJ Day, Houston, Texas, 1st March 2006
Classes to wrap functions Data Fields sqMeters Methods Conversion: square metres to square yards for a piece of fabric toSqYards readSqMeters displayFabric getDouble displayResult ... First BlueJ Day, Houston, Texas, 1st March 2006
GUIs import java.awt.*; public class Message extends Frame { Font f; public Message() { f = new Font("SansSerif", Font.BOLD, 24); setBackground(Color.yellow); setSize(400, 150); setVisible(true); } public void paint(Graphics g) { g.setFont(f); g.setColor(Color.blue); g.drawString("Welcome to Java", 100, 100); } } First BlueJ Day, Houston, Texas, 1st March 2006
GUIs (continued) public class FirstApp extends wheel.users.Frame { private wheels.users.Ellipse _ellipse; public FirstApp() { _ellipse = new wheels.users.Ellipse(); } // magic to let the FirstApp execute public static void main(String[] args) { FirstApp app = new FirstApp(); } } First BlueJ Day, Houston, Texas, 1st March 2006
The problems • Java’s main method is a requirement. • Traditional (procedural) curricula exert a strong influence. • GUI-based examples are attractive, but often carry a lot of baggage. First BlueJ Day, Houston, Texas, 1st March 2006
What I would like to teach • Classes and objects from day 1 • Object fundamentals • state • behaviour • multiplicity • independence • Let students experience objects • Emphasise modelling First BlueJ Day, Houston, Texas, 1st March 2006
Avoiding the problems • Jump start • Don't use main • Don't start with I/O • Beware the complexities of GUIs • custom libraries may have potential • Pick early examples very carefully • avoid simply converting old examples First BlueJ Day, Houston, Texas, 1st March 2006
What does BlueJ have to offer? • Liberation from a main method • A visual and interactive environment that is simple to use • An environment that supports OO concepts • the opportunity to experience objects • access to object state and behaviour First BlueJ Day, Houston, Texas, 1st March 2006
Using BlueJ – first steps Shapes and Pictures First BlueJ Day, Houston, Texas, 1st March 2006
Next steps • Avoid teaching BlueJ • BlueJ is a means to support OO teaching. • Choose examples that illustrate key concepts • Beware of falling back into old ways • Avoid the completeness trap First BlueJ Day, Houston, Texas, 1st March 2006
Next steps (continued) • Don't be afraid to use 'large' examples • Encourage students to read code • Apprenticeship is appropriate • Use sensible examples • Avoid giving them a blank screen • Design is hard • Syntax can be a stumbling block First BlueJ Day, Houston, Texas, 1st March 2006
Summary • Teaching proper OO may require a radical rethink of material • BlueJ provides excellent support for a truly OO curriculum • OO is possible from day 1 – ‘objects first’ First BlueJ Day, Houston, Texas, 1st March 2006