Teaching programming at Introductory Level - PowerPoint PPT Presentation

About This Presentation
Title:

Teaching programming at Introductory Level

Description:

... to create similar applications in the first year (at a high level of abstraction) ... the required level of abstraction to teach important concepts but ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 30
Provided by: char159
Category:

less

Transcript and Presenter's Notes

Title: Teaching programming at Introductory Level


1
Teaching programming at Introductory Level
  • Why has introductory computer science courses
    become so advanced in terms of conceptual
    materials presented Roberts04a?
  • Keeping a generation that has grown up with XBox,
    PSP, Mobile Phone Games interested in our
    courses requires a different approach.
  • How to get them interested in computer science?

2
How institutions attract students to CS(ACM
report)
  • By allowing them to create similar applications
    in the first year (at a high level of
    abstraction)
  • Graphics
  • Events and concurrent programming
  • Distributed objects etc.
  • Convince students at the end of first year
  • Computing is Cool! Programming is Fun!
  • I can do real life applications (Adam Boas)
  • Leaving in-depth matters to be covered later
  • Caching, Transactions, Building Components,
    Optimization
  • Sydney uni spends much of first year programming
    and design
  • Institutions forced to adopt appropriate
    paradigms
  • Java has proved to be suitable but not without
    problems

3
Role of ACM Java Task Force
  • Java is widely taught as the first language. Most
    have moved from whether Java to if Java then
    how ?
  • Despite increasing usage satisfaction is mixed.
    Problems common to all modern languages
  • Complexity associated with huge API
  • Instability changing API, tools
  • ACM Task Force formed to review the language,
    APIs, and tools from the perspective of
    introductory computing education
  • ACM Task Force to develop a stable collection of
    pedagogical resources including a set of new
    packages. Feedback was invited.

4
What are the problems?
  • Modern O-O languages caters to many demands
    trying to meet user needs
  • As a result the number of programming details a
    new user has to must master has increased greatly
    (compare with Pascal)
  • Next program shows the number of constructs that
    must be learnt even before they can get a simple
    program to work using Java (earlier version).
  • Chaining
  • try catch block
  • Converting String to double
  • Use of special class for formatting output

5
  • import java.io.
  • import java.text.
  • public class Add1
  • static public void main(String args)
  • InputStreamReader stdin new
    InputStreamReader(System.in)
  • BufferedReader console new
    BufferedReader(stdin)
  • double a 0,b 0, c
  • String s1,s2
  • try
  • System.out.print("Enter value for a ")
  • s1 console.readLine()
  • a Double.parseDouble(s1)
  • System.out.print("Enter value for b ")
  • s2 console.readLine()
  • b Double.parseDouble(s2)
  • catch(IOException ioex)

