COIT 11222 - Visual ProgrammingAuthor(s): Mike O - PowerPoint PPT Presentation

1 / 88
About This Presentation
Title:

COIT 11222 - Visual ProgrammingAuthor(s): Mike O

Description:

Title: PowerPoint Presentation Last modified by: omalleym Created Date: 1/1/1601 12:00:00 AM Document presentation format: On-screen Show (4:3) Other titles – PowerPoint PPT presentation

Number of Views:490
Avg rating:3.0/5.0
Slides: 89
Provided by: webfuseCq4
Category:

less

Transcript and Presenter's Notes

Title: COIT 11222 - Visual ProgrammingAuthor(s): Mike O


1
COIT 11222 Visual Programming
  • Lecture Week 1
  • References
  • Java Programming - Complete
  • Concepts and Techniques,
  • 3rd Edition, Shelly Cashman et al.

2
Topics For This Week
  • Course overview assessment, course profile, text
    book, how to get help, how to pass / fail the
    course, etc
  • Introduction to Java
  • Basic Java programming.
  • A Simple "Hello World" Program
  • TextPad Hints and Tips
  • Debugging Skills the basics
  • Program Development Strategy

3
Lecturer Introduction
  • Lecturers please insert your own slide(s) here
    to introduce yourself.
  • Please include your name, email, phone, campus /
    location, etc.

4
About this Course
  • This course is called "Visual Programming".
  • So, it is a computer programming course.
  • The emphasis is on designing and writing Java
    programs.
  • The only way to become a good programmer is to
    write lots of code and explore / solve a wide
    range of problems.
  • Even if you hate programming, you can still turn
    this around and achieve high results with the
    right attitude and a good work ethic.
  • Start by getting in the habit of doing the "How
    to Pass This Course" activities each week see
    below.
  • CQU lecturers and tutors are here to help - but
    the emphasis is on you putting in the required
    effort.

5
Course WEB Page
  • Navigate to the course web page from here
  • http//webfuse.cqu.edu.au/Courses/
  • enter the course code (COIT11222), the Year, and
    Period (term), and then click the "GO" button.
  • Please Note All students are required to check
    the course web page often during term. e.g. at
    least once each week.

6
Lecturers / Tutors
  • To find out who the lecturers / tutors are at
    your local campus (if applicable), please visit
    the STAFF section of the Course WEB page for the
    relevant course / term / year.
  • To find out who the Course Coordinator is, please
    visit the STAFF section of the Course WEB page
    for the relevant course / term / year.

7
Email Subject Line
  • Make sure that you ALWAYS use a very meaningful
    email subject line on ALL emails that you send.
  • At the very least, the email subject line should
    include the course code and a brief but specific
    summary of what the email is about.
  • For example, these are good email subject lines
  • COIT 11222 Assignment 2 Array Help Needed !!
  • COIT 11222 Week 2, Q2 Please Help !!
  • WARNING Failure to do this may result in the
    email being delayed, deleted, ignored, or lost in
    the sea of SPAM email that we all receive.

8
Course Profile
  • Available on the Course WEB Page.
  • Contains study schedule, course information,
    assignment and assessment information, and so on.
  • Please Note All students should have a good
    read of this in Week 1.

9
Course Mailing List
  • All students are expected to subscribe to the
    course mailing list, and monitor the mailing list
    regularly during term for useful information,
    hints and tips.
  • See the Course Profile (on Course WEB Page) for
    details.
  • WARNING
  • Do NOT send / submit any assignment related code
    to the course mailing list !
  • If you want to get help with your assignment
    code, then email it by direct email to your local
    campus lecturer / tutor (if available /
    applicable), or, the Course Coordinator (if you
    do not have a local campus lecturer / tutor).

10
Study Guide
  • The Study Guide for this course is available
    electronically on the Course WEB page.
  • Please Note
  • The Study Guide for this course is simply a very
    brief summary of what is being studied.
  • It is NOT a replacement or alternative for a text
    book or the lecture material.

11
Prescribed Text Book
  • There is NO Prescribed Text Book in this course.
  • Why
  • After 2008-T1 redevelopment of lecture and
    tutorial material, students complained they
    didnt need / use old prescribed text book.
  • To date, no replacement prescribed text book has
    been found that is ideal for this course.
  • No prescribed text book gt not possible to list
    the sections that are relevant each week (depends
    on which book / edition you use).

