Lecture and Lab 2
Structure of a Java applet. Introduction to Classes and Objects
Plan for next two weeks
Mostly lab-like sessions, combined with short "lectures", demos and discussions.
All these demos and exercises (and others that will be done later in the semester) are here.
By reading the code and modifying existing
Java applets you will start getting an understanding of the object-oriented
philosophy of Java. Along the way we review basic programming techniques
learned in CS1 and apply them in the context of Java.
Getting started with applets
HTML: simple HTML
document with title, a link and an image.
- In a web browser, view the source of an HTML document; save an HTML file.
Unix and DOS commands (directories, permissions; mkdir, cd, ls, chmod). For a web page to be visible, its
permissions must be properly set. In-class demo of chmod and other unix commands.
- What is an applet? Inserting an
into an HTML page.
How to compile a Java program: compiling a simple applet
including it in web page; viewing it with a web browser.
In-class exercises: how are they helping you learn Java?
By doing these exercises, you learn:
- How the Java code of a more advanced applet looks like.
- That the instructions in Java are very similar to those in C/Python or any "standard" programming language.
- You get to review basic programming concepts (variables, arrays, assignment, for, while, switch), string and input/output functions in the
context of Java.
- You get a gentle introduction to object-oriented programming: class, object, method, inheritance.
- You get a gentle introduction to memory allocation concepts: the new operator.
- You get a gentle introduction to event driven programming: use of mouse events.
- You get a gentle introduction to Graphical User Interface design in Java: buttons, menus, textfields, labels.
- You get a gentle introduction to graphics programming: drawing points, lines, circles, polygons, using colors and text.
- Read first the submission instructions and
make sure you do all the work today in the Lab2 directory, in public_html of your class account. Each time there is an
in-class exercise, do it in a directory Labx, where x is the number of the lecture (e.g. today is lecture 2).
- The exercises are numbered. Start with 01-HelloWorld. Use the readme.html file to guide you and exercise.html file
to tell you how to modify the existing program and what to do with it.
- Submit, as described here, at the deadline. The html page and the class file
should be readable while you are developing the program, but the java file should be made readable ONLY on
Wednesday night, when the first homework is due.
- Check that the submission is visible by checking the Students link
from our 112 class main web page.
Each exercise should be done in its own separate directory named as indicated (HelloWorld, Init, PaintText, etc.).
These exercises will count as part of your first and second homeworks.
You will be told, in the beginning of each lecture/lab period, how many new exercises to do, and which ones.
For today, the plan is roughly: 1 and 2 in the morning, 3, 4, 5, 6 and 7 in the afternoon (to be completed
as part of the first homework.)
Click now to get to the directory of All exercises
Will ask you to create a small applet with basic action and drawing, and doing some simple computations.
It is a combination of all the small exercises
done in this lab.
Check the homework on the class schedule page.