Download 06JavaIntro

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Library (computing) wikipedia , lookup

Java syntax wikipedia , lookup

Class (computer programming) wikipedia , lookup

Name mangling wikipedia , lookup

Scala (programming language) wikipedia , lookup

Object-oriented programming wikipedia , lookup

C Sharp syntax wikipedia , lookup

Java (programming language) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Java performance wikipedia , lookup

Transcript
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 Alice
Others we’ll explore first in Java
The problem of Java
It’s hard
We’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 located
Local Gallery
CD Gallery
Web 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 program
We’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 60s
By teaching the computer to do something
the kids are thinking about thinking
Develop problem solving skills
Learn by constructing and debugging something
Learn by making mistakes and fixing them
JGrasp Demo
Opening a new Java file
Using Turtles
Add bookClasses to your classpath to use
these classes
Telling JGrasp where to find the
Turtle class
Classpath part 2
→
Then click on OK
Then click on Apply
Then click OK
Turtle Demo
Writing a Turtle program
class
public static void main(String [] args)
{} versus ;
// and /*
new
Compiling and running and stopping
Looking at the Javadoc
Assignment
Read Media Computation Chapter 3,
Sections 1 through 5
Classes
Objects
Methods