Back to the home page of this site
Under Construction This page is very new, unfinished and may contain more inaccuracies than the rest of this site. Last Updated 25 April 1999
 

The Java 2 Exam

 


JDK 1.2 or Java2?

Until its release the Java2 platform was known as JDK 1.2, but I will generally refer to it as Java2.

The Java2 Exam Objectives

The release of the Java2 Certification Exam Objectives was slightly surprising as Sun seems to have made the requirements less specific. This makes it slightly harder to study for, certainly until more people have taken the exam and there is a good idea exactly what areas will be examined. Having said that there is one entirely new objective and feedback is starting to come in from people who have taken the exam. My knowlege of the Java2 exam has been is taken mainly from Ians message group at http://www.woj.com/tech/javacert so thanks for all your postings.

Unmentioned but still included

Just becase a topic is not mentioned in the new Objectives does not mean that it will not come up in the exam, thus although I/O and bit shifting are not mentioned they can still come up. The new objectives contains the following


5)Section Title: Operators and Assignments

  1. Determine the result of applying any operator including assignment operators and instanceof to operands of any type class scope or accessibility or any combination of these.

This might be considered to include the bit shifting operators even though it is not specifically mentioned. I suspect that Sun have a whole bunch of questions that have been created over the last two years and they have simple introduced a few new ones rather than come up with a whole new set of questions. For this reason you may be well advised to study the obejctives for the 1.1 exam, as these seemed to give a good guide to what was likely to come up on that version.

The new Objectives


GridBagLayout

The Objective that implies coverage of this this is

Objective 8.2)

Write code using component container and layout manager classes of the java.awt package to present a GUI with specified appearance and resize the behavior and distinguish the responsibilities of layout managers from those of containers.

It makes sense to cover this as it is a very useful LayoutManager but because of its power it can take some learning. Peter van der Linden in Just Java and Beyond 3rd Edition describes it as excessivly complicated and doesn't recommend it. Core Java merely says "using grid bag layouts can be incredibly complex". Whilst it is complex to use by hand, the various GUI tools such as VisualCafe, Visual Age, JBuilder etc etc make it easier to understand.


My favourite Java Tool is Borland/Inprise JBuilder which has its own Layout Manager called the XYLayout manager. This seems to be easier to use than the GridBagLayout, but if you are writing for the net it would require users to download that additional class, causing additional overhead.

GridBagLayout is a little like the GridLayout except that different cell rows can have different heights, and columns can have different widths. The Java2 Docs come with a demonstration applet that shows what can be done with the GridBagLayout manager.


In the exam this is a prime moment to take advantage of the scrap paper to write out a grid and consider the effect of each cell. One of the problems with the GridBagLayout is that instead of being based strictly on the underlying grid, Java tries to guess from the information given. The GridBagLayout manager uses a helper class GridBagConstraints which has a set of member variables that can be set to affect the appearance of each component.The fields that you modify on the GridBagConstraints class act as "suggestions" as to where the components will go. An instance of GridBagConstraints is passed as a parameter with the add method, in the form

  • add(component GridBagConstraint);

GridBagConstraints goes against the general convention in Java in that you might expect its attributes to be configured with setFooParam methods. Instead it takes the form


GridBagLayout gbl = new GridBagLayout();

gbl.weightx=100;

If you use the GridBagLayout without the GridBagConstraints class it acts a little like a FlowLayout, simply dropping the components onto the background one by one. Here is an example of an applet that uses the GridBagLayout without the GridBagConstraints class.

The GridBagLayout acts a little more like the GridLayout if you use the GridBagConstraints class and use the gridx and gridy fields to assign a position in a "virtual" grid to each component as you add it. This applet demonstrates this possibility. This is still a little dull and very like the other layout managers. Things start to get much more interesting when you start to modify other fields of the GridBagConstraints class to modify the appearance of different components within this "virtual" grid.


Remember that although you need to understand this for the purposes of the exam, it might be easier when programming in the real world to use a combination of container controls added with other layout managers. An example of when this is not an option is when you need to dynamically re-size components. This is a situation where GUI builders such as Visual Cafe or JBuilder are not much help and an understanding of the GridBagLayout may be essential.



I have created a demonstration applet that shows the affect of dynamically changing the padding for buttons in a panel parameters for a button sitting in a group of buttons set out with a GridbagLayout manager

The fields for the GridBagConstraints class are

  • gridx gridy
  • gridwidth and gridheight
  • fill
  • ipadx and ipady
  • insets
  • anchor
  • weightx and weighty


You can get a tutorial on the GridBagLayout from Suns Javasoft site at