12
Reference Text Books
  • A range of optional" reference text books are
    suggested (see page 1 of Course Profile).
  • Buy or borrow any of these, or use whatever other
    Java text book you find useful.
  • Hint Borrow / trial a few before you buy.
  • Further reading (highly recommended), use the
    index and table of contents of whatever text book
    you are using to look up the information.
  • Additional questions (highly recommended),
    then select relevant end-of-chapter questions
    from whatever text book you are using.

13
Assignments Model Solutions
  • Assignment Specifications are in the Course
    Profile (on Course WEB Page).
  • Assignment Marking Guides, hints and tips, etc
    are (as required) available on the Course WEB
    Page.
  • Assignment 1s Model Solution will be distributed
    approximately 1 week prior to the due date for
    Assignment 2.
  • Make sure you submit your Assignment 1 prior to
    the release of the Assignment 1 Model Solution,
    otherwise you will receive 0 marks (and your
    assignment will be returned unmarked).

14
Assignments Model Solutions
  • Assignment 2 Model Solution is NOT made available
    to students.
  • Make sure you submit your Assignment 2 before 12
    noon on Friday of Exam Week (Week 14) otherwise
    you will receive 0 marks (and your assignment
    will be returned unmarked).

15
Plagiarism Warning
  • Extensive plagiarism checks are conducted in this
    course before and after the exam period.
  • As stated in the Marking Guides for all
    Assignments in this course
  • All marks are provisional and may be changed
    without notice if any adverse factors (such as
    plagiarism) are discovered at any time in the
    future.
  • If you cheat or plagiarise work, then penalties
    will apply (see CQUniversitys Plagiarism Policy).

16
Plagiarism Warning (cont)
  • We do look for similarities between assignments
    while marking.
  • We do regularly scan for plagiarism attempts via
    on-line auction web sites (such as Rent-A-Coder,
    Script Lance, Get-A-Freelancer, etc) and various
    other web sites.
  • We regularly receive tip-offs from other students
    and from visitors to various web sites.
  • We do conduct extensive and rigorous end-of-term
    term plagiarism checks.
  • We do take action and change results - even after
    exam week - if significant plagiarism is found.
  • Penalties may range from ZERO for the assignment
    to exclusion from CQU.

17
Plagiarism Warning (cont)
  • If you cheat, the chances are you will be caught
    sooner or later.
  • A road that looks easy often isn't.
  • If you cheat on the assignments, then you will
    probably find the exam very difficult.
  • Make sure your assignments are 100 your own work.

18
Lecture and Tutorial Material
  • Available on the Course WEB Page.
  • All students are expected to read the relevant
    lecture material each week (and back this up with
    additional text book reading).
  • All students are expected to complete all
    tutorial questions each week, and also explore
    additional questions at the end of the relevant
    text book chapters.
  • If you fail to do this, then you will have a very
    difficult time with the assessment in this
    course. (More on this later )

19
On successful completion of this course, you
should be able to
  • Read and interpret JAVA statements, syntax, and
    programs that use the techniques covered in this
    course.
  • Demonstrate awareness regarding the applicability
    of JAVA as a problem solving tool.
  • Interpret and analyse user requirements in
    tutorial questions and assignment specifications
    and develop working solutions for these
    requirements.
  • Design reasonably efficient, maintainable,
    understandable, well written, and well-commented
    software solutions using Object Oriented
    Programming (OOP) techniques up to the level
    covered in the course.

20
On successful completion (cont)
  • Design, develop and debug JAVA programs using
    Graphical User Interface (GUI) and other elements
    up to the level covered in the course.
  • Test and verify that a JAVA program works
    correctly.

21
Topics Covered in this Course
  • Java basics declarations, loops, conditional
    statements, arrays, etc.
  • Designing, developing, debugging, and testing
    programs in Java
  • Java Console Programs, Applets, and Applications
  • User I/O, Dialogs
  • GUI Development with AWT
  • Layout Managers

