CS 3131 Introduction to Programming in Java - PowerPoint PPT Presentation

About This Presentation
Title:

CS 3131 Introduction to Programming in Java

Description:

compilers. interpreters. Origin of Java. Application versus Applet. Object ... Compilers generally produce machine code. Some ... specific compiler for ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 27
Provided by: vinod6
Learn more at: https://www.d.umn.edu
Category:

less

Transcript and Presenter's Notes

Title: CS 3131 Introduction to Programming in Java


1
CS 3131 Introduction to Programming in Java
  • Rich Maclin
  • Computer Science Department

2
Course Overview
  • I. Introduction to Java (Ch. 1)
  • II. Graphical User Interfaces (GUIs)
  • A. Graphics commands (Ch. 2)
  • B. Widgets (Ch. 3)
  • C. Layouts (Ch. 4)
  • III. Java Language Features
  • 1. Basic Language Features (Ch.5, part of Ch. 6)

3
  • III. Java Language Features (cont)
  • B. Event Models (Ch. 6)
  • 1. 1.0 Model
  • 2. 1.1 Model
  • C. Building a full program (Ch. 7)
  • D. Advanced Language Features (Ch. 8)
  • 1. Arrays
  • 2. Loops
  • E. Exceptions (Ch. 9)
  • F. Input/Output Streams (Ch. 10)
  • IV. The Next Step (living on the Web)
  • A. The World Wide Wait(Web) (Ch. 12)
  • B. Threads (Ch. 11)

4
Chapter 1
  • Overview of programming languages
  • compilers
  • interpreters
  • Origin of Java
  • Application versus Applet
  • Object-Oriented Programming
  • classes
  • inheritance

5
Computer Languages
  • Machine language
  • 01010110 ADD R1,R2
  • Assembly language
  • ADD R1,R2
  • High-level programming language
  • XY

6
Language Translation
  • High-level code mapped to low-level code
  • Can have multiple steps
  • high-level to assembly
  • assembly to machine language
  • Compiler itself is a program

7
Object Code
  • Compilers generally produce machine code
  • Some produce intermediate code
  • Intermediate code executed by interpreter
  • Java compiles to byte-code
  • Byte-code interpreted

8
Advantages of Interpreters
  • Different machines can have interpreters specific
    to that machine
  • machine independence
  • no need for specific compiler for each machine
  • code compiled on any machine can be run on any
    with an interpreter

9
Disadvantages of Interpreters
  • Resulting code slower (10-100 times)
  • Still need an interpreter for each machine
  • Limited to abilities all machines can produce
    (lose graphics abilities of SGIs)

10
Why Java?
  • Why not?
  • Similar moves had happened before, the difference
    is the World Wide Web
  • Java provides a programming tool for web pages
    that
  • has graphics capabilities
  • is machine independent
  • small language (easy to implement)

11
Why NOT Java?
  • Still very young (undergoing constant change)
  • Visual J already dated
  • So is our textbook (published in 1998)
  • Language is growing in size
  • It is slow

12
The Internet
  • Originated by defense department
  • Mechanism of decentralized communication
  • Nodes route communication to others (seamlessly)

13
World Wide Web
  • Based on the internet
  • Idea distributed hypermedia
  • Pages placed in known locations on machines
    connected to internet
  • Browsers can look at those pages
  • Pages contain links to other pages/info

14
HyperText Markup Language (HTML)
  • Language used in web documents
  • Contains commands enclosed in ltgt
  • ltBgt bold lt/Bgt for bold text
  • Commands interpreted by machine
  • Can contain references to Java programs
  • ltAPPLETgt code Name.class lt/APPLETgt

15
ltHTMLgt ltHEADgt ltTITLEgtPage Titlelt/TITLEgt
lt/HEADgt ltBODYgt Title on the Page ltHRgt
ltAPPLETgt code Name.class
width 100 height 100 lt/APPLETgt ltHRgt
lt/BODYgt lt/HTMLgt
16
Java Programs
  • Applications
  • stand alone
  • compiled, run with interpreter
  • Applets
  • not intended to run on its own
  • embedded in web page

17
Application
public class HelloWorld // A simple
application public static void main (String
argv) System.out.println(Hello
world!) produces output Hello world!
18
Applet
import java.applet. import java.awt. public
class HelloWorld extends Applet // A simple
Applet public void paint (Graphics g)
g.drawString(Hello world!,30,30)
Produces output on a web page
19
Java files
  • ClassName.java - Java source code
  • ClassName.class - compiled byte code for
    ClassName.java
  • WebPageName.html - web page which may contain
    references to ClassName.class

20
Object-Oriented Programming
  • Program consists of objects from classes
  • A class is a set of objects (instances) with a
    common structure (and purpose)
  • Objects consists of
  • data values (instance variables)
  • methods (class procedures)

21
A Robot Class
Robot Data MapLong - number indicating
longitudinal location MapLat - number
indicating latitude location BatteryLevel -
number indicating battery level Methods
MoveForward(x) - move forward x yards
TurnRight(x) - turn right x degrees
22
Robot Instances
  • Each instance has values for the instance
    variables
  • R1 is at long,lat 36.12,38.34
  • Each method can be applied to each robot by
    sending that robot a message
  • Ask R1 to move forward 5 meters

23
Inheritance
  • Can define robot class with features all robots
    share
  • Then subclasses of robots with specific features
    (e.g., Robots with IR sensors)
  • Specific class can inherit the things defining
    regular robots

24
Java and Inheritance
  • Java relies heavily upon inheritance
  • Java provides lots of classes that perform useful
    actions
  • Our job is to produce specialized classes to
    perform those aspects we are interested in

25
Java packages
  • java.applet - basic applet tools
  • java.awt - abstract window toolkit (buttons,
    text, etc.)
  • java.io - input/output classes
  • java.lang - language features
  • java.net - classes for working with networks
  • java.util - other useful utility classes

26
import java.applet. // add classes from applet
pack. import java.awt. // add classes from
awt package public class HelloWorld extends
Applet // New class name HelloWorld //
Class is accessible by all (public) // Class
extends (inherits from) class Applet public
void paint (Graphics g) // Paint is a method
(we are overriding an existing // method)
g.drawString(Hello world!,30,30)
Write a Comment
User Comments (0)
About PowerShow.com