Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
-
Upload
rohan-pape -
Category
Documents
-
view
225 -
download
2
Transcript of Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.
Course Approach
Alternate between Alice and Java as we learn programming concepts
Some concepts we’ll explore first in AliceOthers we’ll explore first in Java
The problem of JavaIt’s hardWe’ll use specially created graphics libraries to help us
Java libraries
What is a Java library?It’s just a class or several classes
In Alice, classes were locatedLocal GalleryCD GalleryWeb Gallery
In Java, we’ll need to tell the computer where to find the classes
Setting the classpath (this is the directory where the classes will be located)Or, using an import statement in our Java programWe’ll see how to do this in lab on Friday
Important object-oriented concepts
Class
Object
Method
Parameter
Sequencing (Do in order vs. Do together)
Design
Alice Java similarities
We are going to find that Alice and Java are quite similar, and that concepts learned in one language immediately apply to the other
There are some differences, mostly mechanical, between the 2 languages
Some differences between Java and Alice
Alice uses a drag and drop editor
Java has Integrated Development Environments (IDEs) that generally require typing code. We’ll be using one called JGrasp
Alice-Java Differences
Classes are found in the local gallery, the CD gallery, or the web gallery
Classes can be located anywhere, but you need to tell the computer where they are
Alice-Java Differences
The main program is generally world.my first method
The main program is generally public static void main (String [] args)
Alice-Java Differences
In Alice, objects are added to a world by dragging them and dropping them into position
In Java, we use the new keyword. We also use the constructor to specify such things as where to place them.
Alice-Java Differences
In Alice each method is located on a separate window – but you can export all of the dragon’s methods into a single html file
In Java, all of the methods for a single class are in one window
Alice – Java Differences
File names always end in .a2w (and sometimes .a2c)
File names always end in .java
Alice-Java Differences
To run an Alice program, just click on the play button
Running a Java program is a 2-step process:
1) Click on compile. This will make sure you don’t have any typos and generates a .class file
2) Click on Run
Alice-Java differences
In Alice, an object’s methods are located in the object pane at the lower left of the screen
In Java, we need to look at an html file (called Javadoc- short for Java documentation) to see an object’s methods
Alice – Java differences
In Alice most objects (except for billboards) are 3D
In Java, most of our objects will be 2D. Java supports 3D, but it’s much harder to program.
Java Example: Turtles
We will work with Turtles in a World in Java
We do this by writing a Turtle class definition
Turtle.java
We compile it to convert it into something the computer can understand
Bytes codes for a virtual machine
Turtle.class
History of Turtles
Seymour Papert at MIT in the 60sBy teaching the computer to do something the kids are thinking about thinking
Develop problem solving skills
Learn by constructing and debugging somethingLearn by making mistakes and fixing them
Turtle Demo
Writing a Turtle programclass
public static void main(String [] args)
{} versus ;
// and /*
new
Compiling and running and stopping
Looking at the Javadoc