24
BPJ444: BPJ444: Business Programming Business Programming Using Java Using Java Introduction Introduction Tim McKenna Tim McKenna

BPJ444: Business Programming Using Java Introduction Tim McKenna

Embed Size (px)

Citation preview

Page 1: BPJ444: Business Programming Using Java Introduction Tim McKenna

BPJ444: BPJ444: Business Programming Business Programming

Using Java Using Java IntroductionIntroduction

Tim McKennaTim McKenna

Page 2: BPJ444: Business Programming Using Java Introduction Tim McKenna

IntroductionIntroduction

The Focus of BPJ444The Focus of BPJ444 What is Java?What is Java? The Sun Java 2 PlatformThe Sun Java 2 Platform Getting Started with Java ProgrammingGetting Started with Java Programming The IBM i5, iSeries, AS/400 Java The IBM i5, iSeries, AS/400 Java

PlatformPlatform

Page 3: BPJ444: Business Programming Using Java Introduction Tim McKenna

The Focus of BPJ444The Focus of BPJ444

Java Java programmingprogramming skills (85%) skills (85%) IBM tool and platform (15%)IBM tool and platform (15%)

– IBM WebSphere Development Studio Client for IBM WebSphere Development Studio Client for iSeries which is based on Eclipse IDE. Use iSeries which is based on Eclipse IDE. Use Eclipse.Eclipse.

– IBM iSeries as a database platformIBM iSeries as a database platform preparation for other coursespreparation for other courses

– DOMINO, iSeries Practicum, Web DOMINO, iSeries Practicum, Web Services Architecture Services Architecture

Page 4: BPJ444: Business Programming Using Java Introduction Tim McKenna

What is Java?What is Java? invented at Sun Microsystems in 1991 invented at Sun Microsystems in 1991

by James Gosling, a Canadian.by James Gosling, a Canadian. named the new language “Oak” after named the new language “Oak” after

looking out his office windowlooking out his office window later renamed “Java” following a later renamed “Java” following a

trademark searchtrademark search 1994: hey, this Web thing is way cool1994: hey, this Web thing is way cool May 23, 1995: Java and HotJava browser May 23, 1995: Java and HotJava browser

officially announcedofficially announced JDK 1.0 available November, 1995JDK 1.0 available November, 1995

Page 5: BPJ444: Business Programming Using Java Introduction Tim McKenna

What is Java?What is Java?

Java starts with C/C++ language form:Java starts with C/C++ language form:– syntax, semantics, expressionssyntax, semantics, expressions

Java improves C/C++:Java improves C/C++:– no pointers in Java … hoorayno pointers in Java … hooray– no memory manglement no memory manglement malloc/freemalloc/free– Java does automatic “garbage collection”Java does automatic “garbage collection”– strings are objects, not null-terminated arraysstrings are objects, not null-terminated arrays– int, long, float int, long, float are the same everywhereare the same everywhere– out of bounds array index checking at run timeout of bounds array index checking at run time

Page 6: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java cleans up C++Java cleans up C++ no operator or keyword overloadingno operator or keyword overloading

– things mean what you think they meanthings mean what you think they mean no header filesno header files

– Java uses classes and packagesJava uses classes and packages no multiple inheritanceno multiple inheritance no standalone functionsno standalone functions

– in Java, all methods belong to a classin Java, all methods belong to a class no preprocessorno preprocessor

– everything is in the Java languageeverything is in the Java language no structures or unionsno structures or unions

– everything is in a classeverything is in a class

Page 7: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java is betterJava is better for Web, business & application for Web, business & application

programming (no memory programming (no memory manglement)manglement)

safer than C & C++ (no pointer stuff)safer than C & C++ (no pointer stuff) rich library of programming featuresrich library of programming features more portable across platformsmore portable across platforms downloadable Java applets can rundownloadable Java applets can run

– in anyin any browser (unlike ActiveX)browser (unlike ActiveX)– safely in the Java security “sandbox”safely in the Java security “sandbox”