22
Software Java Compiler, Editor, etc
  • The software required for this course
  • Java Software Development Kit (SDK)
  • TextPad
  • Freely downloadable from the Internet and from
    the Course WEB Page.
  • See the Course Profile (on Course WEB Page) and
    Course WEB Page (Resources section) for
    downloads.
  • Installation instructions
  • Install the Java SDK first
  • Then install TextPad.
  • All students should install all software required
    for this course on their PCs and verify that it
    works in Week 1.
  • Contact the Course Coordinator if you have any
    problems.

23
Assessment
  • Assessment Item 1 On-Line Quiz
  • Due Friday of Week 3, Weighting 5
  • Assessment Item 2 Assignment 1 Java Program
  • Due Friday of Week 6, Weighting 15
  • Assessment Item 3 Assignment 2 Java Program
  • Due Friday of Week 11, Weighting 15
  • Assessment Item 4 Exam
  • Week 13 / 14 in Exam period, 3 hours, Open Book
  • Weighting 65
  • See Course Profile for further details (available
    on Course WEB page)

24
Getting Help
  • If you have a problem / issue / question and you
    cannot resolve it with a text book / the lecture
    material, then you should do the following
  • Contact your local campus lecturer / tutor (if
    available / applicable) by email or in class or a
    visit to their office.
  • If they cannot provide the help that you need,
    then contact the Course Coordinator via phone or
    email (email is usually best) and they will help.
  • Please Note AIC students should contact and use
    staff at their local campus for assistance with
    their studies. AIC students should only contact
    the Course Coordinator as a last resort, or to
    lodge a complaint.

25
Getting Help (cont)
  • WARNING
  • Do NOT send / submit any assignment related code
    to the course mailing list !
  • If you want to get help with your assignment
    code, then email it by direct email (not to the
    course mailing list) to
  • your local campus lecturer / tutor (if available
    / applicable), or,
  • the Course Coordinator (if you do not have a
    local campus lecturer / tutor).

26
Pass Criteria for this Course
  • To obtain a grade of Pass or higher in this
    course a student must
  • Score at least 50 of the overall marks for the
    course, AND,
  • Score at least 30 / 65 in the exam.
  • Failure to achieve both of these success criteria
    will result in some form of Fail grade in this
    course.
  • You do NOT have to pass every assessment item to
    PASS overall !

27
Student Work Commitment
  • The suggested study commitment for students in
    this course is a
  • Minimum of twelve (12) hours per week !!
  • If you are struggling or fall behind then you may
    need to do a lot more than this.

28
Student Work Commitment (cont)
  • For internal students, the bare minimum in this
    course is attending the lectures and the
    tutorials each week.
  • BUT, you CANNOT succeed in this course by doing
    the bare minimum.
  • 12 hours per week is the work commitment expected
    of students - NOT 3-4 hours per week.
  • If you let things slide for a few weeks, then you
    will need to do a lot more than 12 hours per week
    (for at least several weeks) to catch up.

29
Student Work Commitment (cont)
  • Please Note Spending dozens of hours "spinning
    your wheels" and getting nowhere with an
    assignment or problem does NOT count as
    productive work.
  • It simply indicates that you haven't done the
    work or sought help when you should have, and you
    are therefore wasting valuable time.
  • If students do the work - required reading,
    tutorial questions, end of chapter programming
    questions, etc - each week then you should expect
    to find the assignments quite easy and be able to
    finish them fairly quickly. e.g. Less than 10
    hours of work, and probably less than 5.

30
Student Work Commitment (cont)
  • Heres a guide to the way the 12 hours should
    probably pan out each week
  • 2 hours to work through the lecture material.
  • 1 hour to carefully reviewing all examples and
    topics covered in the lectures, copying the code
    into TextPad, getting it running (you may need to
    supply parts of the program that may be missing
    e.g. class header, imports, main method, etc),
    tracing through the code and make sure you
    thoroughly understand everything.
  • 2 hours to do background / additional reading.
    e.g. from text book.
  • 4.5 hours of programming developing programs to
    solve the tutorial questions, end of chapter
    exercises, etc.
  • 1.5 hours for Assignment work (on average per
    week)
  • 1 hour of creating an alphabetical list / summary
    of each week's material and sample code for each
    topic. (This will be exceptionally useful).

31
Student Work Commitment (cont)
  • Minimum of 12 hours is of course just the
    minimum. If you are struggling or have fallen
    behind, etc, then you may need to put in a lot
    more than 12 hours of productive work per week to
    get yourself back on track.

