Final Questions for First Course in Java  

course homepage      course calendar

This questions are in addition to those for the midterm, which can also appear on the final.

Javadoc:  

1) Convert the following comments to javadoc comments:

// This Class does blablabla and blabla...
// It also...
// Author: Somebody
// This class is related to this other class
public class Something
{
      // This method computes a String
      // The value returned will never be null, but it      
      // might be an empty String
      public String myMethod()
      {
      }      

      // This method computes an integer value based
      //on the parameters.
      // It will compute the square root of 
      // the perimeter of the given planet
      // the planet parameter represents the planet
      // from which you want to compute the perimeter
      // the returned value is an Integer object, 
      // it will never be null and the value
      // should be positive.

      public Integer getSquareRootOfPermiterOfPlanet(Planet planet)
      {
      }
}

   

2) Which of this comments javadoc will ignore:  

/**
  * Blablablablabla bla bla
  * Blablablablabla bla bla
  */  
/*
  * Blablablabla
  * Blablablablabla bla bla
  */  
/**
  ** Blablablablabla bla bla
  ** Blablablablabla bla bla
  ** Blablablablabla bla bla
  */  
/*  Blablablabla
  ** Blablablabla
  ** Blablablablabla bla bla
  **/  

 

3) Explain what the five javadoc tags below are for.
Also, explain the requirements for what the tags specifies.  

@author
@param
@exception
@see
@return

 

Applets:

1) Name and describe (what is it used for, when is it called) three

of the most important methods of the Applet class. Also, give the order in which they will typically be called.

 

2) What is the argument of the paint() method? What is it used for?

 

3) What are (some of) the restrictions of an applet?

 

4) What is the "sandbox"?

 

5) Write the HTML code that you need to insert to display an applet in a web page.

 

6) How do you specify parameters to an applet in the HTML code?

 

7) How do you retrieve parameters from the HTML code, inside of the applet?

 

AWT/Event Driven Programming:

1) What does AWT stand for?

 

2) Describe the components of the event driven programming model and how they interact.

 

3) What is the root class for all of the awt components? [specific to this package, so the answer is not Object]

 

4) What is the root class for all of the awt widgets? [specific to this package, so the answer is not Object]

 

5) What is the default LayoutManager for the Container class and how is it organized?

 

6) How can you get a notification when a Button is clicked?

 

7) What is the class that represents a window?

 

I/O Package:

1) What are the advantages of the way that the IO Package written?

 

2) Name 3 classes of the java.io package and how they are to be used.

 

3) How would you read from a file?

 

Exception handling:

1) What are the 3 keywords of the exception handling mechanism in Java and how are they used?

 

2) What are exceptions used for?

 

Miscellaneous:

1) Javadoc includes all the comments in your code. True or False?

 

2) What might cause a NullPointerException?

 

3) What makes wrapping different from casting?

 

4) What is the recommended way to avoid packages from different vendors having the same name?

 

5) When you use the import statement, it imports all the files and directories

within the directory you point to. True or False?

 

6)

In the follow code, fill in the five blanks:

package awtswinguitest;
______ java.io.*;
 

public class ExceptionsTest _________ Thread
{
   /**
   * This method checks if a file exists, and if it does, tries to read
   * from it, but if the file does not exist,
   * it will throw a FileNotFoundException,
   * which is a subclass of IOException,
   * which is itself a subclass of Exception.
   */

   public static void exceptionThrowingMethod() throws IOException
   {
     if ( !(new File("my_test_file.test").exists()) )  // this file has a four-letter extension: test
     {
        throw new FileNotFoundException("An example of an exception");
        // Code execution halts until the exception is handled.
      }
     else
     {
       //  Do something with the file, such as read the file.
       //  The method we are using can throw an IOException,
       //  so we much either catch it locally, or declare
       //  exceptionThrowingMethod() as throwing IOException
       FileInputStream fis = new FileInputStream("my_test_file.test");
       fis.read();
      }
  

   public static void main(String[] args)
   {
    // The try block is the part of the code
    // that can throw an exception.
    // A least one catch block must follow
   // each try block, and the catch block
  // must catch exactly one type of Exception.
   _________
    {
        // The following method is declared as a
   
     // method that can throw an IOException.
       // This method must catch this exception
       // because the exception cannot be passed to
       // the caller: this method is the initial method.
         exceptionThrowingMethod();
    

     __________ (FileNotFoundException fnfe)

    {
            System.err.println("The file could not be found.");

     }

 

     catch (IOException ioe)
    {
        // This catch block catches any type of IOException
        // other than FileNotFoundException, which gets
        // caught in the block above.
        System.err.println("Some sort of IO Error occurred! "+ioe);
    

     catch (Exception e)
   
{
        // Catch the exception and print it to "standard error" output.
        // When we handle the exception, it does not propagate further.
        System.err.println(e);
     }

 
     ______________
    {
        //  The finally block executes in all cases:
        System.out.println("We're done!");
    }
  }
}

_____________________
course homepage      course calendar