How I may help
LinkedIn Profile Email me!
Call me using Skype client on your machine

Reload this page The Java Platform

This page provides the background on how Java programs are created and executed — companions to pages on Exception Handling, Java IO, JVM GC, & JDBC, J2EE, and comparing threading & Logic.

In 2003, Java replaced C++ in the the College Board's Advanced Placement Computer Science exams.

Over 100 high schools are using "Java Au Naturel" free from Dr. William C. Jones Jr. at Central Connecticut State University.

 

Topics this page:

  • Summary, Installation
  • Version History
  • Executables
  • Documentation
  • .java Source for Apps, Applets, Servlets
  • JVM Detection
  • Java IDEs, Debugging
  • Programming Utilities
  • Instances, Packages, Libraries
  • Methods, Interfaces, Subclass Inheritance, Identifiers, Modifiers
  • Collections
  • Resources
  • Your comments???

  •  

    Site Map List all pages on this site 
    About this site About this site 
    Go to first topic Go to Bottom of this page


    Newsgroup: comp.lang.java

    A website external to this site Roedy Green's Java Glossary

    Set screen Summary

      A website external to this site What is the Java Platform?

      An intermediate JVM makes the Java language device independent because each JVM on the various platforms interpret byte-code the same way.

      To optimize Java software performance, the Version 4 Release 2 Operating System on IBM's AS/400 computers has JVM integrated beneath their Machine Interface (MI). On AS/400 V4R2's, Java classes can be run through a "transformer" to compile Java class files into AS/400-dependent object code using the AS/400 Developer Kit (JDK 1.1.4).

      Microsoft added Java language support after the initial release of their .NET (dot NET) initiative. The Microsoft Visual J#.NET Redistributable Package 1.1 is installed as a separate program.

      Microsoft's does not make use of J# (pronounced J Sharp) code like other Java implementations. Microsoft has its own compilation and run-time architecture for .NET programsanother page on this site.

     

      Java compile workflow
    1. Code:  Java programmers write source code in text files (perhaps using an IDEon this page), then saved with a file suffix of .java.

      Java considers all files residing together in a specific project directory/folder part of a custom package of files containing localized resource messages, images, sounds, GUI forms, HTML code, query definitions, parameters (data paths to resources), and third-party library classeson this page.

      Each source file must contain an import command to specify each external packageon this page it references, except for the java.lang library automatically included by the compiler.

    2. Compile:  Class files are built from source files by a Java compiler provided with the JDK or with an IDE. Byte-code is called neutral intermediate code because its syntax is conceptually between human(nerd)-readable source and low-level machine code. Discussions about a Java "class" refer collectively to the byte-code and the source code from which it is derived.

    3. Correct Syntax Errors:  The compiler issues messages to the programmer if the source code does not meet Sun's Java Language Specifications 2nd Edition. Many programmers apply additional tools to source code.

      If the compiler strictly follows Sun's Java Virtual Machine Specification, it should create byptecode that is usable by a Class Loader within any Java Virtual Machine (JVM) running on a target client's machine with a variety of operating systems (Windows, UNIX, Linux, etc.).

    4. Invoke:  Running in a “soft” universal abstraction layer, the JVM dynamically (as needed) loads Java Core APIs and custom application classes. This is called just-in-time compilation.

      Before Java applets can be linked from an Internet browser or Java applications invoked from the client machine's file system, the JVM must be installed on the client machine.

      Reminder The JVM uses port 5901.

    5. Behind the scenes, A Bytecode Verifier detects whether the bytecode violates Java security restrictions and other run-time checks.

    6. Execute:  At run-time, the Interpreter translates bytecode into low-level machine language instructions optimized to the specific capabilities of the client machine (multiple processors, etc.). The intrepreter also frees memory automatically by performing garbage collectionanother page on this site.

    7. Unit Test, debug logic errors, and Tune performance using profilers other utilities.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Java Version History

      Release Number Comments Release Date # of
      Packages
      “Oak” James GoslingA website external to this site, in Sun MicrosystemsA website external to this site' “Project Green”webpage article, develops a new programming language that is small, secure, and portable enough to control, connect, and interact with “smart” consumer devices such as toasters, water heaters, and TVs. 1987
      Java 1.0a2 (alpha) First introduced by Sun Microsystems as “the universal programming language designed for the Internet”. March 1995
      Java 1.0   January 1996 212 classes in 8 packages
      Java 1.1 This major revision gave us an enhanced ClassLib containing Java Beans software components, Reflection of the fields, constructors, and methods of a Java object at run time, Serialization methods to save and restore object state, Remote Method Invocation (RMI) of objects on different machines, JDBC to SQL, Java Native Interface with code libraries written in other languages, digital signatures, message digests, access control lists, and key generation. Unicode, and a new delegation model for responding to events. The Date class was deprecated. February 1997 504 classes in 23 packages
      Java 1.2 This second major revision to the Java language specification is commonly referred to as Java 2. It now also referred to as J2SE (Standard Edition) when Java 2 Enterprise Edition appeared. This revision added a javac Just-In-Time (JIT) compiler with jdb and javadoc, plug-ins to direct browsers to use a Java Runtime Environment (JRE) rather than the browser's JVM, a CORBA ORB with an idltojava compiler, collections (linked lists, dynamic arrays, and hash tablefsections), Swing user interface with 2D, audio, and Accessibility components, Security Policy files, Digital certificates and signed Java Archive (JAR) files. v1.2 implements a new model for threadsanother page on this site December 1998 1,520 classes in 59 packages
      Java 2 EE The Java 2EE (Enterprise Edition) initiative order to move from Web publishing to Web enterprise information management, the Java 2 Standard Edition (J2SE) was augmented with a multi-tiered approach, separation of user interface and business logic, a global security model, a global transaction management model, and so on. Java 2 Enterprise Edition (J2EE) extended J2SE to enable development of enterprise information systems. Java 2 Platform, Micro Edition (J2ME) is geared toward development of applications for small devices (such as cell phones, pagers and Personal Digital Assistants). June 1999 -
      JDK 1.3 Also called Java 2 because it is an upgrade to Java 1.2 under the Java 2 platform.
      1.3.1_15 is the final release for this version.
      April 2000 1,842 classes in 76 packages
      Java 1.4 Provides regular expression support, Assertions, Wrapper Objects another page on this site, and hashCodes. Feb. 6, 2002 2,991 classes in 135 packages
      Java 1.5
      aka
      J2SE 5.0
      aka
      "Tiger"
      JMX for diagnostics Downloads and Errata Download includes Doug Lea's util.concurrent library, as explained by Brian Goetz Changes include Generics, Metadata, Autoboxing/unboxing, Enumerations, Variable-length arguments (varags), static import, formatted I/O. Sep. 30, 2003 3,500 classes
      Java 1.6
      aka
      JDK 6.0
      - Dec 11, 2006 -
      Java 1.7
      aka
      JDK 7.0
      Code name "Dolphin" July 28, 2010 Oracle acquired Sun in 2010.
      Java 1.8
      aka
      JDK 8.0
      Code name ? 2013 -

      Many say that the next jump in the Java language is the Scala language, created by the developer of Java Generics, Martin Odersky (Professor at EPFL in Lucerne, Switzerland). Scala uses the same compilation model as Java and .NET (separate compilation, dynamic class loading, etc.), but features functional programming concepts critical for tackling concurrency to achieve scalability.

      Set screen Downloads

      Apache Harmony and Open JDK are open-source implementations of Java.

      Rather than going to the Current Release (6.0), go to
      Previous Release (5.0)

      • Download the JRE version to just execute Java plain Java
      • Download the JDK version to also compile plain Java
      • Download the J2EE version to also work with JBoss.

      tool This Java Applet page tells you what version of Java is running on your browser

      download Get the Java2 SDK, Standard Edition and Create Your First Java Application
      download The IBM Java2 SDK (part of the Websphere SDK for Web Services v5.1 using the Eclipse IDE) is still at Java 1.3.1 for Windows and up to 1.4.1 for Linux

      Caution! One of the frustrations with Java is its backward and upward compatibility. Code that works in one version of Java may not work in a newer version. , as shown in this Errata to the Deital book A website external to this site


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen JavaSoft/MS J++ Executables

     

    IDEs have their own compilers and tools,

    Name of ExecutableJavaSoftMS J++
    SQLJ Translator sqlj.exe -
    Console based Compilerjavac.exe
    on-line
    jview.exe
    GUI Interpreter/Compilerwjava.exewjview.exe
    Debuggerjdb.exe-
    Documentation extractor javadoc.exe --
    Stand-alone applet test bed invokes HTML calling applets, ignoring the display of HTML related tags. AppletViewer
    .exe
    --
    Oracle Loader loadjava--
    Runtime Bytecode JVM java.exe--
    J2EE Runtimeanother page on this site runclient.exe--
    in-process DLL used with IE and COM componentsn/amsjava.dll

    tool UMLGraph by Diomidis Spinellis creates UML class diagrams from Java code using AT&T's Graphviz open-source graph drawing software.


    Go to Top of this page.
    Next topic this page

    Set screen Java Documentation


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen .Java Class Source Files and Compilation

      A Java program module is either or both an applicationon this page or an appleton this page. An application that runs on a server (rather than on clients) are called servletson this page.

      (type)

      Set screen Java Stand-Alone Applications

      Java application programs are called stand-alone because they can be invoked from the operating system by using just the Java interpreter.

        java myapp.exe -classpath .;c:\sdk1.4.1\src.jar;c:\sdk1.4.1\lib\tools.jar;c:\sdk1.4.1\lib\dt.jar;

      Idea Name application program source files with suffix APP.java. In the Microsoft world, file extensions trigger a program to be invoked. But in UNIX, the class file to be run is a parameter and Java automatically appends it for you. So remember NOT to type “.class” when executing java classes. If you do, you will get a nasty message such as:

        Exception in thread "main" java.lang.NoClassDefFoundError

      Examples of how applications can use capabilities of the JRE (Java Run-time Environment):

      1. A TCP/IP Finger program which obtains information about users on remote machines.
      2. A Monitor which listens for client requests, such as the database Service Connection Manager.


      // Sample app:
      public static class welcomeAPP { }
       
      Custom applications class files invoked by the Java run-time is called the controlling class because it controls other classes and methods defined in the module. The JRE always invoke custom applications by first calling the module's “main” method. So the main method must be defined with a signature which consists of the "String[] args" whether or not the program actually refers to the string array argument provided upon invocation. The signature of a method also has modifier keyword void to indicate that the method will not return a value and class access keyword public to indicate that other classes can call its methods and static because the main method is a class method and thus executed without constructing an instance.

      args[0] is the first argument passed into from the command line.

      Set screen Java Applets

      Applets are named as a dimunitive of "App" because they don't need a hook to the command console that the modifier “main()” provides. If you try to run an applet from the command console, you will get error Exception in thread "main" java.lang.NoSuchMethodError: main

      Applets run within an internet browser (or AppletViewer during debugging). They are called from a web page using the "hooks" provided by being a subclass derived from the JApplet super (base parent/ancestor) class.

      Idea Name applet source files with suffix APPLET.java, such as “HelloAPPLET.java”.

      import javax.swing.JApplet; // superclass subpackage
      import java.awt.Graphics; // core package with paint.

      public class HelloAPPLET extends java.applet.JApplet {

        public void paint ( Graphics g ) {
          String strText = getParameter("str1");
          int intVar1 = Integer.parseInt(getParameter("num1"));
          super.paint ( g ); // g inherits a version of the paint super method
          g.drawString ( strText, 25, 25 ); // bottom left coordinates
        }
      }

      The java.applet package contains the Applet class which has abstract methods init, start, paint, stop, and destroy.

      <html>
      <applet code="HelloAPPLET.class" name="HelloApplet" alt="hover"
      archive="HelloAPPLET.jar, another.jar"
      width="300" height="45" /* applet window size in pixels. */
      vspace="4" hspace="4" >
      <param name="str1" value="Hello">
      <param name="num1" value="3">
      </applet>
      <html>
      Applet classes are called by a special HTML tag within web pages. This example uses a .jar archive file for faster download.

      Reminder There are no commas between arguments.

      To dynamically size and resize the applet on the screen, add this Javascript.

      The Name= parameter is the handle used by other applets to communicate with it, using this code:

      getAppletContext().getApplet("receiver")

      To flush the class cache during debugging, click Shift-Reload in the browser.

      If an old browser tries to load an applet containing a method for a newer JDK it doesn't support, a NoSuchMethodError exception is thrown. So applets should anticipate this exception and provide an alternative method.

      Set screen Java Servlets

      J2SE within J2EE Java Servlets are server-side components, so they don't have/need a graphical user interface. They are used to provide secure web-based access to data (via JDBC), support facilities such as search engines, and dynamic generation of web pages back to web browser clients. They are invoked by a HTML PUT request in an HTML FORM, typically to a file with a .jsp extension. The Java Servlet API is a Standard Java Extension API as an add-on package.

      Servlet code use the service() method to to handle Servlet requests.

      JSP Resource Index


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Java Virtual Machine Detection

      Compiled java class files are invoked by a browser processing HTML code such as this:

        <html><head>
          <OBJECT CLASSid="clsid:08B0E5C0-4FCB-11CF-AAA5-00401C608500" width=0 height=0 CODEBASE="http://www.microsoft.com/isapi/redir.dll?prd=JAVAVM&pver= 5.00.2910&ar=MSVISUALJ#Version=5,0,2925"> </OBJECT>
        </head><body>
          <APPLET CODE="BirthDayLET.class" width=300 height=70>
          <PARAM name="Person" value="Jerry">
          </APPLET>
        </body></html>

      Reminder If you use IE to hit a web page with Java Applet, but you do not have a JVM installed, you will see screen capturedthis screen


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen The Microsoft JVM

      Windows Me, 200X, and XP, because of System File Protection features, can only update their JVM by installing entire Service Packs from Microsoft.

      The A website external to this site JVM on Microsoft Windows machines is not compatible with the Sun JVM. (The "Java" supported by Microsoft's .NET runtimeanother page on this site does not recognize bytecode)

      When a Sun VM is installed, it de-selects the Microsoft VM.

      However, some applications (such as tree-controls and Rational RUP) were written for and thus need the Microsoft VM enabled. To allow RUP to find the Microsoft VM in a way that doesn't prevent use of the Sun VM by other apps:

      1. Open Internet Explorer. 2. Select Tools->Internet Options->Advanced tab. 3. Scroll down to the “Java (Sun)” and “Microsoft VM” sections. 4. De-select the checkbox beside the Java option. 5. Select the checkbox beside “JIT compiler for virtual machine enabled (requires restart)”. 6. In Start > Settings > Control Panel > double-click Java Plug-in > Browser tab, uncheck "Microsoft Internet Expolorer" under the text "Java(TM) Plig-in will be used as the default Java Runtime in the following browser(s):", then click the Reset button.

      Uninstalling the MS JVM

      Sleasy software such as CoolWebSearch (CWS) infect Windows machines through the ByteVerifier bug in the Microsoft Java Virtual Machine. Microsoft does have a patch for this vulnerability that is included in Windows XP SP1a.

      Since Microsoft no longer supports its JVM, Windows users should remove the MS Java VM

        RunDll32 advpack.dll,LaunchINFSection java.inf,UnInstall

      After you reboot:

      1. Delete the java folder within \%systemroot% (such as WINNT or WINDOWS).
      2. Delete configuration file java.pnf from folder \%systemroot%\inf
      3. Delete compilers jview.exe and wjview.exe from folder \%systemroot%\system32

      Run Regedit to find and delete:

      1. The HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft \Java VM registry subkey
      2. The HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft \Internet Explorer \AdvancedOptions \JAVA_VM registry subkey (to remove the Microsoft Internet Explorer (IE) options)


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Compiling Packages, Classpath, Package Import

      The compiler creates byte-code files with the name of the java file and file extension ".class". Additional files appended with the program name and "$.class" are created for each public class.

      IBM provides its Jikes compiler as a faster replacement to Sun's compiler.

      Sun's compiler uses a DOS command-line interface to compile a Java class file "pgm1" into byte code:

        cmd c:\jdk141\bin\java pgm1 -classpath .;c:\... -verbose -deprecated

      The Sun 1.4 Java compiler's run parameters are:

        Usage: javac <:options> <:source files>
        where possible options include:
          -g                        Generate all debugging info
          -g:none                   Generate no debugging info
          -g:{lines,vars,source}    Generate only some debugging info
          -O                        Optimize; may hinder debugging or enlarge class file
          -nowarn                   Generate no warnings
          -verbose                  Output messages about what the compiler is doing
          -deprecation              Output source locations where deprecated APIs are used
          -classpath <:path>         Specify where to find user class files
          -sourcepath <:path>        Specify where to find input source files
          -bootclasspath <:path>     Override location of bootstrap class files
          -extdirs <:dirs>           Override location of installed extensions
          -d <:directory>            Specify where to place generated class files
          -encoding <:encoding>      Specify character encoding used by source files
          -target <:release>         Generate class files for specific VM version
        
        Add the -g parameter to receive line numbers accompanying a stack trace when an exception is thrown.

      Similar to C-language .h header files, packages must first be declared using the import command such as:

        import java.io.*;

      The classes loaded are shown during compile if the -verbose   parameter is added. java.lang is not listed because JVM automatically loads it.

      A package statement in source code is compiled with the -d option. Any features of the package's classes not explicitly marked with an access modifier will be accessible to all the members of the package.

      Common causes for error messages from various Java Compilers are webpage article described at this site. Some Java compilers, such as tool IBM Jikes (written by common-source contributors in C++ for Windows, Linux, etc.), may issue more descriptive messages.

      Set screen SQL Within Java (SQLJ)

      Oracle8i SQLJ Developer's Guide and Reference Release 2 (8.1.6)

      Set screen Running Java Program From Within Oracle

      A java program can be executed within Oracle using these steps from Experts-Exchange:

      1) Create a java source file. For example, file JavaProc.java

        class JavaProc {
        public static void main(String[] arg_in) {
           system.out.println("Your input is : " + arg_in[0]);
         }
        }

      2) Load the .java file into the database. For example, using the default scott schema's password tiger and the OCI driver, resolving external class references at compile time:

        loadjava -oci8 -resolve -u scott/tiger JavaProc.java

      3) Publish the Java code to PL/SQL by creating a PL/SQL wrapper (rather than BEGIN ... END):

        CREATE OR REPLACE PROCEDURE
        javaproc(cmd VARCHAR2)
        AS LANGUAGE JAVA
        NAME 'JavaProc.main(java.lang.String[])
        return java.lang.String';
        /

      4) Execute the procedure from within Oracle PL/SQL

        SQL> set serverout on (to enable use of DBMS_OUTPUT)
        Server Output ON
        SQL> call dbms_java.set_output(2000);  maximum is 1000000 for 1MB 
        Statement processed.
        SQL> exec JavaProc('Hello');
        Statement processed.
        Your input is : Hello
        	

      Instead of granting specific privileges, several roles are available for Java operations: JAVAUSERPRIV (read I/O operations) and JAVASYSPRIV (write IO operations), JAVA_ADMIN, JAVAIDPRIV, JAVADEBUGPRIV

      5) To remove the procedure or function from within Oracle PL/SQL:

        ALTER JAVA -- compile Java source & resolve Java class references.
        DROP JAVA -- drop a named Java library unit


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Compressed .jar .ear .rar Files

      .jar files contain regular java classes.
      .ear files contain J2EE classes.
      .rar files contain J2EE resource adapter classes.

      The classpath environment variable points to the .jar files.

      For efficient downloading of java applets to a Java-enabled Web browser, multiple .class files are compressed together into a single .jar file. Only a single HTTP connection in the communications overhead. This is done using the jar.exe Java archive tool. It is similar to the PKZIP program for MS-DOS developed by Phil Katz. Both use the ZLIB compression library (RFC 1950) A website external to this site

      A listing of files in a jar file include the META-INF/MANIFEST.MF entry for the manifest of files in the file.

      To ensure non-repudiation by the author, Jar files can be signed with a digital certificate issued to the author from a trusted third party CA. Such trusted jar files may be the only files allowed to be downloaded by a local Java security policy.

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Debugging with jde.exe

      For a list of commands:
      > ?

      To set a breakpoint in class file pgm's main method:

      > stop in pgm.main

      To execute until the breakpoint:

      > run

      For a listing of the source at the => position:

      [] list
      cont

      tool Source-code analysis tools find the most obvious flaws in code. Packages include:

      • Coverity (which counts technology giants Cisco Systems and Oracle among its customers)
      • Ounce Labs Prexis 2.0 creates a V-Density™ (vulnerability density) metric on code.
      • Reflective JTune Java performance service from London and Bulgaria.

      According to an April 2004 report from the National Cybersecurity Partnership's Working Group on the Software Lifecycle, which cited an analysis of development methods by the Software Engineering Institute at Carnegie Mellon University:

      “Commercial code typically has anywhere from one to seven bugs per 1,000 lines of code.”

      Coverity's analysis of MySQL found an average of one bug in every 4,000 lines of code.

      Coverity audit of the Linux kernel found 985 flaws in 5.7 million lines of code (less than one flaw in every 10,000 lines of code).

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Java IDEs (Integrated Development Environments)

     

      How IDEs save time:

    1. Auto indentation of code. How else would you identify what causes the compiler to point to the bottom of the program with message "class expected"?
    2. Undo. You could step backward to determine which change caused a problem.
    3. Key shortcuts and toolbars for one click compile and run or return to editor. No exiting, compiling, reinvoking editor.
    4. Auto highlighting by syntax (different colors for comments, class names, variable names, constants, etc.)
    5. Line numbers shown next to each line
    6. Go to last line changed or line in error
    7. Auto save, undo and redo
    8. Integrated check-in/check-out from version control systems such as PVCS from Merant, the Concurrent Versioning System (CVS) from the Cyclic Software/Free Software Foundation, or Borland TogetherSoft Together Control Center
    9. Auto code completion to save typing (mistyping)
    10. Paste of entire block statements, such as if and try/ catch/finally blocks.
    11. Auto completion and choose superclasses and variables from pop-up windows.
    12. Extended find and replace over several files at once
    13. Templates
    14. Wizards
    15. See changes to GUI immediately

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Utilities For Java Source Code

    • Code Formatters:
        tool $129 Jindent formats Java source code according to user-specified switches. This standardizes code from different sources, making diff-tools more efficient.
      • Jtest from Parasoft does static analysis to detect violations of coding standards. It also creates scaffolding, stubs, and test cases for unit-testing.
    • Code Profilers analyze code execution:
      • JProfiler
      • JProbe from Quest (which purchased original developer KL Group) has a Memory Debugger, Profiler, Code Coverage, and Thread Analyzer that pin-points specific lines of code. Their Profiler compares times from two different runs.
      • Optimizeit from Intuitive Systems
      • Visual Quantify from Rational Software
    • PDF publishing
    • Decompilers reverse engineering from byte-code back into source:
    • Java class file obfuscators reduce the size of Java class files while it blocks decompilers.
      • SourceGuard's 4thpass
      • JAMM Consulting's ObfuscatePro
      • Force5's JCloak
     


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Constructor Instantiating Classes; Accessing Methods

      Because Java is an object-oriented (OO) language, Java programmers make use of objects. A class provides a template or blueprint to instantiate ("make") an object (such as a a GUI button, list box, or panel within a window). To create an instance of a publicly accessible class, use the new constructor without a return type:

      JPanel northPanel = new JPanel();

      Default constructors are inserted only if one has not been provided. Instantiation makes available public features (methods, member variables, and properties). In the OO world, it is not data but methods that are the focus of work. So data is obtained by invoking methods (using a dot operator between class and method names):

      Int curLnF = UIManager.getSystemLookAndFeelClassName();

      reminder Names of Classes have a capital initial character, just like primitive data types such as Int, String, etc. because in the OO world a class is a type of data and used the same way.

      Int style; // Integer
      String class_name = "JavaGUI1"; // String object
      label = new JLabel( "This is a Metal look-and-feel", SwingConstants.CENTER );
      northPanel.add( label );

        The adage "A home is a house that has a family and a pet." in Java translates into

      public class Home extends (is a) House {
        (has)
        Family inhabitants
        Pet theCat
      }
      Java programmers create subclasses by extending a parent superclass, such as the JFrame class from the JDK (Java Development Kit):

      public class JavaGUI1 extends JFrame {


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Packages

      uml package Each package provide a scope for access protection by grouping classes for high-level functional cohesion. By providing a name space that helps prevent name clashes, packages help reduce change impact when releasing.

      Java2 SDK

      Each package has defined classes, interfaceson this page, and exceptions.

      When class files are created, they must be placed in a directory hierarchy that reflects their package names.

      reminder Package names should contain all lowercase alphanumeric characters, starting with an internet domain code or two-letter ISO country code such as

        com.entrust....
        com.visigenic.
        com.inprise.vbroker.CORBA.
        com.visigenic.vbroker.IOP.
        com.entrust.toolkit.CertificateSet.class
        com.fourthpass.

        To be sure that each component of a package name hierarchy is a legitimate directory name on all platforms, don't name classes containing a space, forward slash, backslash, or other symbols.

        Idea packages used only during testing not belonging to a production build should be preceded with "test." so that they can be quickly identiifed for exclusion.


    Go to Top of this page.
    Previous topic this page
    Next topic this page
    Set screen
      Version Package Provides classes to ...
      1.0 java.lang.* contain Java language specifications and methods to manipulate Stringsanother page on this site, exceptions, threadsanother page on this site. Included by default during compilation because it is fundamental to the Java language.
      1.2 .ref for reference object capability; .reflect implements runtime discovery of information about an object's class.
      1.1 java.text parse text stringsanother page on this site
      1.0 java.io manage input and output streams to read and write data to strings and flat files.
      1.0 java.util General utility classes to handle globalized date, time, and calendars; use collections; generate random numbers, generic data structures, bit sets.
      1.1 java.util Added support for collections, sets, bags, maps, lists, linked lists, etc.
      1.1 java.util.jar Compress class files into Java Archive (JAR) files for faster applet downloading
      1.0 java.util.zip read and write compressed zip files; Compute Cyclical Redundancy Check (CRC) and Adler Checksums to ensure quality of data transmission.
      1.0 java.net support network access: TCP & UDP sockets, IP addresses and URLs
      1.0 java.awt (Abstract Window Toolkit) designed as bean components to implement user interface windows, dialog boxes, buttons, checkboxes, lists, menus, scrollbars, text fields.
      java.awt.image
      java.awt.font
      java.awt.peer GUI interfaces for platform indepencdence
      1.1 java.awt.event implement user interface using an extensible more efficient
      1.1 java.awt.datatransfer support clipboard
      1.0 java.applet create applets for use by HTML web bowsers
      1.1 java.lang.reflect Language specification's obtain (reflect) meta info describing runtime classes
      1.1 java.beans The JavaBeans architecture to develop reuseable components (much like Microsoft's ActiveX OLE Automation model) .beancontext implement an execution context for beans.
      1.1 java.rmi Remote Method Invocation methods to remotely invoke components across process and network boundaries (similar to Microsoft's COM/DCOM and CORBA). Related classes .dgc .registry .server
      1.1 java.sql connect and interact with relational databases, database structures, and datasets using the JDBC database engine (much like Microsot's ODBC, but in a object-oriented way)
      1.1 java.security Security Architecture to implement and manage digital signatures, keys, certificates, cryptographic keys, access control lists, and guards.
      1.2 javax.accessibility Assistive technologies, such as screen magnifiers and speech recognition to comply with the Federal Rehabilitation Act and Americans with Disabilities Act.
      1.2 java.awt.dnd Drag and Drop
      1.2 javax.swing.* The foundation for the Swing APIanother page on this site. Sub packages include .border .event .plaf .table .text .text.html .text.rtf .tree .undo
      1.2 java.math Its BigDecimal and BigInteger classes perform arbitrary-precision arithmetic functionsanother page on this site
      1.2 org.omg.CORBA.* CORBA.
      1.2 javax.servlet
      javax.servlet.http
      Replaces Common Gateway Interface programs on Web serversanother page on this site.

      The “x” in javax.swing indicates an 'extension" to the core Java libraries not supported by every implementation.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Mo' Class Libraries



    Due to a bug in Communicator, you must hold down the shift key and then click the link to download class files.)

    Java Repositories:

    The Java Applet Rating ServiceA website external to this site ranks applets. Java's Applet homepageA website external to this site list sources for applet code.

    A website external to this site Karl's JavaOnTheBrain.com provides Java games such as Rubik's cube

  • Java Boutique has tutorials.
  • Sun's Developer site.
  • FreeJava has an annotated list of Java applet sources.
  • AS/400 Java Jems

    tool JPowered.com offers menus, charts, and other Java source goodies.


  • Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Methods

      The behavior of a class is determined by its methods.

      Defining a method with the same name as already defined within a class overrides that class. The overriden method must use identical signature (argument types and parameter order and with identical return type). In other words, it is illegal to overload a library method. However, a class can redefine methods with different signatures (overload) methods.

      By industry convention, the main (entry point) class is usually coded at the bottom of its class code source file.

      When a class is specified without a method, the default method is invoked.

      To reference the original (base) method before subclassing or overriding, Java uses the keyword "super" as the first statement of the constructor:

        super.CalculateX( "heading" );

        C# uses "base" instead of "super".

        C++, however, requires explicit specification of the class name because C++ allows multiple inheritance.

      Anything declared inside a method is not a member of the class, but is local to the method.

      A level in the class inheritance hierarchy cannot be bypassed. If three classes, A, B, and C, all define a method m(), and they are all part of a hierarchy-so that B extends A and C extends B-then the method m() in class C cannot directly invoke the method m() in class A.

      Formal computer terminology describes Java as a programming language which passes by value, where methods get copies of their arguments' values and have no access to the original values. When a caller calls a method and execution flows into the method's body, the JVM copies the argument values provided by the caller and gives the copies to the method.

      If the method alters its arguments, the alteration has no effect on the caller.

      The alternative is called passing by reference, where methods work with the caller's data and not with copies,

     

    Harvy and Paul Deitels'
    Fourth Edition for Java 1.3

    The Errata A website external to this site from publisher Prentice Hall Pearson)A website external to this site


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Interfaces of methods in abstract classes

      A class can extend only a single superclass, but can implement any number of interfaces. This is good for programs whose function is to send data from one interface to another.

      An interface contains no implementation -- a semicolon apears in place of the method body. An interface can only have static final constants -- no fields to be instantiated. Like an abstract class, all methods of an interface are implicitly abstract even if the abstract modifier is omitted.

      Classes encapsulate both abstract data types (such as a size, position, date) and their interface, which is a collection (a set) of public methods of a class.

      An interface allows the use of OO polymorphism by providing common method names for all implementations. Classes are abstract because they are defined with no details about how they are implemented, just their types of behaviors and characteristics. An abstract class can only be subclassed, not instantiated.

      Java operates from a model-view-controller (MVC) paradigm. Registered observers are updated on changes to observable objects.

     

    This I think is the best bargain:
    $15 Java in a Nutshell: A Desktop Quick Reference, 3rd Edition
    by David FlanaganA website external to this site
    (O'Reilly: 1999)A website external to this site

    webpage article Marcus Green on the SCJP Objective 2, Declaring classes and variables.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Creating Subclasses by Inheritance


      File singx.java:
      public class Singx extends JFrame {
        Define instance variables...
        public static void main (String args[]) {
          // Member Variables in the heap
          ...
        }
        // Define sub-class (member of pgmX):
        private void method1 () {
          // Local/Automatic Variables in the stack
          ...
        }
      }
      // another public class:
      public class FileIO {
        ...
      }
       
      A "leaf" class has no subclasses.
      A "node" class has subclasses defined by the extends keyword.

      Classes can be nested. Inner classes defined within the context of an outer class definition are called b>member classes. Member classes provide a hidden reference to the context of the outer class instance at the time the inner class was created.

      OuterClass.InnerClass i = OuterClass().new InnerClass();

      Anonymous classes with no name are created from by extending a class or by implementing a simple, well-known interface such as ActionListener.

      btnOK.addActionListener{
        public void actionperformed( ActionEvent evt ) {
          ...
        }
      }

    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Object Identifier Naming & Duration

      The identifiers used to name variables and references include attributes name, data type, size, and value.

      Reminder Identifiers must start with a letter, $ or _ (underline), but not a number.
      Reminder Uppercase and lowercase alphabetic characters are differentiated.

      The state of an object is determined by the values stored in its variables.

      An identifier's duration in memory is also called its lifetime.

      • Member Variables of a class are created (instantiated) when an instance is created by invoking a new constructor. It is subject to accessibility rules and the need for a reference to the object.

        Stored in the heap, member variables are accessible as long as the enclosing object exists They are destroyed when the object is destroyed. The space they consumed are then recovered by Java's garbage collection mechanisms.

      • Automatic Variables of a method are created on entry to the method (when the method is invoked). They exist only during execution of the method, and therefore is only accessible during the execution of that method. Thus, they are also known as local variables. So, local variables have automatic duration.

        Stored in the stack, they must be explicitly initialized before being used (to avoid a compiler error). They are destroyed on exit from the method.

      The keyword this. is used to reference local variables named the same as variables defined at the class instance level. This is not valid for static methods.

      An identifier's scope defines where the identifier can be referenced within a program.

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Modifier Keywords

      The various modifiers can be specified in any order.

      Class Access Visibility Modifier Keywords

      In Java, the availability of a class' features to its subclasses are specified by one (and only one) Access control keyword modifier (public, private, and protected). The “private protected” keyword in JDK 1.0 has been deprecated. The default (also called "package") modifier is assumed when no modifier is stated.

        webpage article Dickbaldwin's Class Access Tutorial uses a three dimensional chart to explain class access rules for object B:
        • members inherited from object A
        • members in the same or different package as object A
        • members of a superclass of object A.

      Listed by scope of access (from least to most restrictive) -- only one can be specified:

      Modifier
      keyword
      Accessible to...NoteUML

      public

      All objects within system. allows other external classes to view the (applet) class or called by any object. It is used with main to establish the scope of access. Only one per class file. +

      default/
      package

      Instances of classes within the same package. allows a variable to be seen within the class, and from elsewhere within the same package, but not from sub-classes that are not in the same package. ~

      protected

      Instances of the implementing class and its subclasses. methods and variables can only be used by code from classes in the same package and to inherited classes. A member designated as protected appears to be public to members of classes which are derived from that class and appears to be private in classes outside its package. #

      private

      Instances of the implementing class. methods and variables can only be used by code from within the same class, not by an inherited class. So top-level (not inner) classes may not be declared private. -

      Java does not support the C++ function to designate a friend of a class which has direct access to all the private and protected members of a member function (method) of another class or a stand-alone function.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

      Set screen Object modifiers

      In addition to keywords main, void, static defined above:
      Object
      Scope
      Modifier
      keyword
      Purpose

      native

      method bodies are found outside the JVM, usually in a library written in C++ or other low-level language. Native method declarations are ended with a semi-colon and not curly braces having no body, indicating that the implementation is not provided in the class.

      abstract

      Abstract classes cannot be instantiated and must be overridden. Abstract functions do not have an implementation. classes and methods are not instantiated by the new constructor so that implementation is deferred to a subclass. The compiler requires a class to be abstract if any of its methods is abstract. However, an abstract class can have non-abstract methods.

      final (sealed)

      defined in a superclass (or interface) a constant specified with an initial value that cannot be changed. Final classes can't be sub-classed (extended) and must be overridden by the implementing class. Such static variables are usually in upper case and referenced by the class name as a prefix. A final variable must have an initial value or may be initialized in every constructor.

      transient

      variables are not stored as part of its object's persistent state. Such objects may implement the Serializable or Externalizable interfaces to have their state serialized and written to destinations outside the JVM by passing the object to the writeObject() method of the ObjectOutputStream class.

      volatile

      variables might be modified asynchronously in multiprocessor environments.

      Set screen Inner Classes

      Class ModifierPurpose

      static

      methods and variables are called class methods and variables because they are associated with the class itself rather than an instance of that class. Methods cannot be declared inside a static block. So static members and variables are referenced by class name rather than instance name. Inside a static method there is no this reference to an instance. Static methods can't be overridden. Static methods, variables, and blocks of code are created only once for all instances to share.

      static inner

      have access to the static members of the enclosing class, even to those that are private. They do not have implicit reference to members of the instances of the enclosing class.

      member inner

      (not static) can access all the members of the enclosing class, even if they are protected or private.

      local inner

      specified within a method definition of the enclosing class. It cannot be declared as static, public, protected, or private. It can access local variables that are specified as final.

      Anonymous inner

      are use just once and not again. They do not have a class name / constructors. They can access final local variables

      Unlike non-static nested classes, static nested classes can be accessed without having an instance of the outer class.
      Static nested classes do not have access to the instance variables and methods of the outer class.

      The synchronized modifier is used to control access to critical code in multi-threaded programs.


    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen Java Developer Resources

     

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Set screen My Own Style Guidelines

      long[] squares;
      squares = new long[200];
      for( int i = 0; i < squares.length; i++ ) {
        squares[i] = i + i;
      }
      	
    1. Follow function names with a space after the parentheses.
    2. Put braces on the same line which starts it.
    3. Indent using two spaces (rather than tabs).
    4. Use ".length" member variable when creating an array.
    5. Each ending brace is on its own line, aligned vertically.

     
    Go to Top of this page.
    Previous topic this page
    Next topic this page

    Portions ©Copyright 1996-2011 Wilson Mar. All rights reserved. | Privacy Policy |

    Related:

  • Exception Handling
  • Java Beans and J2EE
  • RMI & CORBA
  • PATH & CLASSPATH
  • Design Patterns,
  • Data Types, Strings, Escape Characters, Dates, JDBC
  • Programming Logic, Operators, Functions, Threads, AWT/Swing, Events, I/O
  • Applications Development
  • On the web

  • How I may help

    Send a message with your email client program


    Your rating of this page:
    Low High




    Your first name:

    Your family name:

    Your location (city, country):

    Your Email address: 



      Top of Page Go to top of page

    Thank you!