(unlike ActiveX)(unlike ActiveX)

Page 8: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java formulaJava formula

Java = C++ Java = C++ – complexity and – complexity and

ambiguityambiguity+ security and + security and

portabilityportability

Page 9: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java is Object OrientedJava is Object Oriented focus is on objects, i.e. classes of thingsfocus is on objects, i.e. classes of things objects have attributes: fields or variables objects have attributes: fields or variables

(data)(data) objects have objects have behaviourbehaviour: methods to act on data: methods to act on data Procedural languages like C or COBOL …Procedural languages like C or COBOL …

– use algorithms to act on data – trusting all other use algorithms to act on data – trusting all other programs to behave properly and not corrupt data.programs to behave properly and not corrupt data.

– data has no control of programs acting on it data has no control of programs acting on it data's only protection is DB constraintsdata's only protection is DB constraints

– data and procedures are structurally data and procedures are structurally independent but functionally dependentindependent but functionally dependent

Page 10: BPJ444: Business Programming Using Java Introduction Tim McKenna

The Sun Java 2 PlatformThe Sun Java 2 Platform Java Java mantramantra: : “write once, run anywhere”“write once, run anywhere”

– the same code runs on any platformthe same code runs on any platform also: run anyalso: run anytimetime

– same code runs on the same platform over timesame code runs on the same platform over time– today on WinXP/Pentium 32bit CISCtoday on WinXP/Pentium 32bit CISC– tomorrow on Win?? & Itanium 64 bit EPICtomorrow on Win?? & Itanium 64 bit EPIC– (this has always been OS/400 strength…(this has always been OS/400 strength…

1979 S/38 *PGM objects run on current iSeries) 1979 S/38 *PGM objects run on current iSeries) criticism: “write once, test/debug everywhere”criticism: “write once, test/debug everywhere”

– with Java 2, this is rarely an issue anymore.with Java 2, this is rarely an issue anymore.– with C++, it is still truewith C++, it is still true

Page 11: BPJ444: Business Programming Using Java Introduction Tim McKenna

The Sun Java 2 PlatformThe Sun Java 2 Platform- how does it do that?- how does it do that?

use of use of bytecodebytecode to achieve portability to achieve portability– .java source code ‘compiled’ into .class bytecode.java source code ‘compiled’ into .class bytecode– virtual assembler languagevirtual assembler language

Java Virtual Machine interprets standard Java Virtual Machine interprets standard bytecode and runs it on a specific platformbytecode and runs it on a specific platform

OS/hardware platform implements its own JVMOS/hardware platform implements its own JVM– e.g. OS/400, Wintel, Mac, Unix, Linuxe.g. OS/400, Wintel, Mac, Unix, Linux– each have different Java Virtual Machines (JVM) to each have different Java Virtual Machines (JVM) to

run standard bytecode on their local OS / hardwarerun standard bytecode on their local OS / hardware– some just-in-time compilation for speedsome just-in-time compilation for speed– performance issues everywhere except OS/400performance issues everywhere except OS/400

Page 12: BPJ444: Business Programming Using Java Introduction Tim McKenna

The Sun Java 2 JDKThe Sun Java 2 JDK

terminologyterminology– JRE: Java Runtime EnvironmentJRE: Java Runtime Environment– JDK: Java Development KitJDK: Java Development Kit– SDK: Software Development Kit (old name for JDK)SDK: Software Development Kit (old name for JDK)

Java compiler:Java compiler: > javac > javac classfileclassfile.java.java Java interpreter (JVM)Java interpreter (JVM) > java > java classfileclassfile other command-line tools (e.g. javadoc, jar)other command-line tools (e.g. javadoc, jar) versions: 1.0, 1.1, versions: 1.0, 1.1, 1.21.2, 1.3, 1.4, 1.5, 1.3, 1.4, 1.5

Page 13: BPJ444: Business Programming Using Java Introduction Tim McKenna

