Top Banner
Introducing Java CSC1401
23

Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Dec 14, 2015

Download

Documents

Rohan Pape
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Introducing Java

CSC1401

Page 2: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Course Goals

Teaching programming conceptsIn a “real” language

Page 3: 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

Page 4: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 5: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Important object-oriented concepts

Class

Object

Method

Parameter

Sequencing (Do in order vs. Do together)

Design

Page 6: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 7: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 8: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 9: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Alice-Java Differences

The main program is generally world.my first method

The main program is generally public static void main (String [] args)

Page 10: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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.

Page 11: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 12: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Alice – Java Differences

File names always end in .a2w (and sometimes .a2c)

File names always end in .java

Page 13: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 14: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 15: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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.

Page 16: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 17: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

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

Page 18: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

JGrasp Demo

Opening a new Java file

Page 19: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Using Turtles

Add bookClasses to your classpath to use these classes

Page 20: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Telling JGrasp where to find the Turtle class

Page 21: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Classpath part 2

Then click on OK

Then click on Apply

Then click OK

Page 22: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Turtle Demo

Writing a Turtle programclass

public static void main(String [] args)

{} versus ;

// and /*

new

Compiling and running and stopping

Looking at the Javadoc

Page 23: Introducing Java CSC1401. Course Goals Teaching programming concepts In a “real” language.

Assignment

Read Media Computation Chapter 3, Sections 1 through 5

Classes

Objects

Methods