CS 209 Programming in Java #1 Introduction Spring, 2006 Instructor: J.G. Neal 1 Topics CS 209 Target Audience CS 209 Course Goals CS 209 Syllabus - See handout Java Features, History, Environment Java Development Software Information Sources Applications and Applets 2 1
CS 209 Programming in Java Target audience: Designed for students with previous programming experience Ideally the student should have some experience with: Arrays, Functions/procedures, Passing parameters to functions/procedures 3 CS 209 - Course Goals Goals: Learn the Java programming language Learn about the Java Virtual Machine and Java API Learn to design, develop, debug, and run Java programs Web-based Java applets Stand-alone Java applications Learn to use Java development tools Learn to use good principles and practices 4 2
Features of Java Provides for both web-based and stand-alone applications Is totally object-oriented Provides networking capabilities for distributed systems Provides for dynamic interactive programs Simplifies memory management - automatic garbage collection Supports multithreading - concurrent processing Is portable and platform independent; interpreted Programs run on the Java Virtual Machine at runtime Provides for security Very large set of library packages in the Java API Graphics, user interface capabilities, networking, database operations, file manipulations, etc. 5 Some Java History Developed in the early 1990 s at Sun Microsystems Originally called Oak Designed for use in embedded consumer electronic applications Redesigned for developing Internet applications and renamed Java Releases: JDK 1.0, the first Java programming language release, was officially announced in May 1995 JDK 1.1 released in 1997 Java 2 SDK v 1.2 (a.k.a. JDK 1.2), 1998 Java 2 SDK v 1.3 (a.k.a. JDK 1.3), 2000 Java 2 SDK v 1.4 (a.k.a. JDK 1.4), 2002 Java 2 SDK v 1.5 (a.k.a. JDK 1.5), 2004 Java programmer certification program is available from Sun 6 3
JDK Editions Java Standard Edition (J2SE) ** J2SE can be used to develop client-side standalone applications or applets. Java Enterprise Edition (J2EE) J2EE can be used to develop server-side applications such as Java servlets and Java ServerPages. Java Micro Edition (J2ME). J2ME can be used to develop applications for mobile devices such as cell phones. ** This course uses the J2SE 7 The Java Environment Editor Java Program (MyProgram.java) (Source Code File) Java Compiler (javac) Java Bytecode (MyProgram.class) (Compiled File) Interpreter or Java Platform: Java API Java Virtual Machine Interpreter or Java Platform: Java API Java Virtual Machine Interpreter or Java Platform: Java API Java Virtual Machine HW-based Platform (Sun + Solaris OS) HW-based Platform (PC + WIN OS) HW-based Platform (Mac + Mac OS) 8 4
Java Development Software Sun Microsystems, Inc. Java 2 Standard Edition (J2SE) SDK from Sun Microsystems No cost download from the Sun Microsystems website J2SE includes: javac - Compiler for the Java language java - Launcher for execution of Java applications javadoc - API documentation generator appletviewer - Run applets without a web browser jar - Manage Java Archive (JAR) files jdb - Java Debugger javah - C header and stub generator javap - Class file disassembler extcheck - Utility to detect Jar conflicts HtmlConverter - Converts to a new HTML file with tags for invoking the Java plugin among others... 9 Java Development Software Integrated Development Environments (IDEs): NetBeans IDE (http://www.netbeans.org; http://www.sun.com) Eclipse IDE (http://www.eclipse.org) Borland JBuilder (http://www.borland.com) Sun Java Studio (http://www.sun.com) IBM WebSphere (http://www.ibm.com) JCreator (http://www.jcreator.com) BlueJ (http://www.bluej.org) 10 5
Object-Oriented Programming Benefits: Software modularity Information hiding A wealth of well-tested predefined classes, especially the Java API (part of the J2SE) Software reuse Enhanced programmer productivity 11 Object-Oriented Programming Fundamental principle: Encapsulation of data and methods in an object Objects: Real world objects have state (attributes or data) and behavior (actions or operations) A software object maintains its state (attributes or data) in variables and implements its behavior as methods A class: Is a blueprint or template Defines the variables and methods common to all objects of a certain kind An object is an instance of a class Can you give an example? 12 6
Object-Oriented Fundamentals Programs are developed in the form of classes: The conceptual entities/objects that comprise the program Classes are organized into a hierarchy Levels: The higher the level, the more generic The lower the level, the more specific Inheritance: subclasses automatically have the variables and methods of their superclasses Inherited methods can be overridden in a subclass Programmers write their new programs building on the existing Java Class Hierarchy (Java 2 API) Bicycles Mountain Bikes Racing Bikes Tandem Bikes 13 Example Application-Specific Hierarchy Level 1: Employee Level 2: SalariedEmployee HourlyEmployee TemporaryEmployee Level 3: Tier1 Tier2 Tier3 Union NonUnion Category1 Category2 14 7
Type of Java Programs Application - two types Console-based program: Input and output are typically from/to the command prompt window Window-based program: User interaction (input and output) is performed by way of a graphical user interface (GUI) Applet Runs within a web browser (e.g., Microsoft Internet Explorer, Netscape, Mozilla, Opera) Requires an HTML page containing an Applet tag or Object tag that holds the information needed to invoke the applet To view an applet use: Web browser or JDK appletviewer 15 8