Session 1 Lecture Notes for First Course in Java
course homepage      course calendar

18 March 2002

This session covers the reading in Day 1: 21st Century Java (as well as Appendix A and Appendix B of the paperback edition of the textbook)

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++

Platform Architecture

Syntax and reserved words

Links

Homework Assignment

Introduction of instructors and explanation of the syllabus

Demonstration of the “Hello World” Java application

Demonstration of the Java Glossary applet


LECTURE

Five Major Releases of Java

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, Basic, Fortran, Cobol, Lisp, Perl JavaScript, VBScript HTML XML

http://java.sun.com/products/jdk/1.2/jre/

The JavaTM 2 Runtime Environment v 1.2.2_008 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.


Hello World Code (sneak preview)

public class HelloWorld 
{
  public static void main (String[] args)
  {
    System.out.println("Hello World");
  }
}

What is Java Programming?

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:


Applications, applets, and servlets

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.

Applets run in a browser

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.

Java Plug-in

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. Chapter 8 uses Swing applets, so you will need the plug-in.

[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]

Servlets run on the server

Week 9 of this course covers servlets. For now, all you need to know about servlets is:
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.


Java compared to C, C++

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.

Platform independence

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.

Advantages and disadvantages of the Java platform compared to C++

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


"Platform" Architecture

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.

 

 


Syntax and reserved words

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.


Links


Homework Assignment for 25 March:  

  1. Download the Java SDK.
  2. Optional: Set the path environment variable by giving the class path 
  1. Write, compile, and run the HelloWorld application.
  2. Also do the assignment on p. 57, second bullet
  3. SEND YOUR WORK TO THE INSTRUCTOR EMAILS: davidn@mdli.com and java@WORDesign.com
  4. Read about using a text editor with the Software Development Kit (Appendix B for paperback edition)
  5. Go to http://java.sun.com/docs/books/tutorial/ and look at Sun's Java Tutorial "Getting Started"
    about Getting Started with the HelloWorld application and applet.

_________________________
course homepage      course calendar