How to install Java 2 JDK?How to install Java 2 JDK?

http://http://java.sun.comjava.sun.com– link: J2SE Core Javalink: J2SE Core Java

common problems in installationcommon problems in installation– path name (“command unknown”)path name (“command unknown”)– classpath name (“class file not found”)classpath name (“class file not found”)– upper/lower case namesupper/lower case names

solutions: JDK documentation, General solutions: JDK documentation, General Information, Information, Installation NotesInstallation Notes

see BPJ444 web site for installation see BPJ444 web site for installation notesnotes

Page 14: BPJ444: Business Programming Using Java Introduction Tim McKenna

How to code, compile and run How to code, compile and run a Java program?a Java program?

Java 2 JDK Environment (Windows Platform)Java 2 JDK Environment (Windows Platform) notepad or TextPad: type in Java source codenotepad or TextPad: type in Java source code compile source code:compile source code: > > javacjavac HelloWorld.java HelloWorld.java run program:run program: > > javajava HelloWorld HelloWorld

Eclipse: create a project, enter code (with Eclipse: create a project, enter code (with assistance), save a file (auto compiled), run from assistance), save a file (auto compiled), run from inside Eclipse…inside Eclipse…it's an Integrated Development Environmentit's an Integrated Development Environment

Page 15: BPJ444: Business Programming Using Java Introduction Tim McKenna

Getting Started with Java Getting Started with Java ProgrammingProgramming

Two Examples: Two Examples: a Java a Java applicationapplication and a Java and a Java appletapplet

The Anatomy of a Java ApplicationThe Anatomy of a Java Application Java Applets and the InternetJava Applets and the Internet The Anatomy of a Java AppletThe Anatomy of a Java Applet The Java Tutorial (online): The Java Tutorial (online): http://java.sun.comhttp://java.sun.com see the see the Introduction web pageIntroduction web page

Page 16: BPJ444: Business Programming Using Java Introduction Tim McKenna

DefinitionsDefinitions

package: package: a group of related classesa group of related classes– sometimes called a "library" of classessometimes called a "library" of classes

Java API: Application Program Java API: Application Program InterfaceInterface– Java's many packages with many capabilitiesJava's many packages with many capabilities– all documented with javadoc utility into HTML all documented with javadoc utility into HTML

pagespages base package “java.lang” is base package “java.lang” is

automatically imported into every automatically imported into every Java programJava program

Page 17: BPJ444: Business Programming Using Java Introduction Tim McKenna

Some ExamplesSome Examples

a Java a Java applicationapplication (console-based) (console-based)– HelloWorld.javaHelloWorld.java– HelloWorld2.javaHelloWorld2.java– command line tools: javac, javacommand line tools: javac, java

a Java a Java appletapplet– HelloWorldApplet.javaHelloWorldApplet.java– HelloWorlddemo2.htmlHelloWorlddemo2.html– tools: javac, appletviewer tools: javac, appletviewer

Page 18: BPJ444: Business Programming Using Java Introduction Tim McKenna

The Anatomy of a Java The Anatomy of a Java ApplicationApplication

Example: HelloWorld.javaExample: HelloWorld.java three types of commentsthree types of comments

– line, multi-line, and javadocline, multi-line, and javadoc keywords: public, static, privatekeywords: public, static, private use of API specificationuse of API specification

– names: names: System, out, printlnSystem, out, println– package name: package name: java.langjava.lang

the javadoc command:the javadoc command:– > javadoc HelloWorld.java> javadoc HelloWorld.java– > runJavadoc.bat (in Week01.zip) will > runJavadoc.bat (in Week01.zip) will

organize and document all .java files in a organize and document all .java files in a directorydirectory

Page 19: BPJ444: Business Programming Using Java Introduction Tim McKenna

The Anatomy of a Java AppletThe Anatomy of a Java Applet

a Java program that runs in a web page subject a Java program that runs in a web page subject to security restrictionsto security restrictions