32
How to Pass this Course (and get the most out of
it)
  • Work through the lecture material each week.
  • Do the required reading each week.
  • Explore and trace through the examples provided
    each week to ensure you understand everything.
  • Do the tutorial questions and at least some of
    the end of chapter programming questions (text
    book) each week.
  • Start work on assignments 3 weeks prior to the
    due date.
  • Submit assignments by the specified due dates.
  • Seek help straight away if you get stuck on
    something and cannot find the answer in text book
    or lecture material.
  • Do NOT let yourself fall behind !

33
How to Fail this Course (and have a really
miserable time)
  • Do few or none of the tutorial questions each
    week.
  • Do few or none of the end of chapter programming
    questions (text book) each week
  • Don't do much of the required reading each week.
  • Don't seek help when you need help.
  • Don't learn how to debug and trace your own code.
  • Start work on assignments at the last minute.
  • Cheat / plagiarise assessment material / work.
  • Let yourself fall behind.
  • Aim to scrape by with a pass in the exam.

34
About Passing and the Exam
  • You must score at least 30 / 65 on the exam and
    satisfy all other pass criteria to pass this
    course see "Pass Criteria for this Course"
    (above).
  • Trying to get through with a bare pass in the
    exam is a very risky strategy because if you get
    any questions wrong, then you may get less than
    30 / 65 and fail.
  • You should aim to get more than a pass in the
    exam.

35
End of Course Overview
  • In a nutshell, this is everything that you need
    to know to get started with this course.
  • You now know precisely what this course involves
    and what work commitment is required from you.
  • Any questions / comments ?

36
Introduction to Java
  • High-level language
  • Object-oriented
  • Data and operations are packaged into a single
    unit called an object
  • Basic syntax derived from C, C, and Smalltalk
  • Designed by a team from Sun Microsystems led by
    James Gosling in the early 1990s

37
Introduction to Java (cont)
  • Parsimonious
  • Compatible with older versions
  • Robust
  • Strongly typed and incorruptible data
  • Secure
  • Protection against misuse of code
  • Portable
  • Platform-independent

38
Java Program Types
  • Console Applications
  • Applets
  • Windowed Applications
  • Servlets
  • Web Services
  • JavaBeans
  • We only cover the first 3 in this course.

39
Console Applications
  • Stand-alone programs using a command-line
    interface.
  • Example (from a US text book, hence the US
    spelling of cheque)

40
Applets
  • Client-side programs executed as part of a
    displayed Web page. Example

41
Windowed Applications
  • Stand-alone programs using a graphical user
    interface (GUI). Example

42
Programming a Computer
  • Often, off the shelf software packages do not
    satisfy all of the requirements of a person,
    business, or company.
  • So, custom-built software applications are often
    required to cater for specific needs.
  • All software needs maintenance, monitoring, and
    upgrades.
  • And, new applications are often needed to support
    emerging technologies.

43
Program Development Cycle
  • All software goes through a Program Development
    Cycle when it is developed or enhanced (often
    several times).
  • The Program Development Cycle stages include
  • Analysis
  • Design
  • Validating the Design
  • Implement the Design (Programming)
  • Test the Solution
  • Document the Solution

44
Program Development Cycle (cont)
45
What Is the Java SDK ?
  • The Java Software Development Kit (SDK) is a
    programming package to develop Java applications
  • The Java Runtime Environment (JRE) provides the
    tools to deploy Java applications.
  • These are ALL you need to build and run Java
    programs.
  • However, other tools, such as TextPad, can make
    programming / development easier.

46
Programming in Java
  • Programming in Java involves 3 main steps.
  • The programmer enters Java program code into a
    plain text file (such as a Notepad file).
  • The programmer saves and compiles the program
    code they wrote above, during which Java will
    check the program for syntax errors.
  • The programmer runs the program they compiled
    above to make sure everything works.
  • If any changes are needed, then these steps
    should be repeated (possibly many times) until
    the program is complete and correct.

