CS151 Take Home Midterm (3/8/01)






a. How many types of comments are in Java? What are they? (5 points)


b. Why use double instead of float in Java programming? (5 points)


c. Do all Java application have function(s)? (5 points)


d. What is the best way to find out the length of an array? (5 points)




a. What is the difference between Class and Object? (10 points)


b. Do you have to import a package for every Java program? Explain? (5 points)


c. Do you always need to create your own constructor for a class? (5 points)




a. There are only three access modifiers (public, private and protected) in Java. Right? (10 points)


b. Which class has more data and methods in general: superclass or subclass? (5 points)


c. What is protected keyword means in Java? (5 points)




a. Where is the applet runs on? (5 points)


b. How do you identify a program running on a computer in a network? (10 points)


c. If you are using Java code that throws exceptions, what do you do? (5 points)




a. Can you directly read from an URL object? (5 points)


b. What is a Socket? (10 points)


c. When creating a ServerSocket, why you do not need to provide a hostname? (5 points)



QUESTION 6 - Java Programming (50 points)

Write a Java application called URLMidterm that will

  1. Present an UI (with swing) to the user and request
  2. Create an URL object with http as protocol and the inputted address as resource name.
  3. Parse the newly created URL object and print out in an output UI component such as text area in swing
  4. Then, read directly from the URL object and print out all the contents from the input stream to the output file specified in step 1.
  5. Run the program by "java URLMidterm"