(1) Qual é a diferença entre String e StringBuffer? (1r) Objetos da classe String são strings contantes, imutáveis. Se queremos strings que possam mudar de valor devemos usar instâncias de StringBuffer. (2) Como é o mecanismo de passagem de parâmetros em Java? (2r) Tipos primitivos da linguagem são passados por valor. Objetos são passados por referência. (3) Quais as vantagens e desvantagens do método de tratamento de exceções embutido na linguagem? (3r) Vantagens: o código fica mais claro e é mais fácil de programar. Desvantages: nenhuma. (4) Considere as classes abaixo (são do livro "Java How to Program", 2a. edição, www.deitel.com): // Fig. 17.03: EmptyListException.java // Class EmptyListException definition // package com.deitel.jhtp2.ch17; public class EmptyListException extends RuntimeException { public EmptyListException( String name ) { super( "The " + name + " is empty" ); } } // Fig. 17.3: List.java // Class ListNode and class List definitions // package com.deitel.jhtp2.ch17; class ListNode { // package access data so class List can access it directly Object data; ListNode next; // Constructor: Create a ListNode that refers to Object o. ListNode( Object o ) { this( o, null ); } // Constructor: Create a ListNode that refers to Object o and // to the next ListNode in the List. ListNode( Object o, ListNode nextNode ) { data = o; // this node refers to Object o next = nextNode; // set next to refer to next } // Return the Object in this node Object getObject() { return data; } // Return the next node ListNode getnext() { return next; } } // Class List definition public class List { private ListNode firstNode; private ListNode lastNode; private String name; // String like "list" used in printing // Constructor: Construct an empty List with s as the name public List( String s ) { name = s; firstNode = lastNode = null; } // Constructor: Construct an empty List with // "list" as the name public List() { this( "list" ); } // Insert an Object at the front of the List // If List is empty, firstNode and lastNode refer to // same Object. Otherwise, firstNode refers to new node. public synchronized void insertAtFront( Object insertItem ) { if ( isEmpty() ) firstNode = lastNode = new ListNode( insertItem ); else firstNode = new ListNode( insertItem, firstNode ); } // Insert an Object at the end of the List // If List is empty, firstNode and lastNode refer to // same Object. Otherwise, lastNode's next instance // variable refers to new node. public synchronized void insertAtBack( Object insertItem ) { if ( isEmpty() ) firstNode = lastNode = new ListNode( insertItem ); else lastNode = lastNode.next = new ListNode( insertItem ); } // Remove the first node from the List. public synchronized Object removeFromFront() throws EmptyListException { Object removeItem = null; if ( isEmpty() ) throw new EmptyListException( name ); removeItem = firstNode.data; // retrieve the data // reset the firstNode and lastNode references if ( firstNode.equals( lastNode ) ) firstNode = lastNode = null; else firstNode = firstNode.next; return removeItem; } // Remove the last node from the List. public synchronized Object removeFromBack() throws EmptyListException { Object removeItem = null; if ( isEmpty() ) throw new EmptyListException( name ); removeItem = lastNode.data; // retrieve the data // reset the firstNode and lastNode references if ( firstNode.equals( lastNode ) ) firstNode = lastNode = null; else { ListNode current = firstNode; while ( current.next != lastNode ) current = current.next; lastNode = current; current.next = null; } return removeItem; } // Return true if the List is empty public boolean isEmpty() { return firstNode == null; } // Output the List contents public void print() { if ( isEmpty() ) { System.out.println( "Empty " + name ); return; } System.out.print( "The " + name + " is: " ); ListNode current = firstNode; while ( current != null ) { System.out.print( current.data.toString() + " " ); current = current.next; } System.out.println( "\n" ); } } Escreva um método public boolean search ( Object item ) da classe List que recebe um objeto e o procura na lista, devolvendo sim ou nao conforme o objeto tenha ou nao sido encontrado na lista. Use o seguinte programa para testar seu codigo. Tem que imprimir: true true false false // Fig. 17.03: ListTest.java // Class ListTest // import com.deitel.jhtp2.ch17.List; // import com.deitel.jhtp2.ch17.EmptyListException; import List; import EmptyListException; public class ListTest { public static void main( String args[] ) { List objList = new List(); // create the List container // Create objects to store in the List Boolean b = new Boolean( true ); Character c = new Character( '$' ); Integer i = new Integer( 34567 ); String s = new String( "hello" ); // Use the List insert methods objList.insertAtFront( b ); objList.insertAtFront( c ); objList.insertAtBack( i ); objList.insertAtBack( s ); //objList.print(); // Use the List remove methods Object removedObj; try { System.out.println( objList.search( b ) ); removedObj = objList.removeFromFront(); //objList.print(); System.out.println( objList.search( b ) ); removedObj = objList.removeFromFront(); //objList.print(); System.out.println( objList.search( b ) ); removedObj = objList.removeFromBack(); //objList.print(); System.out.println( objList.search( b ) ); removedObj = objList.removeFromBack(); //objList.print(); } catch ( EmptyListException e ) { System.err.println( "\n" + e.toString() ); } } } (4r) ... // Search for an object public boolean search ( Object item ) { ListNode current = firstNode; while ( (current != null) && (!current.getObject().equals(item)) ) { current = current.getnext(); } return (current != null); } ...