用Java的人很少吗?
怎么没人来看?

解决方案 »

  1.   

    考试的时候就是英文环境
    头晕也得去看,那里是我知道的最好最全面的java讨论区.
      

  2.   

    程序中要定义类和对象,并且要使用类和对象!!! 因为程序的目的就是为了展现面向对象的特点和优点!!!
    假定: 对一家公司的员工进行管理:
    包括人员名字,出生日期,加入公司的年份,那个部门(用ring0---ring9表示10个部门) ,工资标准等(多多不限)
    要求有对(假如有员工改名, 可以实现改名, 尽管使用中不常见, 但主要是为了实现面向对象思想)(更改工资标准)(开除员工和增加员工)(通过工龄即加入公司的时间来对员工进行排序, 同一年的可随便排)(通过部门的对员工排序, 个部门的集中在一起显示,譬如ring0的排了下了跟着就是全是ring1部门的)
    请兄弟们快点回帖, 把源代码和程序发给我, 搞定后就给200分!!!
    这是我期末考试的题目, 兄弟们要快快快!!
     我的email :  [email protected]
      

  3.   

    Threads 
    Objective 3) 
    Write code using synchronized wait notify and notifyAll to protect against concurrent access problems and to communicate between threads. Define the interaction between threads and between threads and object locks when executing synchronized wait notify or notifyAll.Why do you need the wait/notify protocol? 
    One way to think of the wait/notify protocol is to imagine an item of data such as an integer variable as if it were a field in a database. If you do not have some locking mechanism in the database you stand a chance of corruption to the data. Thus one user might retrieve the data and perform a calculation and write back the data. If in the meantime someone else has retrieved the data, performed the calculation and written it back, the second users calculations will be lost when the first person writes back to the database. In the way that a database has to handle updates at unpredictable times, so a multi threaded program has to cater for this possibility.The synchronized keyword 
    The synchronized keyword can be used to  a statement or block of code so that only one thread may execute an instance of the code at a time. Entry to the code is protected by a monitor lock around it. This process is implemented by a system of locks. You may also see the words monitor, or mutex (mutually exclusive lock) used. A lock is assigned to the object and ensures only one thread at a time can access the code. Thus when a thread starts to execute a synchronized block it grabs the lock on it. Any other thread will not be able to execute the code until the first thread has finished and released the lock. Note that the lock is based on the object and not on the method.For a method the synchronized keyword is placed before the method thussynchronized void amethod() { /* method body */}
    For a block of code the synchronized keyword comes before opening and closing brackets thus.synchronized (ObjectReference) { /* Block body */ }
    The value in parentheses indicates the object or class whose monitor the code needs to obtain. It is generally more common to synchronize the whole method rather than a block of code.
     When a synchronized block is executed, its object is locked and it cannot be called by any other code until the lock is freed.synchronized void first();
    synchronized void second();
    There is more to obtaining the benefits of synchronization than placing the keyword synchronized before a block of code. It must be used in conjunction with code that manages the lock on the synchronized code . wait/notify 
    In addition to having a lock that can be grabbed and released, each object has a system that allows it to pause or wait whilst another thread takes over the lock. This allows Threads to communicate the condition of readiness to execute. Because of the single inheritance nature of Java, every object is a child of the great grand ancestor Object class from which it gets this Thread communication capability. wait and notify should be placed within synchronized code to ensure that 
    the current code owns the monitor  A call to wait from within synchronized code causes the thread to give up its lock and go to sleep. This normally happens to allow another thread to obtain the lock and continue some processing. The wait method is meaningless without the use of notify or notifyAll which allows code that is waiting to be notified that it can wake up and continue executing. A typical example of using the wait/notify protocol to allow communication between Threads appears to involve apparently endless loops such as//producing codewhile(true){try{         wait();        }catch (InterruptedException e) {}}//some producing action goes herenotifyAll();
    As true is notorious for staying true this, code looks at first glance like it will just loop forever. The wait method however effectively means give up the lock on the object and wait until the notify or notifyAll method tells you to wake up.  Thread scheduling is implementation dependent and cannot be relied on to 
    act in the same way on every JVM  
    Unlike most aspects of Java, Threading does not act the same on different platforms. Two areas of difference are Thread scheduling and Thread priorities. The two approaches to scheduling arePreemptive 
    Time slicing 
    In a pre-emptive system one program can "pre-empt" another to get its share of CPU time. In a time sliced system each thread gets a "slice" of the CPU time and then gets moved to the ready state. This ensures against a single thread getting all of the CPU time. The downside is that you cannot be certain how long a Thread might execute or even when it will be running. Although Java defines priorities for threads from the lowest at 1 to the highest at 10, some platforms will accurately recognise these priorities whereas others will not.
    The notify method will wake up one thread waiting to reacquire the monitor for the object. You cannot be certain which thread gets woken. If you have only one waiting thread then you do not have a problem. If you have multiple waiting threads then it will probably the thread that has been waiting the longest that will wake up. However you cannot be certain, and the priorities of the threads will influence the result. As a result you are generally advised to use notifyAll instead of notify, and not to make assumptions about scheduling or priorities. Of course this is not always possible and you may have to try to test your code on as many platforms as possible.   
    --------------------------------------------------------------------------------
       Questions
    Question 1)
    Which of the following keywords indicates a thread is releasing its Object lock?1) release
    2) wait
    3) continue
    4) notifyAll--------------------------------------------------------------------------------Question 2)
    Which best describes the synchronized keyword?
    1) Allows more than one Thread to access a method simultaneously 
    2) Allows more than one Thread to obtain the Object lock on a reference
    3) Gives the notify/notifyAll keywords exclusive access to the monitor
    4) Means only one thread at a time can access a method or block of code 
    --------------------------------------------------------------------------------Question 3)
    What will happen when you attempt to compile and run the following code? public class WaNot{int i=0;public static void main(String argv[]){        WaNot w = new WaNot();        w.amethod();        }        public void amethod(){ while(true){ try{          wait();     }catch (InterruptedException e) {} i++;     }//End of while }//End of amethod}//End of class
    1)Compile time error, no matching notify within the method2)Compile and run but an infinite looping of the while method3)Compilation and run4)Runtime Exception "IllegalMonitorStatException"
    --------------------------------------------------------------------------------Question 4)
    How can you specify which thread is notified with the wait/notify protocol?1) Pass the object reference as a parameter to the notify method
    2) Pass the method name as a parameter to the notify method
    3) Use the notifyAll method and pass the object reference as a parameter
    4) None of the above--------------------------------------------------------------------------------Question 5) 
    Which of the following are true1) Java uses a time-slicing scheduling system for determining which Thread will execute
    2) Java uses a pre-emptive, co-operative system for determining which Thread will execute
    3) Java scheduling is platform dependent and may vary from one implementation to another
    4) You can set the priority of a Thread in code Answers
    Answer 1)2) waitAnswer 2)
    4) Means only one thread at a time can access a method or block of code
    Answer 3)4) Runtime Exception "IllegalMonitorStateException"The wait/notify protocol can only be used within code that is synchronized. In this case calling code does not have a lock on the object and will thus cause an Exception at runtime.
    Answer 4)4) None of the above. The wait/notify protocol does not offer a method of specifying which thread will be notified. 
    Answer 5)
    3) Java scheduling is platform dependent and may vary from one implementation to another
    4) You can set the priority of a Thread in code
      

  4.   

    7)Threads 
    Objective 2) 
    Recognize conditions that might prevent a thread from executing.Comment on the objective 
    The expression "prevent a thread from executing" is slightly ambiguous, does it mean a thread that has been deliberately paused, or does it also include threads that have died?. A thread that is prevented from executing is said to be blocked.Reasons a thread may be blocked 
    A thread may be blocked because1) It has been put to sleep for a set amount of time 
    2) It is suspended with a call to suspend() and will be blocked until a resume() message 
    3) The thread is suspended by call to wait(), and will become runnable on a notify or notifyAll message. For the purposes of the exam sleep(), and wait/notify are probably the most important of the situations where a thread can be blocked. The sleep method is static and pauses execution for a set number of milliseconds. There is a version that is supposed to pause for a set number of nanoseconds, though I find it hard to believe many people will work on a machine or Java implementation that will work to that level of accuracy. Here is an example of putting a Thread to sleep, note how the sleep method throws InterruptedException. The threadpublic class TSleep extends Thread{public static void main(String argv[]){       TSleep t = new TSleep();       t.start();       }       public void run(){          try{             while(true){                  this.sleep(1000);                  System.out.println("looping while");                 }            }catch(InterruptedException ie){}       }}With the release of the Java2 platform the Thread methods stop, suspend and resume have been deprecated (no longer recommended for use, and will produce a warning at compile time). The JDK notes have the contain the following notice//QuoteDeprecated. This method has been deprecated, as it is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended, no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, deadlock results. Such deadlocks typically manifest themselves as "frozen" processes. For more information see Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?.//End QuoteA generally reliable source (Kathy Kozel) has indicated that you may need to be aware of this for the purpose of the exam. I will assume that you do not need to know how to actually use them.Thread blocking via the wait/notify protocol is covered in the next topic 7.3. 
    --------------------------------------------------------------------------------
       Questions
    Question 1)
    What will happen when you attempt to compile and run this code?public class TGo implements Runnable{public static void main(String argv[]){        TGo tg = new TGo();        Thread t = new Thread(tg);        t.start();        }        public void run(){                while(true){                        Thread.currentThread().sleep(1000);                        System.out.println("looping while");                        }        }}
    1) Compilation and no output
    2) Compilation and repeated output of "looping while"
    3) Compilation and single output of "looping while"
    4) Compile time error--------------------------------------------------------------------------------Question 2) Which of the following are recommended ways a Thread may be blocked?1) sleep()
    2) wait/notify
    3) suspend
    4) pause--------------------------------------------------------------------------------Question 3) Which of the following statements are true?1) The sleep method takes parameters of the Thread and the number of seconds it should sleep
    2) The sleep method takes a single parameter that indicates the number of seconds it should sleep
    3) The sleep method takes a single parameter that indicates the number of milliseconds it should sleep
    4) The sleep method is a static member of the Thread class Answers
    Answer 1)
    4) Compile time error
    The sleep method throws InterruptedException and thus this code will not compile until the while loop is surrounded by a try/catch block
    Answer 2)1) sleep()
    2) wait/notifyFor the Java2 platform the suspend method has been deprecated and thus is valid but not recommended
    Answer 3)3) The sleep method takes a single parameter that indicates the number of milliseconds it should sleep
    4) sleep is a static method of the Thread class
      

  5.   

    7) Threads 
    Objective 1) 
    Write code to define, instantiate and start new threads using both java.lang.Thread and java.lang.RunnableWhat is a thread? 
    Threads are lightweight processes that appear to run in parallel with your main program. Unlike a process a thread shares memory and data with the rest of the program. The word thread is a contraction of "thread of execution", you might like to imagine a rope from which you have frayed the end and taken one thread. It is still part of the main rope, but it can be separated from the main and manipulated on its own. An example of where threads can be useful is in printing. When you click on a print button you probably don't want the main program to stop responding until printing has finished. What would be nice is that the printing process started running "in the background" and allowed you to continue using the main portion of the program. It would also be useful if the main program would respond if the printing thread encountered a problem. A common example used to illustrate threads is to create a GUI application that launches a bouncing ball every time a button is clicked. Unlike most language threading is embedded at the heart of the Java language, much of it at the level of the ultimate ancestor class called Object.The two ways of creating a thread 
    Of the two methods of creating a new thread the use of Runnable is probably more common, but you must know about both for the purpose of the exam. Here is an example of a class created with the Runnable interface.class MyClass implements Runnable{        public void run(){//Blank Body}}
    Creating the thread of execution.MyClass mc = new MyClass();Any class that implements an interface must create a method to match all of the methods in the interface. The methods need not do anything sensible, i.e. they may have blank bodies, but they must be there. Thus I include the method run even in this little example, because you must include a run method if you implement Runnable. Not including a run method will cause a compile time error. To do anything useful when you create a thread of execution from a class you would, of course need to put something where I have put//Blank Body.
    The other method for creating a thread is to create a class that is descended from Thread. This is easy to do but it means you cannot inherit from any other class, as Java only supports single inheritance. Thus if you are creating a Button you cannot add threading via this method because a Button inherits from the AWT Button class and that uses your one shot at inheritance. There is some debate as to which way of creating a thread is more truly object oriented, but you do need to go into this for the purpose of the exam. Instantiating and starting a Thread 
    Although the code that runs in your thread is in a method called run, you do not call this method directly, instead you call the start method of the thread class. The Runnable interface does not contain a start method, so to get at this and the other useful methods for threads (sleep, suspend etc etc), you pass your class with the Runnable interface as the constructor to an instance of the Thread class.Thus to cause the thread to execute from a class that implements Runnable you would call the followingMyClass mc = new MyClass();
    Thread t = new Thread(mc);t.start();
     Although it is the run method code that executes, a thread is actually 
    started via the start method  Again note that was a call to start, not a call to run, even though it is the code in the run method in your class that actually executes.If you create your class as a sub class of Thread you can simply call the start method. The drawback of sub classing the Thread class is that due to only supporting single inheritance you cannot inherit the functionality of any other class.--------------------------------------------------------------------------------
       Questions
    Question 1)
    What will happen when you attempt to compile and run this code?public class Runt implements Runnable{public static void main(String argv[]){        Runt r = new Runt();        Thread t = new Thread(r);        t.start();        }        public void start(){        for(int i=0;i<100;i++)                System.out.println(i);        }}
    1) Compilation and output of count from 0 to 99
    2) Compilation and no output
    3) Compile time error: class Runt is an abstract class. It can't be instantiated.
    4) Compile time error, method start cannot be called directly--------------------------------------------------------------------------------Question 2) Which of the following statements are true?1) Directly sub classing Thread gives you access to more functionality of the Java threading capability than using the Runnable interface
    2) Using the Runnable interface means you do not have to create an instance of the Thread class and can call run directly
    3) Both using the Runnable interface and subclassing of Thread require calling start to begin execution of a Thread
    4) The Runnable interface requires only one method to be implemented, this is called run--------------------------------------------------------------------------------Question 3) What will happen when you attempt to compile and run the following code?public class Runt extends Thread{public static void main(String argv[]){        Runt r = new Runt();        r.run();        }        public void run(){        for(int i=0;i<100;i++)                System.out.println(i);        }}
    1) Compilation and output of count from 0 to 99
    2) Compilation and no output
    3) Compile time error: class Runt is an abstract class. It can't be instantiated.
    4) Compile time error, method start has not been defined--------------------------------------------------------------------------------Question 4) Which of the following statements are true?1) To implement threading in a program you must import the class java.io.Thread
    2) The code that actually runs when you start a thread is placed in the run method
    3) Threads may share data between one another
    4) To start a Thread executing you call the start method and not the run method Answers
    Answer 1)
    3) Compile time error: class Runt is an abstract class. It can't be instantiated.The class implements Runnable but does not define the run method.Answer 2)
    3) Both using the Runnable interface and subclassing of Thread require calling start to begin execution of a Thread
    4) The Runnable interface requires only one method to be implemented, this is called runAnswer 3)
    1) Compilation and output of count from 0 to 99However, note that this code does not start the execution of the Thread and the run method should not be called in this way.Answer 4)
    2) The code that actually runs when you start a thread is placed in the run method
    3) Threads may share data between one another
    4) To start a Thread executing you call the start method and not the run methodYou do not need to import any classes as Threading is an integral part of the Java language
      

  6.   

    还有没有?
    Iutput/Output的呢?
      

  7.   

    The java.io package 
    Although it is not mentioned on the objectives questions on I/O can come up on the Java2 exam. For the 1.1 exam the requirements for knowing the I/O system was spelt out in the objectives, so I will mainly repeat the objectives and my comments from my 1.1 tutorial.Write code that uses objects of the file class to navigate a file system. 
    In his excellent book Just Java and Beyond Peter van der Linden starts his chapter on File I/O by saying "It is not completely fair to re, as some have, that support for I/O in java is "bone headed".I think he was implying that it is slightly bone headed, and so it is an area worthy of double checking your knowledge of before you go for the exam. The names of the I/O Stream classes are not intuitive and things do not always work as you might guess.When you are learning it you have the compensation that at least it is a useful area of the language to understand. The File class is not entirely descriptive as an instance of the File class represents a file or directory name rather than a file itself.
    My first assumption when asked about navigating a file system would be to look for a method to change directory. Unfortunately the File class does not have such a method and it seems that you simply have to create a new File object with a different directory for the constructor.
    Also the exam may ask you questions about the ability to make and delete files and directories which may be considered to come under the heading of navigating the file system. The file class offers
    delete()To delete a file or directorymkdir() and mkdirs()To create directories.The File class contains the list() which returns a string array containing all of the files in a directory. This is very handy for checking to see if a file is available before attempting to open it. An example of using list.import java.io.*;public class FileNav{public static void main(String argv[]){          String[] filenames;          File f = new File(".");          filenames = f.list();          for(int i=0; i< filenames.length; i++)            System.out.println(filenames[i]);          }}
    This simply outputs a list of the files in the current directory ("*.*")Some of the file object methods that allow navigation of the file system are. In a real world version of such a program you would use method such isDirectory and isFile to distinguish between files and directories.The getParent method allows you to get the name of the parent directory of your current path. To traverse up the directory path you would have to create a new instance of File Write code that uses objects of the classes InputStreamReader and OutputStreamWriter to translate between Unicode and either platform default or ISO 8859-1 character encodings. 
    I was surprised that this objective was not be emphasized in the JDK1.2 exams as internationalization has been enhanced and is a big feature with Java. It's nice to sell software to a billion Europeans and Americans but a billion Chinese would be a nice additional et (even if you only got 10% of it).The StreamReaders were introduced with JDK 1.1 and are purely concerned with text I/O. Java was designed from the ground up to deal with multibyte character sets with a format called UTF. This allows it to be used with non western alphabets. This means it can deal with Japanese Chinese, and just about any other character set known. You will be pleased to know that you don't have to give examples of any of these for the exam.The StreamReader class converts a byte input (i.e. not relating to any character set) into a character input stream, one that has a concept of a character set.If you are only concerned with ASCII style character sets you will probably only use these Reader classes in the form with the InputStreamReader(InputStream in)
    This version uses the platform-dependent default encoding. In JDK 1.1 this default is identified by the file.encoding system property (please email me if you know how this is stored). If this system property is not defined, the default encoding identifier is 8859_1 (ISO-LATIN-1). The assumption seems to be that if all else fails, revert back to English.If you are dealing with other character sets you can use
    InputStreamReader(InputStream in, String encoding);Remember that the InputStream comes first and encoding second.If you were reading Vietnamese you might create an InputStreamReader thus.InputStreamReader in = new InputStreamReader( new FileInputStream("inputfile"), "Cp1258"); Distinguish between conditions under which platform default encoding conversion should be used and conditions under which a specific conversion should be used. 
    This could be a "bondage and discipline" type of objective. By this I mean that some purists might take the attitude that you should always specify the encoding conversion because you never know where, when and how your program will be used. It was because so many programmers assumed that the code they wrote that would never have to cope with the year 2,000 that there is such a mess at the moment. Well it's a well paying mess for some programmers.
    If you take a more benign view, this objective asks you identify if your code is likely to ever have to deal with anything but the default encoding. If your home default encoding is not ISO-LATIN-1 and you consider that English is the international language of Business, or you may need to deal with other character sets, then take advantage of the ability to do specific conversions.Select valid constructor arguments for subclasses from a list of classes in the java.io.package. 
    These children of classes take instances of other streams as constructors. Thus the exam might ask you if they could take an instance of file, a string file, a writer or a path to see if you understand the valid constructors. A valid constructor will be some kind of stream.The Filtering in these classes allow you to access information more usefully than a stream of bytes. It might be useful not to worry about the names FilterInputStream and FilterOutputStream as it is the Subclasses that contain the useful methods. These subclasses are
    BufferedInputStream
    DataInputStream
    PushBackInputStream and
    BufferedOutputSteam
    DataOutputStream
    PrintStream
    One of the most typical and useful of these filter classes are DataInputStream and DataOutputstream. Write appropriate code to read, write and update files using FileInputStream, FileOutputStream, and RandomAccessFile objects. 
    The following example creates a text file called Out.txt and writes the text Hello into it. If you type out the resulting file you will see that file comes out as H e l l o (with a gap between each letter) . I suspect this is because a character is 16 bits and because ASCII is 8 bit, the upper 8 bits result in a blank character.
    This also illustrates the previous objective in that it uses the FilterOutputStream descendent DataOutputStream. This allows human readable chars to be written. If this example only used FileOutputStream methods you would be limited to writing bytes or ints. If you do this and then type the results to the console, it just shows up as junk characters.
    import java.io.*;public class Fos{                    String s = new String("Hello");                    public static void main(String argv[]){                    Fos f = new Fos();                    f.amethod();                   }            public void amethod(){                try{                FileOutputStream fos = new FileOutputStream("Out.txt"); //DataOutputStream allows you to write chars                DataOutputStream dos = new DataOutputStream(fos);                dos.writeChars(s);                }catch(IOException ioe) {}              }}The following example will read the text file produced by the last example and output the text to the console. Note that because the previous program will have written Out.txt as unicode, if you create a text file with an editor containing a a string such as "Hello" , the following code will probably print out junk such as question s.import java.io.*;public class Fis{                 public static void main(String argv[]){                 Fis f = new Fis();                 f.amethod();                }      public void amethod(){ try{         FileInputStream fis = new FileInputStream("Out.txt");                DataInputStream dis = new DataInputStream(fis);                while(true){                    char c =dis.readChar();                    System.out.println(c);                    }                }catch(IOException ioe) {}                         }}
    The RandomAccessFile class is way out on it's own and doesn't fit neatly with the Stream I/O classes. If you get answer possibilities that mix instances of RandomAccessFile with other streams, then they are almost certainly the wrong answers.
    For its constructor RandomAccessFile takes either an instance of a File class or a string and a read/write mode argument. The mode argument can be either "r" for read only or "rw" can be read and written to. Memorise those two options, don't get caught out in the exam by a bogus mode such as "w", "ro" or "r+w";
    This example will read the Out.txt file created by the Fos.java example shown earlier.Because of the blank high byte (not bit), the results show a question  with each letter.import java.io.*;public class Raf{               public static void main(String argv[]){                 Raf r = new Raf();                 r.amethod();                 }            public void amethod(){  try{                RandomAccessFile raf = new RandomAccessFile("Out.txt","rw");                for(int i=0; i<10;i++){                                raf.seek(i);                                char myc = raf.readChar();                                //?Show for high bytes                 System.out.println(myc); }                 } catch(IOException ioe) {}                         }}
    Describe the permanent effects on the file system of constructing and using FileInputStream, FileOutputStream, and RandomAccessFile objects. 
    When you create an instance of a decendent of FileOutputStream such as DataOutputStream, any existing file with the same name will be overwritten. As you might expect the creation of a descendent of FileInputStream such as DataInputStream does not modify the file system.The exam may ask questions as to the size of a file after modification such as the creation of a file. For this, allow two bytes for each character in any string written.Constructing an instance of RandomAccessFile with the "rw" mode set can cause the size of a file to increase.The MediaTracker Class
    The exam question database contains at least one question that mentions the MediaTracker class. I do not actually know what it is really about but you might be slightly more prepared if you check out the Java API on the subject at.http://java.sun.com/products/jdk/1.2/docs/api/java/awt/MediaTracker.html
    --------------------------------------------------------------------------------
        --------------------------------------------------------------------------------Question 1)
    What will be output if you try to compile and run the following code, but there is 
    no file called Hello.txt in the current directory?. import java.io.*; public class Mine {         public static void main(String argv[]){
            Mine m=new Mine();         System.out.println(m.amethod()); }
    public int amethod() {         try {                FileInputStream dis=new FileInputStream("Hello.txt");                 }catch (FileNotFoundException fne) {                         System.out.println("No such file found");                         return -1;                         }catch(IOException ioe) {                         } finally{         System.out.println("Doing finally");         }         return 0;         } }
    1) No such file found 
    2) No such file found ,-1 
    3) No such file found, Doing finally, -1 
    4) 0 Question 2)
    Which of the following statements are true? 1) Java uses a system called UTF for I/O to support international character sets
    2) The RandomAccessFile is the most suitable class for supporting international character sets
    3) An InputStream class may not be chained to an OutputClass
    4) File I/O activities requires use of Exception trapping   Question 3)
    Assuming any exception handling has been set up, which of the following will create an instance of the RandomAccessFile class? 1) RandomAccessFile raf = new RandomAccessFile("myfile.txt","+rw");
    2) RandomAccessFile raf = new RandomAccessFile( new DataInputStream());
    3) RandomAccessFile raf = new RandomAccessFile("myfile.txt");
    4) RandomAccessFile raf = new RandomAccessFile( new File("myfile.txt")); Question 4)
    Which of the following are valid constructors for the DataInputStream class?1) File f = new File("file.txt");
    2) InputStreamWriter isw = new InputStreamWriter();
    3) String s = new String("file.txt");
    4) FileInputStream fis = new FileInputStream("file.txt");Question 5)
    Given the following code File f = new File("myfile.txt");What method will cause the file "myfile.txt" to be created in the underlying operating system.?1) f.write();
    2) f.close();
    3) f.flush();
    4) none of the aboveAnswers
    Answer to Question 1)
    3) No such file found, doing finally, -1 The no such file found message is to be expected, however you can get caught out if you are not aware that the finally clause is almost always executed, even if there is a return statement. Answer to Question 2)
    1) Java uses a system called UTF for I/O to support international character sets
    3) An InputStream class may not be chained to an OutputClass
    4) File I/O activities requires use of Exception trapping Internally Java uses Unicode which are 16 bit characters. For I/O Java uses UTF which may be more thatn 16 bits per character.
    InputStreams can only be chained to other OutputStreams and OutputStreams can only be chained to other OutputStreams.Answer to Question 3)
    1) RandomAccessFile raf = new RandomAccessFile("myfile.txt","+rw");The RandomAccessFile is an anomoly in the Java I/O architecture. It descends directly from Object and is not part of the Streams architecture.Answer to Question 4)
    4) FileInputStream fis = new FileInputStream("file.txt");The DataInputStream class is a child of the FilterInputStream class. All descendents of the FilterInputStream class take instances of the stream classes as constructors.Answer to Question 5)
    4) none of the aboveThe File class mainly just describes a file that might exist. To actually create it in the underlying operating system you need to pass the instance of the File class to an instance of one of the OutputStream classes.