Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.stsci.edu/hst/training/events/Java/SSD981214java/Java1.html
Дата изменения: Unknown
Дата индексирования: Sun Dec 23 13:24:39 2007
Кодировка:
Поисковые слова: п п п п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п р п
|
Introduction to Object-Oriented/Internet Programming with Java I
The objective of this course is to help you to understand some fundamental basic
concepts behind the Java technology. The audience is assumed to have little or no
prior exposure to Java and Object-Oriented programming. Here we will cover the basics
of the Java technology. The topics will help you to understand how to use Java to
create, access, and support Java applications and applets. We will also discuss the
portability features of Java and how they are changing the way Web users access applications
at the desktop level.
In the next few sessions, we will:
- Discover why Java provides the answer to so many of today's computing problems.
- Introduce object-oriented programming concepts and how they apply to Java programming.
- Learn how Java applets are changing the way that client-server architectures
are implemented.
- Understand how the Java Virtual Machine and "Just-In-Time" technology
offer considerable advantages over the long accepted C++ development and run-time
environments.
- Peruse the Java application programming interface (API) for all of the packages
offered for applet and application programming, using the Java Development Kit (JDK)
1.1.
- Introduce the new Java 2 (formerly JDK 1.2) platform.
- Implement a completely platform independent Java application which takes advantage
of graphical user interface (GUI) components that operate on any Java supported platform,
including UNIX, Windows95, WindowNT, and MacOS.
Topics:
What is "Java"
An early description of the Java language from Sun
Java: A simple, objected-oriented, distributed, interpreted, robust, secure,
architecture neutral, portable, high-performance, multithreaded, and dynamic language.
- Java was introduced in late 1995, and took the Internet by storm.
- Java is a 3rd generation object-oriented programming language.
- Java is designed to be "platform independent" for both application
development and deployment. This is achieve by the Java Virtual Machine (JVM).
- The Java compiler generates byte-codes for the Java Virtual Machine (JVM), rather
than native machine code, so you run the generated byte-codes through the JVM (the
Java interpreter).
- Java is architecture neutral and portable - because Java programs are compiled
to an architecture neutral byte-code format, a Java application can run on any system
as long as that system implements a JVM.
- Java programs come in two flavors: Java Applets vs. Java Applications.
- The latest version of Java: Java 2 (formerly JDK 1.2).
A Simple Example - Hello World
Here, we will do the "Hello World" program in Java.
Filename MUST be HelloWorld.java, since the class name is HelloWorld
public class HellowWorld
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
At the prompt, you would:
- Compile the program with the command:
javac HelloWorld.java
- Run the program with the command:
java HelloWorld
A More Detailed Look at the Java Technology
- The Java Object-oriented programming language
- The Java Virtual Machine (JVM)
- Java Applications and Applets
- JDBC and JSQL
- Java Native Interface (JNI)
- Java Remote Method Invocation (RMI)
- JavaBeans
- Java Scripting (not part of Java)
New Additions
- Java Security Model - expanded sandbox, Java Cryptography Architecture
- Java Foundation Class
- Java IDL (Interface Definition Language)
The Java Object-Oriented Programming
Language
- Java can be used to develop a complete application just as one would develop
an application with C or C++.
- Or Java can be used to develop applets that run within a web browser.
Application vs. Applet
- Application
- Java class(es) intended to be executed in a standalone manner.
- main() method must be defined somewhere
- O/S command line parameters are passed to main() method
- have access to the host file system.
- Applet
- Java class(es) intended to be executed from within a Web Browser
- main() method is not needed - init() defined instead
- <applet> tag used in HTML to invoke class and define parameters
- applet can read parameters like environment variables
- access to browser environment is provided - e.g., windows and menus
- do not have access to the client's file system; only have access to the server's
file system
One reason behind these distinctions has to deal with security issues.
The Java Virtual Machine (JVM)
Java applications and applets need the JVM in order to run.
JVM:
- provides the Java Runtime Environment for Java programs to run
- the JVM emulates a stack-based machine architecture
- establishes a perimeter for Java applets to run (Java 1.x)
- establishes a perimeter for Java applications to run (Java 2)
- ensure compatibility among different platforms (through proper implementation
of JVM)
Java - as a programming language
for Internet applications
- Platform independent
- Object-oriented
- Security
Java - Pros and Cons
Pros:
- Platform independent
- Object-oriented
- Security
- Flexibility
- GUI
Cons:
- Performance
- Platform independent (but OS dependent)
- Subject to platform implementation
Object-Oriented Programming &
Application Development
To develop Java applets and applications, one must first understand the fundamental
concepts of object-oriented programming (OOP) and application development. OOP is
quite different from traditional programming approaches, quite different from Fortran,
Pascal, and C programming.
Object-Oriented Concepts
- An object is an entity that is defined in terms of data, processes, state, and
external interfaces.
- e.g. NICMOS, STIS, WFPC2, ...
- A class is a set of objects that share a common structure and a common behavior
- e.g. HST Science Instruments
- Objects are concrete entities, i.e., take up storage.
- Objects perform some role in the overall system.
Definitions
- Abstraction
- Focusing upon the essential properties of an object which distinguish it from
all other kinds of objects
- Encapsulation
- Hiding all the details of an object that do not contribute to its essential characteristics
("information hiding")
- Inheritance
- Ranking or ordering of abstractions ... consider it as the "Is-A" relationship
between 2 objects.
- Polymorphism
- Objects denoted by the same name are able to respond to some commonly named set
of operations in different ways.
Language Properties
- Incremental Problem Solving
- Reusable Software Components
- Templates
- Garbage Collection
Application Development
Functional/Traditional
- Algorithmic abstraction
- Provides the "steps" to solve the problem
- Yields a top-down procedural solution
- Integration into a final implementation
Object-Oriented Approach
- Identifies objects and their interaction and dependencies
- Most stable structure of a software system
- Incremental series of prototypes
- Evolution into the final implementation
Resources
One of the main source of Java resources is the Sun Java website:
http://www.javasoft.com/
Detail documentations can be found at:
http://www.javasoft.com/docs/index.html
Also see http://www.oreilly.com/catalog/books/javanut2/
for Java examples available for downloading as noted in the Java in a Nutshell reference.
Several good books:
Java in a Nutshell by David Flanagan, from O'Reilly.
Java - How to Program by Deitel & Deitel, from Prentice Hall.
Inside Java by Siyan & Weaver, from New Riders Publishing.
The Java Series, from Addison-Wesley.
Paul Lee
update: 12/14/98