Try catch() Needed because readLine() may
throw an exception Though it will not happens
when reading from keyboard)
BufferedReader Cannot read double directly
6
Equivalent program in C
  • include ltstdio.hgt
  • int main(int argc, charargv)
  • int a,b,c
  • printf(Enter values for a and b")
  • scanf("d ",a)
  • scanf("d",b)
  • c ab
  • printf(d d d\n",a,b,c)

7
How can J2SE 5 help?
  • import java.util.Scanner
  • public class Add2
  • static public void main(String args)
  • Scanner console new Scanner(System.in)
  • double a,b, c
  • System.out.print("Enter value for a and b
    ")
  • a console.nextDouble()
  • b console.nextDouble()
  • c a b
  • System.out.printf("f f .2f",a,b,c)

try ... catch() avoided as no checked
exception thrown by Scanner methods
8
What are some new J2SE 5 features?
  • Scanner class
  • Formatted output
  • Using/Creating Generic classes
  • Autoboxing
  • Enhanced for loop
  • Type safe enum
  • Variable arguments
  • Static import

9
Using Generic classes
  • All JCF classes can be used as generic classes
  • For example, an ArrayList instance can be created
    to store only Account objects by passing the type
    (Account) to the constructor and the reference as
    in
  • ArrayListltAccountgt accList
  • new ArrayListltAccountgt()
  • Similarly to map a customer name (String) to
    Account objects we can use
  • HashMapltString,Accountgt hashMap
  • new HashMapltString,Accountgt()

10
Example using ArrayList
  • import java.util.
  • class Account
  • class Customer
  • public class TestGenericArray
  • public static void main(String args)
  • ArrayListltAccountgt accList new
    ArrayListltAccountgt()
  • accList.add( new Account() )
  • accList.add( new Account() )
  • ArrayListltCustomergt custList new
    ArrayListltCustomergt()
  • custList.add( new Customer() )
  • custList.add( new Customer() )
  • // custList.add( new Account() )
  • System.out.println("Entries in accList "
    accList)
  • System.out.println("Entries in custList "
    custList)

11
Autoboxing
  • Box/Unbox
  • Wrap a primitive into a class to be used as an
    object and extract primitive value from object
    manually
  • AutoBox/AutoUnbox
  • Compiler does the work

Before JDK 1.5
ArrayList a new ArrayList(10) int num
10 a.add(new Integer(num)) int x
((Integer)a.get(0)).intValue()
System.out.println(x)
With JDK 1.5
ArrayListltIntegergt a new ArrayListltIntegergt(10)
int num 10 a.add(num) int x
a.get(0) System.out.println(x)
12
Enhanced for loop
  • Iterations are made easy
  • Before (iterating through a set)
  • Iterator iterator set.iterator()
  • while ( iterator.hasNext())
  • System.out.print(iterator.next() " ")
  • With JDK 1.5
  • for (String s set )
  • System.out.print(s " ")

13
Variable Arguments
  • Java 1.5 allows vararg specification allowing any
    number of arguments
  • It is of the form
  • int args
  • String messages
  • You can have only one vararg in method
    specifiction and it must be the last.

14
class Utility / Returns the largent
of any number of int values / public
static int max(int... arg) if (
arg.length 0) System.out.println("Erro
r Max of zero values")
System.exit(0) int largest
arg0 for (int i1 iltarg.length i)
if (argi gt largest ) largest
argi return largest
Example Variable Arguments
public class TestUtility public static void
main(String args) int max1
Utility.max(10,40,30) int max2
Utility.max(10,40,30,60)
System.out.println("max1 " max1 " max2 "
max2)
15
Type Safe enums
  • Like C enum
  • Type Safe
  • Can be printed

import java.util. public class Test3 enum
WorkDay MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY
public static void main(String args)
WorkDay meetingDay WorkDay.THURSDAY
System.out.println(meetingDay)
16
Static import
  • By adding a import statement for static method
    you can avoid having to precede the method with
    class name.
  • import static java.lang.Character.toUppercase
  • toUpperCase(firstCharacter)
  • // instead of Character.toUpperCase(firstCharacter
    )

17
Remaining problems teaching/learning(according
to Java Task Force)
  • Scale
  • Instability (methods deprecated, new models)
  • Static methods
  • Exceptions
  • Conceptual difficulty of Graphics model
  • Writing event driven code
  • due to event model
  • due to difficulty of concurrent programming

18
Java Task Force Solutions
  • Graphics Package
  • Uses an extensible hierarchy of grapical objects
    rooted at GObject

GObject
  • Program Package
  • Uses an hierarchy of Program classes
    (ConsoleProgram, DialogProgram, GraphicsProgram)
  • Others

19
ACM approach
  • Pros
  • Helps avoid overloading student with details
  • Makes available pedagogical resources
  • Beta version of JTF classes released
  • Cons
  • Are we adding to the scale of complexity?
  • Will will be chasing moving target (new features
    in Java creates new problems)
  • Can all staff agree on these or other classes
    (such as developed by IBM) ?
  • Availability of resources

20
Our challenge
  • Changing profile of students
  • Students with high enter scores are usually
    self-motivated
  • Average students are willing to try
  • If the problem is perceived to be interesting
  • If it is not too difficult to get started
  • Average students need more guidance and feedback

21
Our Approach thus far
  • Use of helper classes / Container classes to hide
    complexity in the initial stages
  • ConsoleReader class
  • Date class
  • From this year JCF from first semester
  • Regular Assessments (9 excluding exam)
  • Demos, WebLearn tests, MS-Test, Assignments (3)

22
Our Approach thus far
Use some Animation, Games, Robot Control,
Aircraft Simulation etc to motivate the students
using a layered Approach.
Layered Approach
Use given Graphical objects (emphasis on
algorithms)
Student extend given Graphical objects (Emphasis
OO Progr.)
Students use Swing classes Emphasis GUI
Students use Threads, sockets, MVC, RMI to
design apps
23
How can our JTF help ?
  • Study the ACM JTF classes and recommend adoption
    (or otherwise)
  • Assignments form very important part of student
    learning and Java allows us to provide the
    required level of abstraction to teach important
    concepts but it takes time.
  • Develop and share pedagogical resources.
  • Invite speakers from Industry and get student
    feedback. Apr 4 speaker from Sun.
  • Decide what Java features needs to be taught
    the depth.
  • Avoid duplication in electives. Currently no Java
    course in school (only used as a vehicle)

24
Discussion
25
A Parameterized Library class
The generic library class has a single type
parameter E, allowing it to store objects of type
E.
Using parameterized type E
  • import java.util.
  • class LibraryltEgt
  • private ArrayListltEgt resources new
    ArrayListltEgt()
  • public void add(E x)
  • resources.add(x)
  • public E retrieveLast()
  • int size resources.size()
  • if (size gt 0)
  • return resources.get(size-1)
  • return null

Uses the services of parameterized ArrayList
reference
Constructor
Allows any object of type E to be added
objects retrieved are of type E
26
Converting a class to Generic class
import java.util. class Library private
ArrayList resources new
ArrayList() public void add(Media x)
resources.add(x) public Media
retrieveLast() int size
resources.size() if (size gt 0)
return (Media) resources.get(size-1)
return null
public class TestLibrary public static void
main(String args) Library myBooks new
Library() myBooks.add(new Book())
myBooks.add(new Book()) // myBooks.add(new
Video()) Book lastBook (Book)
myBooks.retrieveLast() lastBook.print()

For storing Book objects
Cannot detect at compile time resulting in
runtime error when retrieving
Explicit cast needed
27
Using the Parameterized Library
  • When using the parameterized (generic) Library
    class a type must be passes to the type parameter
    E.
  • Note the element extracted from the parameterized
    Library need not be cast.
  • public class TestLibrary
  • public static void main(String args)
  • LibraryltBookgt myBooks new
    LibraryltBookgt()
  • myBooks.add(new Book())
  • myBooks.add(new Book())
  • Book lastBook myBooks.retrieveLast()
  • lastBook.print()
  • LibraryltVideogt myVideos new
    LibraryltVideogt()
  • myVideos.add(new Video())
  • myVideos.add(new Video())
  • myVideos.add(new Video())
  • Video lastVideo myVideos.retrieveLast()
  • lastVideo.print()

Creating a Library to store Book objects
Creating a Library to store Video objects
No casting needed
28
Things to take note when creating and using a
Parameterized classes
  • Primitive types cannot be passed as parameters.
  • ArrayListltIntegergt numbers new
    ArrayListltIntegergt()
  • ArrayListltintgt numbers new ArrayListltintgt()
  • When a class uses parameterized type T, the type
    parameter T can be used as a reference but not
    for constructing.
  • T object
  • T a
  • new T()
  • new T10
  • The parameter can be used for casting
  • E e2 (E) new Object()
  • E e3 (E)new Object10
  • Generic classes cannot be array base type
  • LibraryltVideogt videoLibs new
    LibraryltVideogt10
  • ArrayListltVideogt vidLibs new
    ArrayListltVideogt10

29
References
  • Roberts04a
  • The dream of a common language The search for
    simplicity and stability in computer science
    education. Proceedings of the Thirty-Fifth SIGCSE
    Technical Symposium on Computer Science
    Education, Norfolk, VA, March 2004.    
Write a Comment
User Comments (0)
About PowerShow.com