47
Programming in Java (cont)
  • Java has a very specific syntax that programmers
    must follow when writing programs.
  • Java has specific naming conventions for names
    that programmers must use for variables, classes,
    etc.
  • Java is case sensitive, which means that you must
    get the case correct before Java will recognise
    commands or statements.
  • In addition, the file name used for a source code
    file must match the name of the class exactly and
    have the same case. (More on this soon )

48
Java Naming Conventions
  • The names that a Java programmer can assign to
    classes, variables, methods, etc must conform to
    a very strict standard.
  • The names cannot be Java Reserved Words.
  • Names cannot start with digits (0-9).
  • The names can contain uppercase (A-Z), lowercase
    (a-z), underscore (_), and digits (0-9) but
    nothing else. No spaces, minus signs, etc are
    allowed.
  • Note There are some other characters you can
    use, but lets not confuse things. Simply follow
    the above rules to avoid trouble.

49
Exercise Java Naming Conventions
  • Exercise Which of the following names are legal
    and which are illegal, and why ?
  • My Data
  • 123Fred
  • Total_Dollars
  • Page-Limit
  • Bank_Blance12
  • class
  • cRaZy_d_U_dE4

50
Answer
  • My Data Invalid, contains a space
  • 123Fred Invalid, starts with number
  • Total_Dollars Valid
  • Page-Limit Invalid, due to minus sign
  • Bank_Blance12 Valid
  • class Invalid, reserved word
  • cRaZy_d_U_dE4 Valid

51
Comments
  • Comments are descriptions that a programmer adds
    to their program to explain what it is doing and
    why.
  • Comments are ignored by the compiler.
  • Three types of comments are available in Java.
  • // Everything on this line after slash-slash is
    comment.
  • /
  • Everything between the slash-star and
    star-slash
  • is a comment and it
  • can extend over multiple lines ...
  • /
  • And, the 3rd type are Java DOC Comments / .
    / , but these are not covered in this course.

52
Console Applications
  • Stand-alone programs using a command-line
    interface.
  • General form
  • // File Comments Title, Author, Description. etc
  • // Import statements (if needed)
  • public class W01_Console_App_General_Form
  • public static void main (String args)
  • // Declarations
  • // Code
  • // public static void main
  • // public class W01_Console_App_General_Form

53
Console Applications (cont)
  • Import statements are used to bring in any
    additional functionality that your program
    requires, such as Date handling, Applet support,
    and so on. (More on this later).
  • Class the class statement must start with
    public class followed by a valid name that you
    provide. In the prior, example, our class was
    called My_Class.
  • The code for each class must be enclosed in
    braces
  • The text file that this program is saved in must
    be called My_Class.java (case sensitive).

54
Console Applications (cont)
  • main Next comes the main(), which is something
    called a method.
  • Methods are named sections of code that can be
    executed.
  • The code for each method must be enclosed in
    braces
  • For Console Applications, Java automatically
    looks for and executes the main method when you
    run the program.

55
Console Applications (cont)
  • The main method must have this form
  • public static void main (String args)
  • // Your code goes here.
  • Or, this form
  • public static void main (String args)
  • // Your code goes here.

56
Console Applications (cont)
  • public static void main (String args)
  • // Your code goes here.
  • Notes about the main() method
  • The main() method must be pubIic, static, and
    void (in that order).
  • The main() method must accept an array of
    strings.
  • If you miss out any of these items, then your
    program may still compile, but it will not
    execute.
  • Java will report that it cannot find the required
    main () method.
  • The square brackets indicates an array. More
    on this later in this course.
  • It does not matter what the array of strings is
    called, for example, instead of args you could
    call it fred.

57
Semi Colons
  • Rule All Java commands / statements must be
    terminated with a semi-colon "".
  • However, there are exceptions to this rule, for
    example
  • Do not put a semi-colon at the end of braces or
  • Do not put a semi-colon at the end of a method or
    class statement.

58
Displaying Output
  • To display output from a Java program, and not
    move to the next line on the screen
  • System.out.print ()
  • To display output from a Java program, and then
    move to the next line on the screen
  • System.out.println ()
  • e.g. This would produce "Hi There" (the quotes
    would not show in the output)
  • System.out.print ("Hi ")
  • System.out.println ("There ")

