Docsity

Java Language and Environment - Computer Science Design - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Java Language and Environment - Computer Science Design - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

The Java Language and Environment

Overview of Presentation

• Motivation and Introduction to Java

• Designing and Developing Applets in Java

• The Java User Interface - GUI with AWT

• Designing and Developing Java Classes

• Inheritance and Interfaces in Java

• Polymorphism and Object Serialization

An Overview of Java

• Java is a Third Generation, General Purpose,

Platform Independent, Concurrent, Class-Based,

Object-Oriented Language and Environment

• Java Composed of JDK and JRE

  • Java Language
  • Java Packages (Libraries)
  • javac Compiler to Bytecode (p-code)
  • JDB Java Debugger
  • Java Interpreter - Platform Specific

• JDK: Java Development Environment

http://www.javasoft.com/products/jdk/1.2/

• JRE: Java Runtime Environment

http://www.javasoft.com/products/jdk/1.2/jre/index.html

What is Java?

Software Releases and IDEs

  • Java is Free!
  • Current Releases
    • Version 2 for Win95, Win98, NT
    • Version 2 (Early Access) for Solaris
  • Third-Party Ports to All Conceivable HW/SW

Platforms from Micros to Mainframes

http://www.javasoft.com/cgi-bin/java-ports.cgi

  • Integrated Development Environments (IDEs)
    • Commercial Products, Freeware, Visual IDEs
    • Visual J++, Visual Café, Kawa, Jpad, Javelin

Java Visualization

Packages In Java

• Allows Related Classes to be Grouped into a

Larger Abstraction

  • Similar to Ada95 Packages
  • Unavailable in C++

• Utilization of Packages for SW Design and

Development

  • Components, Modularization, Groupings
  • Enforcement by Compiler of Package Rules

• Overall, Packages Enhance the Control and

Visibility to Fine-Tune

  • Who Can See What When

The Java Language

• Overview of Non-OO Capabilities

  • Based on C/C++
  • No includes, typedefs, structures, groups
  • Unicode Character Set - 34,168 Characters
  • Automatic Coercions Not Supported
  • Strongly-Type Language

• Variables in Java

  • Primitive Types : ints, floats, booleans, Unicode chars
  • Reference Types : arrays, classes, interfaces

• No Physical Pointers in Java!

The Java Language

• Statements in Java - Resembles C and C++

– Assignment/Expressions and Precedence

– for, while, do-while

– if-then, switch-case

– break, continue, label, return

• Exception Handling

– Similar to C++

– try, throws, catch Blocks

– Strongly Integrated Throughout APIs

The Java Language

Object-Oriented Features

• Class - similar to C++ Class

• Classes have Members (Methods and

Variables)

• Members Tagged Using Keywords

– private: Typically, Inaccessible

– public: Potential to be Accessible

– protected: Accessible via Inheritance

– package: Accessible within Package

• Involve Visible Between Classes, Within

Packages, and Due to Inheritance

Classes in Java

• A Supermarket Item

• Keywords must be Utilized for Each

Attribute or Method Declaration

class Item { private String UPC, Name; private int Quantity; private double RetailCost; protected double WholeCost;

public Item() { ... }; public void finalize() { ... }; public boolean Modify_Inventory(int Delta){...}; public int Get_InStock_Amt() {return Quantity;}; };

Visibility of Attributes/Methods

• Class Members (Attributes and Methods)

• Visibility Tags for Members

– Private : Visible only to Class

– Protected : Visible to Class and Other Classes

within Package

– Public : Visible to Class, Other Classes within

Package, and if Class is Public, Visible to Other

Packages/Classes

– No Tag : Visible Only to Other Classes within

Defining Package

• Java's Controlled Sharing within/betweenDocsity.com

Inheritance - Two Roles

• Controlled Sharing Between Classes

– Generalization vs. Specialization

• Treat Instances of Different Classes in a

Uniform Fashion

– Polymorphism and Dynamic Binding

• Inheritance in Java

Item /
DeliItem ProduceItem | SaladItem class DeliItem extends Item { ... }; class SaladItem extends DeliItem { ... }; class ProduceItem extends Item { ... };

Designing and Developing Applets

in Java

• An Applet is a Java Program that Executes

as part of an HTML Page

applet

A.java

applet

A.class

javac

HTML file

Applets Inheritance Structure

java.lang.Object

java.awt.Component

java.awt.Container

java.applet.Applet

your applet

Everything in Java inherits from the Object class Event-handling and drawing capabilities Ability to hold components

Limits what an Applet can and cannot do

Every Applet is a subclass of the Applet class.