28
Intro to Java Programming International Technology University

Intro to Java Programming

  • Upload
    sanura

  • View
    75

  • Download
    0

Embed Size (px)

DESCRIPTION

Intro to Java Programming. International Technology University. Contents. Java Introduction Java Features How Java Differs from other OO languages Java and the World Wide Web Java Environment Build your first Java Program. Java Introduction. - PowerPoint PPT Presentation

Citation preview

Page 1: Intro to Java Programming

Intro to Java Programming

International Technology University

Page 2: Intro to Java Programming

Contents Java Introduction Java Features How Java Differs from other OO

languages Java and the World Wide Web Java Environment Build your first Java Program

Page 3: Intro to Java Programming

Java Introduction Originally created for consumer

electronics (TV, VCR, Freeze, Washing Machine, Mobile Phone).

Java - CPU Independent language Internet and Web was just

emerging, so Sun turned it into a language of Internet Programming.

It allows you to publish a webpage with Java code in it.

Page 4: Intro to Java Programming

Sun white paper defines Java as:

Simple and Powerful Safe Object Oriented Robust Architecture Neutral and Portable Interpreted and High Performance Threaded Dynamic

Page 5: Intro to Java Programming

Java is Compiled and Interpreted

Text Editor Compiler Interpreter

Programmer

Source Code

.java file

Byte Code

.class file

Hardware and Operating System

javac

JavaNetscapeInternet Explorer

Page 6: Intro to Java Programming

Compiled Languages

Text Editor Compiler linker

Programmer

Source Code

.c file

Object Code

.o file

gcc

Executable Code

a.out file

Page 7: Intro to Java Programming

Total Platform Independence

JAVA COMPILERJAVA COMPILER

JAVA BYTE CODEJAVA BYTE CODE

JAVA INTERPRETERJAVA INTERPRETER

Windows XP Macintosh Solaris Windows NT

(translator)

(same for all platforms)

(one for each different system)

Page 8: Intro to Java Programming

Architecture Neutral & Portable

Java Compiler - Java source code (file with extension .java) to bytecode (file with extension .class)

Bytecode - an intermediate form, closer to machine representation

A interpreter (virtual machine) on any target platform interprets the bytecode.

Page 9: Intro to Java Programming

Architecture Neutral & Portable

Porting the java system to any new platform involves writing an interpreter.

The interpreter will figure out what the equivalent machine dependent code to run

Page 10: Intro to Java Programming

Class Environment

Core ClasseslanguageUtilitiesInput/OutputLow-Level NetworkingAbstract Graphical User Interface

Internet ClassesTCP/IP NetworkingWWW and HTMLDistributed Programs

Page 11: Intro to Java Programming

Overlap of C, C++, and Java

C

C++

Java

Page 12: Intro to Java Programming

Java better than C++ ?

No Typedefs, Defines, or Preprocessor No Global Variables No Goto statements No Pointers No Unsafe Structures No Multiple Inheritance No Operator Overloading No Automatic Coercions No Fragile Data Types

Page 13: Intro to Java Programming

Java Applications We can develop two types of Java

programs:

Stand-alone applications Web applications (applets)

Page 14: Intro to Java Programming

Applications vs. Applets

Different ways to run a Java executable are:Application- A stand-alone program that

can be invoked from command line. A program that has a “mainmain” method

Applet- A program embedded in a web page, to be run when the page is browsed. A program that contains no “main” method

Page 15: Intro to Java Programming

Applets vs. Applications

Application –Executed by the Java interpreter.

Applet- Java enabled web browser.

Page 16: Intro to Java Programming

Execution of Applets

HelloHelloHello Java

<app=“Hello”>

4APPLET

Development “hello.java”

AT SUN.COM

The Internet

hello.class AT SUN’S

WEB SERVER

2 31 5

Create Applettag in

HTMLdocument

Accessing from

itu.edu

The browser createsa new

window and a new thread

and then runs the

code

Page 17: Intro to Java Programming

Power of Java and the Web Deliver applications, not just

information Eliminate porting Eliminate end-user installation Slash software distribution costs Reach millions of customers -

instantly

Page 18: Intro to Java Programming

Java Development Kit

javac - The Java Compiler java - The Java Interpreter jdb- The Java Debugger appletviewer -Tool to run the applets javap - to print the Java bytecodes javaprof - Java profiler javadoc - documentation generator

Page 19: Intro to Java Programming

Let us Try Out

Building your first Java Program

Page 20: Intro to Java Programming

Hello World

// hello.java: Hello World programclass HelloWorld { public static void main(String args[]) { System.out.println(“Hello World”); }}

Page 21: Intro to Java Programming

Program Processing

Compilation# javac hello.javaresults in HelloWorld.class

Execution# java HelloWorldHello World#

Page 22: Intro to Java Programming

Simple Java Applet

//HelloWorld.java import java.applet.Applet;import java.awt.*;

public class HelloWorld extends Applet {public void paint(Graphics g) { g.drawString (“Hello World !”,25, 25);

}}

Page 23: Intro to Java Programming

Calling an Applet

<HTML><TITLE>HELLO WORLD APPLET</TITLE><HEAD>THE HELLO WORLD APPLET</HEAD><APPLET CODE=“HelloWorld.class” width=500

height=500></APPLET></HTML>

Page 24: Intro to Java Programming

Applet Execution

Using AppletViewer Using Browser

Page 25: Intro to Java Programming

Java on the Web: J2EE

Client Server

JSPsServlets

EJBJDBC

Thin clients Java all “server side”

Page 26: Intro to Java Programming

Windows Users - Install Install JDK 5 (SE), Update 12 Set the Path to include the JDK

Start->Settings->Control Panel->System->Advanced Tab->Environmental Variables

Alter the ‘Path’ variable so that it also contains the path to the Java executable. For example: ;c:\Program Files\Java\jdk1.5.0_12

Reboot the computer Install Java EE SDK 5, Update 3

Page 27: Intro to Java Programming

Mac Users - Install The Java JDK is already installed Install JBoss – EJB Application

Server Install Ant – Build Tool (if not

installed already) Mac instructions for both apps can be found at:

http://developer.apple.com/internet/java/enterprisejava.html

Page 28: Intro to Java Programming

Both Mac and XP Choose and install a Free IDE Eclipse (

http://www.eclipse.org/downloads/)