59
Displaying Output (cont)
  • Actually, there is slightly more to displaying
    output than this.
  • The console output can be sent to the screen, or
    it can be redirected to another device (such as
    file, printer, etc).
  • For example, to redirect output to a file, use a
    DOS command line with a greater than sign
    followed by a file name.
  • e.g. To send output to the file "abc.txt", use
    this DOS command line
  • Myprog.exe gtabc.txt

60
Displaying Output (cont)
  • If your output MUST go to the screen (and you do
    not want it to be redirected anywhere else), then
    use either of these
  • System.err.print ()
  • System.err.println ()
  • If your are happy for your output to go to the
    screen or file or wherever else it may be
    redirected then use either of these
  • System.out.print()
  • System.out.println()

61
Hello World Application
  • // Author Mike O'Malley
  • // Source File Hello_World.java
  • // Description Java Hello World Program
  • public class Hello_World
  • public static void main (String args)
  • System.out.println ("Hello World")

62
TextPad Hints and Tips
  • When you run TextPad, you should see something
    like this

63
TextPad Hints and Tips (cont)
  • TextPad's big window is where we type our Java
    programs.
  • If we want, we can copy and paste code from
    elsewhere.
  • For example, we can copy the "Hello World"
    program above, and then paste it into the
    TextPad.
  • When we do this we will see the following (see
    next slide)

64
TextPad Hints and Tips (cont)
65
TextPad Hints and Tips (cont)
  • Before we can compile or run our program, we need
    to save it.
  • Recall (from earlier) that the source file name
    must exactly match the class name and have a
    ".java" extension.
  • So, for our "Hello_World" class, the source file
    must be "Hello_World.java".
  • If we click the "Save" icon (or use the File ?
    Save menu), then we need to enter
    "Hello_World.java" as the File name (without the
    quotes), and then select "Java (.java)" in the
    Save as type.

66
TextPad Hints and Tips (cont)
67
TextPad Hints and Tips (cont)
  • If we want, we can use the standard navigation
    controls built into the Save Dialog to navigate
    to the drive and directory where we want to save
    our source code.
  • Then, we click the "Save" button.
  • When we do this, we should see the following
    (see next slide)

68
TextPad Hints and Tips (cont)
69
TextPad Hints and Tips (cont)
  • Note, if the save is successful, then you should
    see "Hello_World.java" in TextPad's title bar
    (with the files drive and directory).
  • See (1) on next slide.
  • You should also see "Hello_World.java" in the
    TextPad's documents window on the left.
  • See (2) on next slide.
  • And, the source code should become "colour coded"
    to reflect the current Java colour coding
    settings in TextPad.
  • See (3) on next slide.

70
TextPad Hints and Tips (cont)
71
TextPad - Compiling and Running
  • OK, we are now ready to compile and run our
    program.
  • To compile our program do either of the
    following
  • Select the Tools ? Compile Java menu option.
  • Or, simply hold down the Ctrl and 1 keys
    simultaneously and release them.

72
TextPad - Compiling and Running (cont)
  • The first compile takes a few seconds to respond
    (as Java is loaded in the background). On the
    lab PCs, it may take quite a bit longer than this
    if Java is being loaded over the network.
  • Subsequent compiles are very fast.
  • If all is OK, then TextPad should return with the
    display of our program.
  • If there are any errors, then TextPad will show
    us an error window (more on this soon).

73
TextPad - Compiling and Running (cont)
  • Assuming the compile was successful, we can now
    run our program.
  • To run our program do either of the following
  • Select the Tools ? Run Java Application menu
    option.
  • Or, simply hold down the Ctrl and 2 keys
    simultaneously and release them.
  • Please Note Run Java Applet (Ctrl-3) is only for
    running Applets which we cover in the future.
    Do not use the run Applet commands for console
    applications (like our "Hello World" program).

74
TextPad - Compiling and Running (cont)
  • Running our "Hello World" console program

75
Testing and Debugging
  • Testing is the act of running our programs and
    checking their outputs and also checking how they
    operate to make sure they work properly in all
    situations and produce the correct results for
    all possible inputs.
  • Debugging is the act of tracking down and
    removing errors from our programs. That is, we
    are fixing our programs.
  • Testing and Debugging are essential skills for
    all programmers.
  • We will now cover some very simple debugging
    using TextPad.
  • Now that we have a working program, let's break
    it to see how we can fix it.

76
Debugging Example 1
  • Let's introduce an error into our program.
  • To start with, let's use the wrong case for the
    println command.
  • Change this
  • System.out.println ("Hello World")
  • To
  • System.out.Println ("Hello World")
  • If we make this change and then compile our
    program again, then Java will find this error,
    and TextPad will display it. (See next slide).

77
Debugging Example 1 (cont)
78
Debugging Example 1 (cont)
  • Java generates error messages that are often
    cryptic.
  • However, in this case, it is quite clear that
    Java cannot find or understand the command
    "Println".
  • The "9" indicates the error is on line 9.
  • The error message includes the line of code and
    below this is a carrot symbol "" which points
    where Java thinks the error is
  • System.out.Println ("Hello World")

79
Debugging Example 1 (cont)
  • If we double click the mouse on the first line in
    the error messages window, then TextPad will take
    us to that location in our code so that we can
    fix it.
  • Let's fix this error and then introduce a
    different error.

80
Debugging Example 2
  • OK, this time, let's change the class name to
    "Hello_world" so that the case no longer matches
    the file name "Hello_World.java".
  • public class Hello_world
  • Once we make this change, it's time to recompile.

81
Debugging Example 2 (cont)
  • After recompiling, the error message produced is
  • D\Java\Hello_World.java5 class Hello_world is
    public, should be declared in a file named
    Hello_world.java
  • public class Hello_world
  • Which makes it pretty clear that the class name
    and file name don't match.
  • The "5" indicates the error is on line 5.
  • Double click on the first line and TextPad will
    take us to that location in our code so that we
    can fix it.

82
Debugging Example 3
  • OK, this time, let's miss a semi-colon.
  • We only have one line of code in this program, so
    we don't have much scope. But, let's remove the
    semi-colon anyway.
  • Change this
  • System.out.println ("Hello World")
  • To
  • System.out.println ("Hello World")
  • Once we make this change, it's time to recompile.

83
Debugging Example 3 (cont)
  • After recompiling, the error message produced is
  • D\Java\Hello_World.java10 '' expected
  • Which makes it pretty clear that a semi-colon is
    missing. However, Java is pointing the brace
    below the line of code where the semi-colon is
    missing.
  • The "10" indicates that Java thinks the error is
    on line 10 but it is really on line 9.
  • Hint Sometimes you need to look at a prior line
    of code to find the real error.

84
Exercise How many errors can you find in this
program ?
  • // Author Mike O'Malley
  • // Source File Hello_World.java
  • // Description Java Hello World Program
  • Public class Hello_World
  • public void main (String args)
  • System.out.println ("Hello World")
  • System.Out.print ("Java Rules)
  • System.out.println ("OK")

85
Answer 5 Errors (in Red)
  • // Author Mike O'Malley
  • // Source File Hello_World.java
  • // Description Java Hello World Program
  • Public class Hello_World
  • public static void main (String args)
  • System.out.println ("Hello World")
  • System.Out.print ("Java Rules")
  • System.out.println ("OK")

86
Program Development Strategy
  • You should use the following approach whenever
    you develop any programs
  • Ensure that you understand what is required.
  • Start off with the most basic program possible to
    provide a small part of what is required. Get
    this working and tested.
  • Then, add some functionality to the program to
    solve the next small part of the problem. Get
    this working and tested.
  • Keep doing this until your program completely
    satisfies the original requirements and is fully
    tested and working.
  • Keep an eye out for common functionality (and
    make this a separate method - More on this in a
    future lecture).
  • If things do not work, then do NOT fall into the
    trap of making random changes to your program.
    If a program does not work, then there is a good
    reason why. Learn to trace through your code so
    you can work out why it isnt working. (More on
    this in future lectures).
  • Keep regular backups of your work.
  • In this way, you will not end up with a program
    with 100's of errors, and any errors you do have
    will be manageable.

87
Summary of Topics Covered
  • Course overview
  • Introduction to Java
  • Basic Java programming.
  • A Simple "Hello World" Program
  • TextPad Hints and Tips, and compiling and running
  • Debugging Skills the basics
  • Program Development Strategy
  • Note Students who do this week's tutorial
    questions will be applying the above.

88
End of Lecture
Write a Comment
User Comments (0)
About PowerShow.com