Example: Example: HelloWorldApplet.java HelloWorldApplet.java keyword: import keyword: import use of API specificationuse of API specification

- names: - names: java.applet.Applet, paintjava.applet.Applet, paint names: packages, classes, method, objectsnames: packages, classes, method, objects

tools: appletviewer, Firefoxtools: appletviewer, Firefox

Page 20: BPJ444: Business Programming Using Java Introduction Tim McKenna

IBM i5, iSeries, AS/400 IBM i5, iSeries, AS/400 Java PlatformJava Platform

Sun JDK compliantSun JDK compliant the QShell Interpreter and Integrated File the QShell Interpreter and Integrated File

System (IFS) – simulated UNIX environmentSystem (IFS) – simulated UNIX environment AS/400 Toolbox for JavaAS/400 Toolbox for Java

– Java classes developed by IBM to access OS/400 Java classes developed by IBM to access OS/400 resourcesresources

performance optimizationperformance optimization– the JVM is integrated with OS/400 in microcodethe JVM is integrated with OS/400 in microcode– OS/400 Java commands: CRTJVAPGM, RUNJVAOS/400 Java commands: CRTJVAPGM, RUNJVA

Page 21: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java and IBM eServer iSeriesJava and IBM eServer iSeries Approach 1: use of a workstation (or desktop)Approach 1: use of a workstation (or desktop) locally develop Java code, e.g. using IBM WDSClocally develop Java code, e.g. using IBM WDSC ftpftp the Java code to the IBM iSeries server the Java code to the IBM iSeries server

Integrated File System e.g. /bpj444demoIntegrated File System e.g. /bpj444demo use iSeries QShell (STRQSH) to compile & run:use iSeries QShell (STRQSH) to compile & run:

cd /bpj444democd /bpj444demoset CLASSPATH . set CLASSPATH . javac HelloWorld2.javajavac HelloWorld2.javajava HelloWorld2java HelloWorld2

Page 22: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java and IBM eServer iSeriesJava and IBM eServer iSeries

Approach 2: Use of IBM Operations Approach 2: Use of IBM Operations NavigatorNavigator

workstation development of Java codeworkstation development of Java code “ “drag and drop” drag and drop”

– from Windows Explorer to Operations from Windows Explorer to Operations NavigatorNavigator

– use an iSeries Integrated File System directoryuse an iSeries Integrated File System directory RIGHT click on HelloWorld2.java RIGHT click on HelloWorld2.java

to compile the codeto compile the code RIGHT click on HelloWorld2.class RIGHT click on HelloWorld2.class

to run the codeto run the code

Page 23: BPJ444: Business Programming Using Java Introduction Tim McKenna

Java and IBM eServer iSeriesJava and IBM eServer iSeries

Approach 3: green screen server Approach 3: green screen server environmentenvironment

use SEU or EDTF to build Java programsuse SEU or EDTF to build Java programs use CL commands to compile and run Java use CL commands to compile and run Java

programs. e.g.programs. e.g.===> ===> RUNJVA CLASS(HelloWorld2) RUNJVA CLASS(HelloWorld2)

CLASSPATH('/bpj444demo')CLASSPATH('/bpj444demo')===> GO CMDJVA===> GO CMDJVA

Page 24: BPJ444: Business Programming Using Java Introduction Tim McKenna

WebSphere Development WebSphere Development Studio Client for iSeriesStudio Client for iSeries

build on Eclipse technologybuild on Eclipse technology– open source IDE: open source IDE: www.eclipse.orgwww.eclipse.org

tool for developing Java, etc. codetool for developing Java, etc. code built-in special support for OS/400 built-in special support for OS/400

JavaJava - AS/400 Toolbox for Java- AS/400 Toolbox for Java- Enterprise Toolkit for AS/400- Enterprise Toolkit for AS/400

www.ibm.com/software/ad/wdt400/www.ibm.com/software/ad/wdt400/