http://www.javasoft.com/nav/read/Tutorial/ui/layout/gridbag.html


This information can be downloaded from Sun. The tutorial points to this information with the following statement


Note: This trail does not tell you how to use the AWT components. If you need to write a JDK 1.0 program or a 1.1 program that doesn't use Swing components, then this trail is not for you! Instead, you can download an archive version of the old UI trail, Creating a User Interface (AWT Only).


You can ftp the section from

ftp://ftp.javasoft.com/docs/tut-OLDui.zip

Collections

This is the Only completly new section in the exam Objectives and comes in the form of Section 10


10)Section Title: The java.util package

  1. Make appropriate selection of collection classes/interfaces to suit specified behavior requirements.

    The Java 2 API includes new interfaces and classes to enhance the collections available. Earlier versions of Java included

  • vector
  • hashtable
  • array
  • BitSet

    Of these only array was included in the objectives for the 1.1 certification exam. One of the noticable omissions from these classes was any support for sorting, a very common requirement in any programming situation.

    The Java2 API includes the following new collection interfaces

  • Sets
  • Lists
  • Maps

    The collection classes store objects as elements rather than primitives. This approach has the drawbacks that creating objects has a performance overhead and the elements must be cast back from Object to the appropriate type before being used. It also means that the collections do not check that the elements are all of the same type, as an object can be just about anything.

    A Set

    A Set is a collection that cannot contain duplicate elements. It thus matches nicely onto concepts such as a record set returned from a relational database.

    A list

    A list is a sorted collection that can contain duplicates


    A Map

    A map cannot contain duplicate keys, and is similar to a hashtable.

    
    
    				

    Why use Collections instead of arrays?.


    The big advantage of the collections over arrays is that the collections are growable, you do not have to assign the size at creation time. The drawback of collections is that they only store objects and not primitives and this comes with an inevitable performance overhead. Arrays do not directly support sorting, but this can be overcome by using the static methods of the Collections. Here is an example.

    import java.util.*;

    public class Sort{
    
            public static void main(String argv[]){
    
           Sort s = new Sort();
    
            }
    
            Sort(){
    
            String s[] = new String[4];
    
            s[0]="z";
    
            s[1]="b";
    
            s[2]="c";
    
            s[3]="a";
    
            Arrays.sort(s);
    
            for(int i=0;i< s.length;i++)
    
                    System.out.println(s[i]);
    
    
    
            }
    
    
    
    
    
    }

    Using Vectors

    The following example illustrates how you can add objcts of different classes to a Vector. This contrasts with arrays where every element must be of the same type. The code then walk through each one printing to the standard output. This implicitly access the toString() method of each object.

    
    
    				
    import java.awt.*;
    
    import java.util.*;
    
    public class Vec{
    
    public static void main(String argv[]){
    
      Vec v = new Vec();
    
      v.amethod();
    
    	}//End of main
    public void amethod(){
    
         Vector mv = new Vector();
    
    	//Note how a vector can store objects 
    
    	//of different types
    
    	  mv.addElement("Hello");
    
    	  mv.addElement(Color.red);
    
    	  mv.addElement(new Integer(99));
    
    	
    
    	//This would cause an error
    
    	//As a vector will not store primitives
    
    	//mv.addElement(99) 
    
    
        //Walk through each element of the vector
    
    	  for(int i=0; i< mv.size(); i++){
    
            	 System.out.println(mv.elementAt(i));
    
    	         }
    
    
    
    	}//End of amethod
    
    
    
    }
    
    
    				

    Using Hashtables

    Hashtables are a little like a Visual Basic concept of a Collection used with a key. It acts like a Vector, except that instead of referring to elements by number you refer to them by key. The Hashtable part of the name refers to a math term dealing with creating indexes. A hashtable can offer the benefit over a Vector faster look ups.


    BitSet

    A BitSet as its name implies, stores a sequence of Bits. Don't be misled by the "set" part of its name its not a set in the mathematical or database sense, or is it related to the Sets available in java2. It is more appropriate to think of it as a bit vector. A BitSet may useful for the efficient storage of bits where the bits are used to represent true/false values. The alternative of using some sort of collection containing Boolean values can be less efficient.


    According to Bruce Eckel in "Thinking in Java"

    It’s efficient only from the standpoint of size; if you’re looking for efficient access, it is slightly slower than using an array of some native type.


    The BitSet is somewhat of a novelty class which you may never have a need for. I suspect that it might be handy for the purposes of cryptography or the processing of images. Please let me know if you come accross a question relating to it on the Java2 exam.