17 March 2003
This session covers the reading in Chapter 1: The Genesis of Java |
Introduction to class and
explanation of the syllabus
History: Five Major Releases of Java “Hello World” Java code and demonstration Demonstration of the Java Glossary applet What is Java Programming?Applications, Applets and Servlets Java compared to C/C++Quiz |
Introduction of instructor and explanation of the syllabus
Demonstrations:
The promise of Java: http://java.sun.com/docs/books/tutorial/getStarted/intro/changemylife.html
Free download of the current SDK, Software Development Kit at http://www.sun.com
Types of languages | ||||
Object-oriented programming | Procedural | Web scripting | Page description | Data description |
Java, C++, SmallTalk, Objective-C, C# | C, Basic, Fortran, Cobol, Lisp, Perl | JavaScript, VBScript | HTML | XML |
Note: The runtime environment is for users who only need to run existing Java bytecode and do not write the code. http://java.sun.com/j2se/1.4/ The Java Runtime Environment consists of the Java virtual machine, the Java platform core classes, and supporting files. It is the runtime part of the Java 2 SDK, but without the development tools such as compilers and debuggers. (The JRE download is only 8 MB, compared to 38 MB for the SKD download.) The installer for certain programs might install the runtime environment so that end users can run the application.
public class HelloWorld { public static void main (String[] args) { System.out.println("Hello World"); } }
Java programming is the process of creating applications, applets, servlets, and can include creating Java Server Pages (JSP), and Enterprise Java Beans (EJB).
Sun Microsystems likes to think of the Java platform as a target for software development, much as traditionally software developers targeted an operating-system or processor-based platform such as MacOS/Motorola, Windows/Intel, or Sun/Sparc.
To develop code for the Java platform, the software developer uses:
Some people say JDK (Java Development Kit), and this is the same as the Java
SDK (Software Development Kit).
However, the JRE (Java Runtime Environment) is a subset of the SDK for running
Java programs that does NOT include development tools.
To run your code, you and whoever uses your code will need:
An application is software that runs on top of the operating system, has a specific purpose, and usually allows the user to interact. An example of an application is Microsoft Word. On the other hand, the software that runs your printer (a "driver") is something for the operating system or an application, rather than for the human user.
Java introduced the concept of applets, which are applications that can run inside of a web browser on the client computer. A web browser is an application.
An applet is a "safe" application that can only run inside of another, very specific application. Some of the key restrictions on an applet
Note: If an applet provider registers a specific applet with a registration company, the "signed applet", if you accept it, can have access to your file system and the native operating system.
Note: A Java application, like any application, does have access to your file system.
http://java.sun.com/products/plugin/index-1.4.html
The Java Plug-in allows you to run applets using Sun's Java 2 Runtime Environment, Standard
Edition (JRE) instead of the web browser's default virtual machine. Sun's JRE
provides a Java CompatibleTM environment for
today's widely adopted web browsers. That means consistency and reliability when
running applets.
[Swing is part of the Java 2 Foundation Class library that extends the Java 1 Advanced Windowing Toolkit (AWT) to provide new GUI components and features, better event handling, and selectable look and feel]
http://java.sun.com/products/servlet/index.html
JavaTM Servlet technology provides
web developers with a simple, consistent mechanism for extending the
functionality of a web server and for accessing existing business systems to
give them a web interface. A
servlet can almost be thought of as an applet that runs on the server side --
without a face. Java servlets have made many web applications possible.
A computer platform is the combination of the operating system and the central processing unit (CPU).
Examples of operating systems include
Examples of CPUs include
A standard, compiled application runs machine code that is specific for a platform. Machine code is the raw zeros and ones that a computer "chip" understands. If you want your UNIX application to run on Windows, for example, you must "port" the code and recompile it using a compiler that produces machine code that is "native" to the target CPU.
Java code is different from standard, compiled code. You compile your Java source code into a special language, "bytecode", that a special application, the Java virtual machine (JVM), interprets.
The Java interpreter (java) is different from the "HotSpot" just-in-time (JIT) compiler. The interpreter interprets bytecode and makes API calls into the native operating system, for example, calls to Win32API. The JIT compiler can improve performance with optimization capabilities that allow it to compile into native machine code parts that are most heavily used.
The JVM is an application that emulates a computer. It translates Java bytecode into native machine code.
There is a JVM for Mac OS, UNIX, Linux, and Windows. This means that the same source code should be valid for multiple platforms. You do not need to "port" the application to another platform. It should be "write once, run anywhere", assuming there is a JVM for that platform.
There are even JVMs for smaller platforms, such as the PalmOS that runs on the PalmPilot.
Pro | Con |
Harder to create careless bugs (memory leaks, pointer errors) | performance is slow because of CPU-intensive interpretation or compilation of byte code into machine code |
Relatively platform independent: "write once, run anywhere", which is particularly valuable on the server | vision is not fully realized write once, debug everywhere |
strict object-oriented model; cannot mix with procedural code | can use more CPU and memory because C++ can be optimized with lower-level code |
Dynamic linking: supports introducing new objects at runtime without recompiling everything [RMI (remote method invocation)] | slower because of look up; mitigate with JIT compilation |
For more on static versus dynamic linking: http://www.cpp.atfreeweb.com/StaticVersusDynamic.html
From Sun's point of view, Java 1.4.1 is part of Sun's J2EE platform. C# is a Microsoft programming language that closely resembles Java. C# is for use in Microsoft's .NET platform, which relies on libraries of the Microsoft Windows operating system. Insofar as .NET has an intermediate language (IL) and a common language runtime, there is a something analogous to a JVM-like portability, but only within the Microsoft family of programming language. For details, see http://genamics.com/developer/csharp_comparative.htm.
The virtues of Java (as in theory of C#):
http://java.sun.com/docs/overviews/java/java-overview-1.html :
Simple
Like other programming languages, you compile your Java source code (in a
text file) by invoking a compiler that outputs compiled code.
In this case, the compiled code is called "bytecode", which is in a .class file.
You can install the same .class file on multiple operating systems.
To enable platform independence, the Java platform inserts "interpretation"
between the compiled code (.class file of bytecode) and the operating system's
native machine code.
The Java interpreter, named java, converts compiled "bytecode" into machine
code.
The Java interpreter executes bytecode within the Java virtual machine, a sort of virtual computer inside the computer.
Sun defines a total of three (3) Java platforms at http://java.sun.com/java2/whatis/:
http://java.sun.com/j2se/1.3/
The JavaTM 2 Platform, Standard Edition
(J2SETM) has revolutionized computing with the
introduction of a stable, secure and feature-complete development and deployment
environment designed from the ground up for the Web. It provides cross-platform
compatibility, safe network delivery, and smartcard to supercomputer
scalability. It provides software developers with a platform for rapid
application development, making it possible to deliver products to market in
Internet time. It defies traditional software development and deployment models
by delivering on the promise of cross-platform compatibility.
In the current J2SE, the JRE and the SDK include new core APIs, such as XML
and Logging:
http://java.sun.com/j2se/1.4/docs/relnotes/features.html
When you use any language, whether it is a computer language or a human language, you have to follow the rules. The term "syntax" refers to the rules of word order and word combination. Some languages, like French, have a flexible syntax that lets you say "the chocolate good" as well as "the good chocolate". Other language are more rigid about word order. Java syntax is more rigid than, say, Perl syntax.
For example, Java has certain "reserved words" that you use according to Java's syntax and semantics. The Hello World application consists almost exclusively of reserved words or predefined words (in bold):
public class HelloWorld { public static void main (String[] args) { System.out.println("Hello World"); } }
The only words that are not reserved words or predefined words are the three variables:
Just as human languages have punctuation in addition to words, so Java has special symbols, such as the curly braces { }, parentheses ( ), the brackets [], the comma separator , the wildcard asterisk *, quotation marks " ", the forward slash /, the backslash \, the dot . and the semicolon ; that completes a statement.
The PATH system environment variable should point to the directory that has the java interpreter (java.exe), which is typically the "bin" subdirectory of the directory for JDK version.
For example, I went to my Windows Control Panel > System > Advanced > Environment Variables
and edited the path by adding a new entry:
;D:\java\j2sdk1.4.1_01\bin
-------------------------------------------------
I also created a new user variabled, CLASSPATH, and included:
.;D:\java\j2sdk1.4.1_01\;D:\java\j2sdk1.4.1_01\lib\tools.jar
Then I logged out (or rebooted), so the changes would take effect.
For a complete, step-by-step, illustrated guide, see Sun's tutorial, "Your
First Cup of Java":
http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
Be sure to read the installation instructions, including the section about
updating the PATH variable:
http://java.sun.com/j2se/1.4/install-windows.html#Environment
If you have problems, check this troubleshooting guide: http://java.sun.com/docs/books/tutorial/getStarted/problems/index.html
_________________________
course
homepage course
calendar