Java Basics & Platform
Introduction

Agenda

Prerequisites

What is a computer?

Schematic Diagram of a Computer

What is a computer?

The computer is the network
(8 Fallacies of Distributed Computing)

What Is Programming?

Programming Languages

Computers are mind magnification tools

The Progress of Abstraction

All programming languages provide abstractions.

 

SORCER Vision

Object Abstraction

What is Java?

Object-Oriented Philosophy

Java Programming Language

Exceptions

Multi-threading

Java APIs

Compiling and Running

Compiler machine dependent environment

The JVM model

 
Java is also unusual in that each Java program is both compiled and interpreted. With a compiler, you translate a Java program into an intermediate language called Java bytecodes--the platform-independent codes interpreted by the Java interpreter. With an interpreter, each Java bytecode instruction is parsed and run on the computer. Compilation happens just once; interpretation occurs each time the program is executed.

Linking, Optimization, and Execution

Java Virtual Machines

 

 

 

You can think of Java bytecodes as the machine code instructions for the Java Virtual Machine (Java VM). Every Java interpreter, whether it's a Java development tool or a Web browser that can run Java applets, is an implementation of the Java VM. The Java VM can also be implemented in hardware.

Java bytecodes help make "write once, run anywhere" possible. You can compile your Java program into bytecodes on any platform that has a Java compiler. The bytecodes can then be run on any implementation of the Java VM. For example, the same Java program can run on Windows NT, Solaris, and Macintosh.

Java virtual machines (JVMs), Java development kits (JDKs), Java runtime environments (JREs)

Just-in-time (JIT) compilers

Just-in-time (JIT) compilers are essentially fast traditional compilers that translate the Java technology bytecodes into native machine code on the fly. A JIT running on the end user's machine actually executes the bytecodes and compiles each method the first time it is executed.

The Java HotSpot VM Architecture

Rather than compiling method by method, just in time, the Java HotSpot VM immediately runs the program using an interpreter, and analyzes the code as it runs to detect the critical hot spots in the program. Then it focuses the attention of a global native-code optimizer on the hot spots.

The Java HotSpot Client VM, on the left, and the Java HotSpot Server VM, on the right, use a different compiler but otherwise interface to the same virtual machine, using the same garbage collection (GC) routine, interpreter, thread and lock subsystems, and so on.

The J2SE SDK contains both of the these systems in the distribution, so developers can choose which system they want by specifying -client or -server

Java Related Compilation Summary

 

 

Benchmarking programming languages?
"There are lies, damn lies and Benchmarks".

How can we benchmark a programming language?
We can't - we benchmark programming language implementations.

How can we benchmark language implementations?
We can't - we measure particular programs.

The Computer Language Shootout Benchmarks

The Java is Faster than C++ and C++ Sucks Unbiased Benchmark

Performance Comparison of Java/.NET Runtimes
Linpack Benchmark FAQ

Self Check

  1. Does a person who uses a computer for office work ever run a compiler?
  2. Where is a program stored when it is not currently running?

Answers

  1. No–a compiler is intended for programmers, to translate high-level programming instructions into VM (byte) code.
    Yes–a JVM compiler can compile opcodes into a physical machine code.
  2. In secondary storage, typically a hard disk on a local host or a remote host . Class loaders are used when a program is located on of remote hosts.

The Java Platform

A platform is the hardware or software environment in which a program runs. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other, hardware-based platforms. Most other platforms are described as a combination of hardware and operating system.

The Java platform has two components:

Java Card Technology

 

End-to-End Computing

Java™ Technology Leads the Way…

New application development by language ( Soundview TG, 2001)
 

Freedom

Security

Internet Networking

Three Laws of Computing

Waves of Computing

Many Kinds of Networks and Technologies

Applets on a Web Page

Jmol is a free, open source molecule viewer written in Java. It is a collaboratively developed visualization and measurement tool for chemical scientists.

Features


 

File Hello.java

1 public class Hello
2 {
3    public static void main(String[] args)
4    {
5       // display a greeting in the console window
6       System.out.println("Hello, World!");
7    }
8 }

 

A simple program

 

Syntax: Method Call

 
object.methodName(parameters)

Example:

 
System.out.println("Hello, Dave!");

Purpose:

To invoke a method of an object and supply any additional parameters

Compiling and Running

From Source Code to Running Program


 

Errors

The Edit-Compile-Test Loop

How Will Java Change My Life?

I can't promise you fame, fortune, or even a job if you learn Java. Still, Java is likely to make your programs better and requires less effort than other languages. I believe that Java will help you do the following: