Java Questions and Answers

 

 Contents


1 Java
1.1. What is the difference between an Interface and an Abstract class?
1.2. What is the purpose of garbage collection in Java, and when is it used?
1.3. Describe synchronization in respect to multithreading.
1.4. Explain different way of using thread?
1.5. What are pass by reference and pass by value?
1.6. What is HashMap and Map?
1.7. What is the difference between HashMap and HashTable?
1.8. Difference between Vector and ArrayList?
1.9. Difference between Swing and Awt?
1.10. What is the difference between a constructor and a method?
1.11. What is an Iterator?
1.12. State the significance of public, private, protected, default modifiers both singly and in combination and state the effect of package relationships on declared items qualified by these modifiers.
1.13. What is an abstract class?
1.14. What is static in Java?
1.15. What is final?
1.16. What if the main method is declared as private?
1.17. What if the static modifier is removed from the signature of the main method?
1.18. What if I write static public void instead of public static void?
1.19. What if I do not provide the String array as the argument to the method?
1.20. What is the first argument of the String array in main method?
1.21. If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?
1.22. How can one prove that the array is not null but empty using one line of code?
1.23. What environment variables do I need to set on my machine in order to be able to run Java programs?
1.24. Can an application have multiple classes having main method?
1.25. Can I have multiple main methods in the same class?
1.26. Do I need to import java.lang package any time? Why?
1.27. Can I import same package/class twice? Will the JVM load the package twice at runtime?
1.28. What is Overriding?
1.29. What are different types of inner classes?
1.30. Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?
1.31. Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?
1.32. What is the difference between declaring a variable and defining a variable?
1.33. What is the default value of an object reference declared as an instance variable?
1.34. Can a top level class be private or protected?
1.35. What type of parameter passing does Java support?
1.36. Primitive data types are passed by reference or pass by value?
1.37. Objects are passed by value or by reference?
1.38. What is serialization?
1.39. How do I serialize an object to a file?
1.40. Which methods of Serializable interface should I implement?
1.41. How can I customize the seralization process? i.e. how can one have a control over the serialization process?
1.42. What is the common usage of serialization?
1.43. What is Externalizable interface?
1.44. When you serialize an object, what happens to the object references included in the object?
1.45. What one should take care of while serializing the object?
1.46. What happens to the static fields of a class during serialization?
1.47. Does Java provide any construct to find out the size of an object?
1.48. Give a simplest way to find out the time a method takes for execution without using any profiling tool?
1.49. What are wrapper classes?
1.50. Why do we need wrapper classes?
1.51. What are Checked and UnChecked Exception?
1.52. What are checked exceptions?
1.53. What are runtime exceptions?
1.54. What is the difference between error and an exception?
1.55. How to create custom exceptions?
1.56. If I want an object of my class to be thrown as an exception object, what should I do?
1.57. If my class already extends from some other class what should I do if I want an instance of my class to be thrown as an exception object?
1.58. How does an exception permeate through the code?
1.59. What are the different ways to handle exceptions?
1.60. What is the basic difference between the 2 approaches to exception handling (1) try catch block and (2) specifying the candidate exceptions in the throws clause? When should you use which approach?
1.61. Is it necessary that each try block must be followed by a catch block?
1.62. If I write return at the end of the try block, will the finally block still execute?
1.63. If I write System.exit (0); at the end of the try block, will the finally block still execute?
1.64. How are Observer and Observable used?
1.65. What is synchronization and why is it important?
1.66. How does Java handle integer overflows and underflows?
1.67. Does garbage collection guarantee that a program will not run out of memory?
1.68. What is the difference between preemptive scheduling and time slicing?
1.69. When a thread is created and started, what is its initial state?
1.70. What is the purpose of finalization?
1.71. What is the Locale class?
1.72. What is the difference between a while statement and a do statement?
1.73. What is the difference between static and non-static variables?
1.74. How are this() and super() used with constructors?
1.75. What are synchronized methods and synchronized statements?
1.76. What is daemon thread and which method is used to create the daemon thread?
1.77. Can applets communicate with each other?
1.78. What are the steps in the JDBC connection?
1.79. How does a try statement determine which catch clause should be used to handle an exception?
1.80. Can an unreachable object become reachable again?
1.81. What method must be implemented by all threads?
1.82. What are synchronized methods and synchronized statements?
1.83. What is Externalizable?
1.84. What modifiers are allowed for methods in an Interface?
1.85. What are some alternatives to inheritance?
1.86. What does it mean that a method or field is "static"?
1.87. What is the difference between preemptive scheduling and time slicing?
1.88. What is the catch or declare rule for method declarations?
1.89. Is Empty .java file a valid source file?
1.90. Can a .java file contain more than one java classes?
1.91. Is String a primitive data type in Java?
1.92. Is main a keyword in Java?
1.93. Is next a keyword in Java?
1.94. Is delete a keyword in Java?
1.95. Is exit a keyword in Java?
1.96. What happens if you dont initialize an instance variable of any of the primitive types in Java?
1.97. What will be the initial value of an object reference which is defined as an instance variable?
1.98. What are the different scopes for Java variables?
1.99. What is the default value of the local variables?
1.100. How many objects are created in the following piece of code?
1.101. Can a public class MyClass be defined in a source file named YourClass.java?
1.102. Can main method be declared final?
1.103. What will be the output of the following statement?
1.104. What will be the default values of all the elements of an array defined as an instance variable?
1.105. What do you mean by exception and error handling?
1.106. What is the difference between an Error and an Exception?
1.107. Can you give an example of an unrecoverable problem when error is thrown?
1.108. Does it mean that when error is thrown, we cannot catch it and continue execution?
1.109. What are the different kinds of Exceptions?
1.110. What are runtime Exceptions?
1.111. What do you mean by Checked Exceptions?
1.112. Can we create our own checked exceptions?
1.113. How can we create our own runtime exception?
1.114. How can we create our own Errors?
1.115. What are the different approaches of Exception handling?
1.116. Explain the difference between the two approaches of exception handling
1.117. What is finally?
1.118. What is the difference between catch and finally?
1.119. Can we have a try block without a catch block?
1.120. What happens when we use only try and finally block without a catch block?
1.121. When do you use a catch block and when do you use a finally block?
1.122. What will happen if we return from the try block, will the finally block get executed?
1.123. What happens when we have a return statement in the try block as well as in the finally block.
1.124. If I write System.exit (0); at the end of the try block, will the finally block still execute?
1.125. Can I have more than one catch block following a try block?
1.126. What are the rules for having multiple catch blocks?
1.127. Suppose I have a class A that has a method X which throws FileNotFoundException. I have a class B that extends class A and the method X is overridden in B. In the ovverriden method X in class B can I throw IOException?
1.128. Is the above rule logical?
1.129. What are the two types of multitasking?
1.130. What are the two ways to create the thread?
1.131. What is the signature of the constructor of a thread class?
1.132. What are all the methods available in the Runnable Interface?
1.133. What is the data type for the method isAlive() and this method is available in which class?
1.134. What are all the methods available in the Thread class?
1.135. What are all the methods used for Inter Thread communication and what is the class in which these methods are defined?
1.136. What is the mechanisam defind by java for the Resources to be used by only one Thread at a time?
1.137. What is the procedure to own the moniter by many threads?
1.138. What is the unit for 1000 in the below statement? ob.sleep(1000)
1.139. What is the data type for the parameter of the sleep() method?
1.140. What are all the values for the following level? max-priority, min-priority, normal-priority
1.141. What is the method available for setting the priority?
1.142. What is the default thread at the time of starting the program?
1.143. The word synchronized can be used with only a method. True/ False
1.144. Which priority Thread can prompt the lower primary Thread?
1.145. How many threads at a time can access a monitor?
1.146. What are all the four states associated in the thread?
1.147. The suspend()method is used to teriminate a thread? True /False
1.148. The run() method should necessary exists in clases created as subclass of thread? True /False
1.149. When two threads are waiting on each other and can't proceed the programe is said to be in a deadlock? True/False
1.150. Which method waits for the thread to die ?
1.151. Which of the following is true? (1) wait(),notify(),notifyall() are defined as final & can be called only from with in a synchronized method (2) Among wait(),notify(),notifyall() the wait() method only throws IOException (3) wait(),notify(),notifyall() & sleep() are methods of object class
1.152. Garbage collector thread belongs to which priority?
1.153. What is meant by timeslicing or time sharing?
1.154. What is meant by daemon thread? In java runtime, what is it's role?
1.155. What is the difference between procedural and object-oriented programs?
1.156. What are Encapsulation, Inheritance and Polymorphism?
1.157. What is the difference between Assignment and Initialization?
1.158. What is OOPs?
1.159. What are Class, Constructor and Primitive data types?
1.160. What is an Object and how do you allocate memory to it?
1.161. What is the difference between constructor and method?
1.162. What are methods and how are they defined?
1.163. What is the use of bin and lib in JDK?
1.164. What is casting?
1.165. How many ways can an argument be passed to a subroutine and explain them?
1.166. What is the difference between an argument and a parameter?
1.167. What are different types of access modifiers?
1.168. What is final, finalize() and finally?
1.169. What is UNICODE?
1.170. What is Garbage Collection and how to call it explicitly?
1.171. What is finalize() method?
1.172. What are Transient and Volatile Modifiers?
1.173. What is method overloading and method overriding?
1.174. What is difference between overloading and overriding?
1.175. What is meant by Inheritance and what are its advantages?
1.176. What is the difference between this() and super()?
1.177. What is the difference between superclass and subclass?
1.178. What modifiers may be used with top-level class?
1.179. What are inner class and anonymous class?
1.180. What is a package?
1.181. What is a reflection package?
1.182. What is interface and its use?
1.183. What is an abstract class?
1.184. What is the difference between Integer and int?
1.185. What is a cloneable interface and how many methods does it contain?
1.186. What is the difference between abstract class and interface?
1.187. Can you have an inner class inside a method and what variables can you access?
1.188. What is the difference between String and String Buffer?
1.189. What is the difference between Array and vector?
1.190. What is the difference between exception and error?
1.191. What is the difference between process and thread?
1.192. What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?
1.193. What is the class and interface in java to create thread and which is the most advantageous method?
1.194. What are the states associated in the thread?
1.195. What is synchronization?
1.196. When you will synchronize a piece of your code?
1.197. What is deadlock?
1.198. What is daemon thread and which method is used to create the daemon thread?
1.199. Are there any global variables in Java, which can be accessed by other part of your program?
1.200. What is an applet?
1.201. What is the difference between applications and applets?
1.202. How does applet recognize the height and width?
1.203. When do you use codebase in applet?
1.204. What is the lifecycle of an applet?
1.205. How do you set security in applets?
1.206. What is an event and what are the models available for event handling?
1.207. What are the advantages of the model over the event-inheritance model?
1.208. What is source and listener?
1.209. What is adapter class?
1.210. What is meant by controls and what are different types of controls in AWT?
1.211. What is the difference between choice and list?
1.212. What is the difference between scrollbar and scrollpane?
1.213. What is a layout manager and what are different types of layout managers available in java AWT?
1.214. How are the elements of different layouts organized?
1.215. Which containers use a Border layout as their default layout?
1.216. Which containers use a Flow layout as their default layout?
1.217. What are wrapper classes?
1.218. What are Vector, Hashtable, LinkedList and Enumeration?
1.219. What is the difference between set and list?
1.220. What is a stream and what are the types of Streams and classes of the Streams?
1.221. What is the difference between Reader/Writer and InputStream/Output Stream?
1.222. What is an I/O filter?
1.223. What is serialization and deserialization?
1.224. What is JDBC?
1.225. What are drivers available?
1.226. What is the difference between JDBC and ODBC?
1.227. What are the types of JDBC Driver Models and explain them?
1.228. What are the steps involved for making a connection with a database or how do you connect to a database?
1.229. What type of driver did you use in project?
1.230. What are the types of statements in JDBC?
1.231. What is stored procedure?
1.232. How to create and call stored procedures?
1.233. What is servlet?
1.234. What are the classes and interfaces for servlets?
1.235. What is the difference between an applet and a servlet?
1.236. What is the difference between doPost and doGet methods?
1.237. What is the life cycle of a servlet?
1.238. Who is loading the init() method of servlet?
1.239. What are the different servers available for developing and deploying Servlets?
1.240. How many ways can we track client and what are they?
1.241. What is session tracking and how do you track a user session in servlets?
1.242. What is Server-Side Includes (SSI)?
1.243. What are cookies and how will you use them?
1.244. Is it possible to communicate from an applet to servlet and how many ways and how?
1.245. What is connection pooling?
1.246. Why should we go for interservlet communication?
1.247. Is it possible to call servlet with parameters in the URL?
1.248. What is Servlet chaining?
1.249. How do servlets handle multiple simultaneous requests?
1.250. What is the difference between TCP/IP and UDP?
1.251. What is Inet address?
1.252. What is Domain Naming Service (DNS)?
1.253. What is URL?
1.254. What is RMI and steps involved in developing an RMI object?
1.255. What is RMI architecture?
1.256. What is UnicastRemoteObject?
1.257. Explain the methods, rebind() and lookup() in Naming class?
1.258. What is a Java Bean?
1.259. What is a Jar file?
1.260. What is BDK?
1.261. What is JSP?
1.262. What are JSP scripting elements?
1.263. What are JSP Directives?
1.264. What are Predefined variables or implicit objects?
1.265. What are JSP ACTIONS?
1.266. How do you pass data (including JavaBeans) to a JSP from a servlet?
1.267. How can I set a cookie in JSP?
1.268. How can I delete a cookie with JSP?
1.269. How are Servlets and JSP Pages related?
1.270. What is the difference between Java and JRE?
1.271. What is the difference between JRE and SDK?
1.272. What is the name of the class that is the super class for every class?
1.273. Is it possible to extend the java.lang.String class? Why or why not?
1.274. What primitives are defined in Java?
1.275. How are the methods this() and super() used within constructors?
1.276. What is the difference between a static and non-static method?
1.277. In Java, what is meant by the phrase “Write once and run anywhere”?
1.278. Java language does not natively support multiple inheritance. What feature of Java can be used to simulate multiple inheritance in Java?
1.279. What is the difference between a constructor and a method?
1.280. What is the difference between an Interface and an Abstract class in Java?
1.281. What is the purpose of garbage collection in Java, and when is it used?
1.282. Discuss garbage collection and explain the different ways that it is implemented in Perl and Java.
1.283. In Java, if you do not want to make a function a virtual function, what is one technique for achieving this?
1.284. How many public classes are permitted within a single Java class file?
1.285. How many package statements (declarations) are allowed in a Java source file?
1.286. Is it a requirement to have a package statement in a Java source file?
1.287. In a Java source file, which statement needs to come first, import or package?
1.288. If all three statement elements of a Java source file are included (imports, classes, packages), in which order must they appear?
1.289. Consider a program that imports a large number of classes. Is there any performance degradation from importing many classes at runtime?
1.290. What is the command-line utility used to compile Java source code into bytecode?
1.291. What is the name of the method the JVM uses as the normal entry point for a Java application? What is its signature?
1.292. Is it a requirement that the main() method be declared as static? Explain your answer as to why or why not?
1.293. What are the four signed integral data types in Java? What are their sizes and range of values?
1.294. Within your Java application, you catch all exceptions and want to know the exact circumstances under which it occurred. Which method would you use from the Throwable class to obtain a complete stack trace?
1.295. What is the difference between System.out.println() and System.out.print()?
1.296. When creating a String object, is it necessary to use the new operator?
1.297. What is the value a String is automatically initialized to?
1.298. How do you make a variable a constant?
1.299. When you put the + operator between two strings, what does this do?
1.300. What characters can be legally used as the first character of a Java identifier?
1.301. What statement would you use to convert the String str1 to an integer named int1?
1.302. What statement would you use to convert the String str1 to a byte named byte1?
1.303. What statement would you use to convert the String str1 to a long named long1?
1.304. Which method of the String class is used to compare two strings while ignoring their case?
1.305. How many boolean literals (values) are possible and what are they?
1.306. What is the name of the access modifier when you do not explicitly specify private, public or protected?
1.307. What is an object wrapper?
1.308. What keyword is used in Java that allows you to develop a class that inherits from another class?
1.309. Is int an object in Java?
1.310. Briefly describe the purpose of the Java Virtual Machine?
1.311. All command-line arguments being passed into a Java application are passed in as an array of Strings. What would you need to do if your application needs to have an integer value to be passed in? What, if anything, could go wrong while attempting this?
1.312. How do you determine the length of a String in Java?
1.313. When a method is not meant to return a value, what keyword in Java should be used in place of the return type?
1.314. What is a JAR file?
1.315. Are JAR files meant to be platform independent?
1.316. Why is it important to override the equals() method in the Object class when using it to compare objects?
1.317. What is the package concept and use of packages?
1.318. Suppose you have a package named com.acme and you want to import all classes within this package into your application. Which import statement would you include in your Java application?
1.319. When using the wildcard character “*” in an import statement as in import com.acme.*, what gets included and what does not get included?
1.320. What is the difference between Java and Java 2?
1.321. What method in the String class is used to return a new string that is all uppercase?
1.322. What does the term initialization mean?
1.323. What exactly does the trim() method do?
1.324. Is it possible to cast a double value to a byte?
1.325. Does a class inherit the constructors of its superclasses?
1.326. Is it possible for an anonymous class to be defined as implementing an interface or extending a class?
1.327. When overriding the equals() method of the Object class, which other method in the Object class should you override?
1.328. Is it legal to declare a class as final abstract? Explain why or why not.
1.329. Will the following code snippet successfully compile? Why or why not?
1.330. In a JAR file, what is the optional META-INF directory used for?
1.331. Which package in the Java API can be used to programmatically create a JAR file?
1.332. What are the four types of methods in Java that cannot be overridden?
1.333. What is the difference between the == operator and the equals() method?
1.334. What is BYTE Code and what are its benefits?
1.335. Is it possible for a Java program to run out of memory even with the garbage collector active?
1.336. Will calling the System.gc() method guarantee the garbage collector will collect and remove all unused objects from the memory heap?
1.337. What is the purpose of finalize() method?
1.338. If an object is still reachable, can the object’s finalize() method be invoked by either the garbage collector or other objects?
1.339. How many times may the garbage collector call an object’s finalize() method?
1.340. In a try-catch-finally statement, what is the purpose of the finally clause?
1.341. What is the command-line option with Sun’s SDK that can be used to print a message to standard output each time a Java class is loaded?
1.342. Are classes that are in the same package, able to access each other’s protected members?
1.343. What does a “default” member mean?
1.344. Which statement in Java causes a program to go back to the statement that began the loop, thereby incrementing the counter and then keep going from there?
1.345. What is the difference between the break and continue statement in Java?
1.346. What are the range of values return by the Math.random() method?
1.347. What is the value returned from the following statement? Math.ceil(Math.PI);
1.348. Which access is more restrictive “default” or “protected”?
1.349. Consider a class named MyClass with a final static variable named b. It is possible to have 4 instances of MyClass, each of which has a different value for b?
1.350. What is the resulting type when a byte is added to a char variable?
1.351. If a char type is divided by a long type, what is the resulting type?
1.352. What is a transient variable?
1.353. Consider an abstract class named Parent that contains an abstract method named methodA(). If you subclass Parent, does your new subclass have to implement methodA()?
1.354. Consider any of the signed data types. Are there an equal number of non-zero positive numbers and negative values available?
1.355. What is the range of values that can be assigned to a short variable?
1.356. What is the range of values that can be assigned to a byte variable?
1.357. Consider the following snippet of code: int x, a = 3, b=5; x = ++a + b++; After executing both lines, what are the values of a, b, and x?
1.358. You came up with several mathematical functions that you feel should have been part of the java.lang.Math class. You decide to extend the Math class to add your new functions. What happens?
1.359. You want to use several functions in the java.lang.Math class. Is it necessary to import java.lang.Math in your Java source code? Why or why not?
1.360. Is it possible to create an instance of the java.lang.Math class? Explain why or why not.
1.361. Consider a String object named str1 that contains the value of “Retesting”. Write a statement that would return the string “test” from str1.
1.362. Are overloaded methods allowed to change the access level?
1.363. Is the following a valid statement? Why or why not? int x = 1; x = !x;
1.364. Is the third line in the following code snippet legal? If so, what is the value of x and describe what happens when assigning x.
1.365. What is the value of x in the following code snippet?
1.366. What is the value returned by the statement Math.ceil(-17.8)?
1.367. What is the value returned by the statement Math.floor(13.2)?
1.368. Consider the following code snippet: String name1 = “Alex”; StringBuffer name2 = new StringBuffer(“Alex”); How would you compare the contents of name1 and name2 to determine if they are equal?
1.369. Consider the class declaration: Class Student extends Person What is the order in which each of the constructors get invoked including the Object class?
1.370. What is the value returned by the statement Math.round(14.34)?
1.371. Will the following class compile? If not, how would you fix it to compile?
1.372. When creating an abstract class, is a requirement that the class contain at least one abstract method before it will compile?
1.373. If you have a class that contains one or more final methods, does the class need to be declared final? Explain why of why not.
1.374. The signature of the sin() method of the Math class is as follows: public static double sin(double angle) What unit of measure is the angle argument?
1.375. Will the following produce a compile-time error? If so, how would you fix it? float pi = 3.142;
1.376. Using Sun’s Java 2 SDK, how do you check which version of the SDK you are using?
1.377. After installing the Java 2 SDK bundle, what are the most important environment variables that should be set?
1.378. What is the environment variable CLASSPATH used for?
1.379. If you do not set CLASSPATH, what value will be used by the JVM to locate and load Java class files by default?
1.380. If the CLASSPATH environment variable is set and the -classpath option is used for the JRE, which one takes precedence?
1.381. Sun’s JDK includes a minimal profiler. What command-line option is used with the java executable to invoke this profiler with Sun’s JDK 1.2 or higher?
1.382. A common mistake programmer’s make is to perform “premature optimization” – trying to optimize your code during code development. Why is this a bad idea?
1.383. What methods can you call in Java to encourage or suggest the garbage collector to reclaim memory?
1.384. What is the command-line option with Sun’s SDK that can be used to print out messages by the interpreter each time a garbage collection is performed?
1.385. When tuning an application, you should monitor and determine if the application is limiting any of the three major computer resources. What are these three computer resources?
1.386. When using the default profiler packaged with Sun’s JDK 1.2 (or higher), what is the default name of the results file that contains the profile data?
1.387. When using the default profiler packaged with Sun’s JDK 1.2 (or higher), is it possible to specify the name of the results file that will contain the profile data? If so, what does the command-line option look like.
1.388. What is a Just-In-Time compiler and what are the benefits to using it?
1.389. What is the difference between the StringBuffer class and the String class?
1.390. What method in the StringBuffer class can be used to append character data to the end of the current data already within the StringBuffer object?
1.391. How would you return the content of a StringBuffer object into a String object?
1.392. Consider the following code snippet: int x = 8; int y = x/4; Using bit-wise arithmetic, could you replace the operation in the second line with a faster and more efficient operation without changing the meaning of the statement?
1.393. Consider the following code snippet: int x = 4; int y = x * 8; Using bit-wise arithmetic, could you replace the operation in the second line with a faster and more efficient operation without changing the meaning of the statement?
1.394. Consider the following code snippet:
1.395. Java security use the term “Java Sandbox”. What is meant by this term?
1.396. What is the default security manager used for an application by the Java virtual machine when no security options are set when starting the application?
1.397. When starting a Java application, how many security managers can be installed for it?
1.398. What is the name of the command-line property and what should it value be set to in order to install the default (built-in) security manager when starting a Java application?
1.399. What is the difference between the SecurityManager and AccessController elements of Java’s security model?
1.400. What package would you find the SecurityManager class defined in?
1.401. When one of the check methods in the SecurityManager determines that the operation it is checking is not permitted, what exception is thrown?
1.402. When one of the check methods in the SecurityManager determines that the operation it is checking is not permitted, it throws the exception SecurityException. What is the one check method that is an exception to this convention?
1.403. Do you have to wrap the check methods that throw a SecurityException exception of SecurityManager in a try-catch block? Why or why not?
1.404. What two methods available in the System class allow you to retrieve and install a Security Manager?
1.405. If you are running an application with no security manager installed and call the System.getSecurityManager() method, what is returned?
1.406. Before attempting to install a security manager using the System.setSecurityManager() method, what runtime permission must you have in order to instantiate the security manager object?
1.407. What method from the SystemManager class is used to check if the calling thread is allowed to write to the specified file descriptor?
1.408. What is the name of the property that could be set on the command-line to specify the policy files to be utilized when starting an application?
1.409. When using the java.security.policy property, what is the difference between using the equals sign ‘=‘ and the double equals sign ‘==‘ when specifying the policy file name?
1.410. What is the default name of the policy file?
1.411. What is the name of the GUI tool included with Sun’s JDK that allows a user to create policy files?
1.412. What is the name and location of the global policy file that will be applied to all applications run by any system user?
1.413. What is the name of the property that could be set to print trace messages by the Java 2 security system during runtime? What would be the main reason for setting this property?
1.414. What is the file java.security used for and where is it typically located?
1.415. What is the bytecode verifier and why is it important within the context of Java security?
1.416. What are some of the items that the bytecode verify is responsible for checking and proving?
1.417. The Java virtual machine (JVM) maintains two stacks for each thread of execution. What are these two stacks and which is the only one that can be validated to not underflow or overflow by the bytecode verifier?
1.418. What is a message digest and what are they primarily used for?
1.419. What are some of the more common message digest algorithms?
1.420. Write a method called performRot13() that implements the rot13 algorithm. Here is the signature of the method to implement: String performRot13(String in);
1.421. Which package contains classes and interfaces for parsing and managing certificates, certificate revocation lists (CRLs), and certification paths?
1.422. Which package contains the interfaces for generating DSA and RSA keys?
1.423. What is a thread?
1.424. What does the phrase “thread safe” mean and why is it so important in Java?
1.425. What is the difference between green threads and native threads?
1.426. Which package contains the Thread class?
1.427. What are the two basic approaches for writing code that creates a new thread of control?
1.428. If you have a class that must subclass another class (i.e. Applet), which strategy must you use to create another thread?
1.429. After extending the Thread class to create a new thread, what method do you need to override in the Thread class to define the code to be executed by the new thread?
1.430. What is the signature of the run() method in the Thread class?
1.431. Which interface does the Thread class implement?
1.432. Within your program, you just created a Thread object named myThread. What method would you know call on this object to start it as a separate thread of execution?
1.433. What key method in a thread gets called by the start() method?
1.434. What are thread groups used for?
1.435. What is the keyword synchronized used for?
1.436. What are the high-level states a thread can be in?
1.437. If you have a method in a class that is synchronized, and a subclass that is extending this class contains a method that is overriding the synchronized method, is it mandatory that the new overriding method be declared as synchronized?
1.438. What is the difference between a daemon thread and a user thread?
1.439. How do you make a daemon thread?
1.440. You just created and started a thread object named myThread. What method would you call to determine if this thread is a daemon thread?
1.441. What does the Thread.isAlive() method tell you about a particular thread?
1.442. If you create a new Thread without specifying its group in the constructor, what thread group does it get created in?
1.443. What method from the Thread class allows you to retrieve the number of active threads in the current thread’s thread group?
1.444. Explain how the join() method works and an example of what it’s used for?
1.445. There exists a version of the join() operation that takes a single long parameter that specifies how long it wait to join another completed thread before it times out and simply continues. What is the time unit of the long passed into the join() method?
1.446. What class would you find the methods sleep() and yield() in?
1.447. What class would you find the methods notify(), notifyAll()and wait()in?
1.448. What is a semaphore?
1.449. What will happen if you attempt to call the wait() method on an object where the Thread does not own the lock on it?
1.450. What is meant by the phrase “race condition”?
1.451. Is it possible to declare a static method to be synchronized?
1.452. At any moment, how many object locks can a thread be waiting for?
1.453. If two threads with different priorities are ready to run, which thread will be run first? Explain your answer.
1.454. Which method can a thread call to give up its right to execute thereby halting its execution?
1.455. A thread attempts to yield the CPU to other threads, all of which have a lower priority. What happens when Java executes the yield() method?
1.456. The Thread class contains two constants that define the numeric values for the highest and lowest values for thread priority. What are they?
1.457. What is the name of the constant variable in the Thread class that holds the numeric value of the default priority assigned to a thread?
1.458. You have a class named MyThread that implements the Runnable interface. Write a sample code block that starts a thread of type MyThread.
1.459. You have an application that contains a separate thread of control that is executing a long running computation. What method could you call from within this long running that that would suspend its operations allowing the thread scheduler to choose another runnable thread to execute?
1.460. What is the difference between sleep() and yield()?
1.461. Is the yield() method declared as a static method?
1.462. If a thread calls the yield() method, is it possible for the thread scheduler to choose the same thread that called the yield() method?
1.463. From within the run() method, you want to stop execution of the thread by calling the stop() method from the Thread class. Is this safe to do?
1.464. What method of the Thread class would you use to check to see if a thread has been interrupted without changing the interrupted status of the thread?
1.465. Is it possible to acquire a lock on a class?
1.466. What is the state of a thread when it blocks on I/O?
1.467. What is the initial state of a thread after it is created and started?
1.468. What happens to the status of the current thread as it refers to its interrupted status when the interrupted() method has been called on it?
1.469. Within your program, you used the setPriority() method to set your thread to a particular priority. Later in the program, you call the getPriority() method expecting to have returned the same value you specified when calling setPriority(). Is it possible for getPriority to return a different value from the one you requested even if no one has made a manual change to the priority?
1.470. Is it possible to call the wait() method in a non-synchronized block?
1.471. In a multithreaded application, would the method generateIdNumber() in the following code snipped need to be synchronized to ensure only unique numbers are returned and therefore guaranteeing thread safety?
1.472. What is the Java Collections Framework API?
1.473. How would you best define a collection?
1.474. Which top-level interfaces in the Collection Framework API do not extend the Collection interface? Why?
1.475. In which package would you find the interfaces and classes defined in the Java Collections Framework?
1.476. What two methods defined in the Collection interface allow you to add elements to a collection?
1.477. What method defined in the Collection interface allows you to determine the current size of the collection? (e.g. How many elements are in the collection)
1.478. What method in the Collection interface can tell you if the collection is empty or not?
1.479. Java 2 includes two special classes in the Collections Framework that consists of many static methods and for working with and manipulating collection instances. What are the names of these two classes and which package can they be found in?
1.480. What is the difference between Java’s historical collections (i.e. Vector, Stack, Hashtable, Dictionary, Bitset, etc) and the new collections found in the Java 2 Collections Framework as it relates to thread-safety and synchronization?
1.481. If you need thread-safety when working with collections in the Java 2 Collections Framework, what methods are available in the Collections class to provide for implementations that are thread-safe (List, Set, Map, etc)?
1.482. You created a HashSet object named mySet using: Set set = Collections.synchronizedSet(new HashSet(50)); You now need to walk through the set using an Iterator. Is the iterator thread-safe? If not, how would you traverse the set in a thread-safe manner?
1.483. What is the one basic collection used in many programs and is built right into the Java programming language?
1.484. In Java, what index value do Arrays start at?
1.485. Is it possible to set the length variable of an array to increase and decrease the size of an array?
1.486. What class and method provided in the Java API is used to sort an array?
1.487. What method in the System class allows you to copy elements from one array to another?
1.488. When using the System.arraycopy() method, what exception is thrown if the destination array is smaller than the source array?
1.489. When using the System.arraycopy() method, will an exception be thrown if the destination array is larger than the source array?
1.490. Consider a boolean array where none of the entries in the array have been initialized. What are the default values for each value of the array?
1.491. Write a one line Java statement that declares, constructs, and initializes an integer (int) array named array1 with the values 3, 4, and 5?
1.492. Is a character array the same as a String object in Java?
1.493. What is the Vector class?
1.494. Using a Vector, what method would you call to change the size of the internal vector buffer?
1.495. When using the setSize() method of the Vector class, what happens if you set the size of the collection to a size smaller than the number of elements in the Vector?
1.496. In the Vector class, what does the capacity() method tell you?
1.497. What are the only two methods defined in the Enumeration interface?
1.498. The Enumeration interface is one of Java’s historical interfaces. Which interface introduced in Java 2, version 1.2 replaces the Enumeration interface and provides for several new capabilities for traversing collections?
1.499. What is the Iterator interface?
1.500. What are the three methods in the Iterator interface and what do they do?
1.501. What is the List interface?
1.502. Is it possible for a List object to contain object references of more than one type?
1.503. What are some of the concrete implementations of the List interface?
1.504. What is the name of the Iterator that you should use for a List to traverse the elements in both directions?
1.505. What are the capabilities provided with the ListIterator interface not available with the Iterator when using a List collection?
1.506. You are about to insert a considerable number of elements into an ArrayList. What method, although not required, should be called to ensure the elements you are about to add will not cause an excessive number of resizes of the internal data structures during insertion-time?
1.507. After adding all of the elements you need to the ArrayList collection, what method could you use to reduce the amount of unused space within the internal data structures?
1.508. If you try to add or remove an element from a list that does not support adding or removing elements, what exception gets thrown in both operation attempts?
1.509. Is the LinkedList implementation provided by the Collection Framework a doubly linked list?
1.510. What are the two methods in the LinkedList implementation that allow you to treat the linked list as either a queue or a stack data structure for adding elements?
1.511. What is the Map interface?
1.512. What are the four concrete implementation of the Map interface?
1.513. Consider the following code snippet:
1.514. How many values will be stored in the map and what are they after executing this code block?
1.515. What is the Set interface?
1.516. What are some of the concrete implementations of the Set interface?
1.517. Which of the Set implementations support an ordered collection?
1.518. Does the TreeSet collection maintain a balanced tree?
1.519. The TreeSet implementation maintains a balanced tree. What is it’s guaranteed search time expressed in Big-O notation?
1.520. What collection is used as the “backend” data structure for the HashSet collection for storing its unique elements?
1.521. What is the default “load factor” for a HashSet collection? Can you specify another load factor when creating the collection?
1.522. Which package in the Java API includes a collection of stream classes that support algorithms for reading and writing I/O streams?
1.523. The Java I/O stream classes are divided into two basic class hierarchies. What are they?
1.524. What are the names of the two abstract superclasses for reading and writing all character streams in the java.io package?
1.525. To read in textual information, would it be best to use a Reader or an Input Stream?
1.526. What is the length (in bits) of each character read and written using the character streaming classes?
1.527. Which character set do the character stream classes use?
1.528. Which character set do the byte stream classes use?
1.529. What is the size (in bits) of all Unicode characters?
1.530. What gets printed out given the following code snippet?
1.531. For any of the steam classes (reader, writer, input streams, and output streams), if you do not explicitly call the close() method to the stream, what process will eventually close the stream for you?
1.532. You are reading and writing binary streams. Which two streams (reading/writing) could be used with other streams to reduce the number of accesses on the original data and thereby improve reading and writing efficiency? What two streams would you use if you were reading/writing character streams?
1.533. Which two stream classes would you use to serialize (read/write) objects?
1.534. When reading from a stream, it is sometimes useful to peek at the next few character or bytes in the stream to decide what to do next. Which streams (character and binary) can be used to perform this?
1.535. Suppose you want to create a single stream from multiple input sources. This comes in useful when you want implement a concatenation utility that sequentially concatenates several files together. Which stream class provided in the java.io package would you use to easily perform this?
1.536. How do you delete a file in Java?
1.537. Is it a requirement with object serialization that the ObjectInputStream and ObjectOutputStream be constructed from another stream?
1.538. What interface must a class implement before it can be considered serializable?
1.539. What is Object Serialization?
1.540. What are the two main purposes for using object serialization?
1.541. Is it possible to find the creation date of a file using pure Java?
1.542. Is there a way to get a list of all files in the current working directory using the File class? If so, sketch out a code snippet that would perform this.
1.543. Do readers have methods for reading and returning primitive data types like float, int, double?
1.544. Consider running the following statement in an empty directory: File f = new (“file.txt”); Will the file get created since it doesn’t exist?
1.545. In the File(String x, String y) constructor, what do both of the parameters stand for?
1.546. What value is returned from the readLine() method when it has reached the end of a file?
1.547. What value is returned from the read() method when it has reached the end of a file?
1.548. What are the DataInputStream and DataOutputStream classes used for?
1.549. Which package would you find the ZipInputStream and ZipOutputStream classes?
1.550. Which two streams can be used while reading to keeps track of line numbers while reading?
1.551. What is an I/O filter?
1.552. Which package in the Java API contains interfaces and classes for network communication programming?
1.553. What is the name of the class in the java.net package that can be used to represent an Internet Protocol (IP) Address?
1.554. Which class in the java.net package would you use if you needed to represent an Internet Protocol (IP) Version 6 Address?
1.555. What is the purpose of the ServerSocket class is it found in?
1.556. What is the URL class used for? Which package is it located in?
1.557. What are some of the protocols that can be defined in a URL?
1.558. Given the URI http://www.acme.com, how would you turn this absolute URI into a URL object?
1.559. Given the URL http://www.acme.com, how would you turn this URL into a URI object?
1.560. When creating a URL object using the constructor listed below, what value would you specify as the port number to indicate that the URL should use the default port for the protocol?
1.561. What is the default port for an HTTP (Web) server?
1.562. What are the methods that would be used to retrieve the protocol, host, port, file, and reference of a URL object named url?
1.563. What is the difference between a “port” and a “socket”?
1.564. What does reverse name resolution mean?
1.565. How would you perform reverse name resolution by returning a machine’s host name given a textual representation of a machines IP address?
1.566. If you pass a textual representation of an IP address to the getByName() method, what gets returned by the method getHostName() if the method is not able to resolve the IP address to a host name?
1.567. What method in the InetAddress class can be used to create an InetAddress object of the local host?
1.568. What is the default implementation and form of the returned String of the toString() method in the InetAddress class?
1.569. When using the getByName() method to create an InetAddress object for the local host, what should be passed to the getByName() method?
1.570. When using the getByName() method to create an InetAddress object, what exception must you catch if the host name passed in cannot be resolved to an IP address?
1.571. What class is typically used to create a client socket?
1.572. You created a client Socket object named socket. What method would you use to return an InetAddress object that represents the address it is connected to?
1.573. What is meant by the term “well known ports” of a computer and what is their range of addresses?
1.574. What is the difference between the two transport protocol socket classes ServerSocket and DatagramSocket?
1.575. Is it possible to “ping” an email address?
1.576. What is “nagling” and how do you turn it on and off in Java?
1.577. Swing is only one component of a group of features called the Java Foundation Classes (JFC) used for building graphical user interfaces. What are some of the other features included in the JFC?
1.578. What version of the Java SDK did Sun start to include the Swing API as part of the core part of the product?
1.579. What is the name of the design pattern used by Java for all Swing components?
1.580. Briefly describe each of the three elements of the Model / View / Controller (MVC) design pattern?
1.581. What package would you find most of the AWT events that support the event-delegation model?
1.582. What is the purpose of the pack() method found in the java.awt.Window package?
1.583. What is the height and width of a newly constructed JFrame if neither the pack() method or the setSize() is called?
1.584. What method needs to be called on a newly constructed JFrame to make it visible?
1.585. The default implementation when attempting to close the main application frame is to only hide the frame. This results in the virtual machine still running a frame that is not visible. What new method is included with the Java SDK 1.4 that allows you to exit the application when the JFrame is closed?
1.586. What is a Top-Level Container?
1.587. What are the three generally useful top-level containers included with Swing?
1.588. For a standalone application with a Swing-based GUI, what is the top-level container at the root used in the containment hierarchy?
1.589. What special intermediate container does every top-level container have that is used to contain the visible components in the top-level container’s GUI?
1.590. Suppose you have a JFrame object named frame. What method would you use to get the frame’s content pane?
1.591. When you add the optional menu bar to a top-level container, is it positioned within the content pane? If not, where is it positioned?
1.592. How do you create a menu separator object?
1.593. What is the immediate superclass of the Menu class?
1.594. What is the purpose of a Layout Manager?
1.595. Name some of the Layout Managers include in Java?
1.596. What method would you call to specify the layout manager for a container?
1.597. What is the default layout manager for every JPanel?
1.598. Briefly describe how the FlowLayout layout manager works.
1.599. What is the default Layout Manager for a JFrame’s content pane?
1.600. What are the names of the five regions in the BorderLayout layout manager used to hold components?
1.601. Are there any restrictions as to the number of components that can be placed in any of the regions of the BorderLayout layout manager? If so, what are they?
1.602. Of the five regions in the BorderLayout layout manager, which of the regions would be appropriate for a toolbar? A status line?
1.603. Is it possible to bypass the use of layout managers in and use absolute positioning of components when performing component layout? If so, then how would you go by doing this?
1.604. What is one component that every Dialog box should have?
1.605. What is the immediate superclass of the Dialog class?
1.606. What are the two methods used to hide and display a JDialog box and what package are they from?
1.607. What is the difference between a modal and modeless dialog box?
1.608. Which Swing component would you use to display hierarchical data in a tree format?
1.609. Which method and value would you use for a component to disable it from receiving user input?
1.610. You want to draw a rectangle that is 10 pixels wide and 50 pixels high to the screen starting at 100 pixels down and 20 pixels over. What is the syntax to draw the rectangle?
1.611. What are the primary differences between Java applets and ActiveX controls?
1.612. Which method of the Container class is used to cause the container to lay out its subcomponents again after the components it contains have been added to or modified?
1.613. You have written several Listeners and added them all to the same component. Is it true that all of the Listener’s will get notified of an event in the order they were added?
1.614. Suppose you have an ActionListener object name buttonListener and a JButton object named button1. What statement would you use to register this button with the buttonListener?
1.615. Briefly describe how the CardLayout layout manager works.
1.616. What are the methods used in the CardLayout class that are used to switch from one component to another?
1.617. What is the return type for all methods in all event listener interfaces in the java.awt.event package?
1.618. When implementing the ActionListener interface, what is the only method defined that has to be implemented?
1.619. Which event listener interface (listener type) would you implement with the actions to perform when a user either clicks a button, presses while typing in a text field, or chooses a menu item?
1.620. Which event listener interface (listener type) would you implement with the actions to perform when a user presses a mouse button while the cursor is over a component?
1.621. Which event listener interface (listener type) would you implement with the actions to perform when a component gets keyboard focus?
1.622. Suppose you have a myMenuItem object named m on a Menu named myMenu. Write the statement that will cause the item to not appear on the Menu.
1.623. Is it possible to determine if a user single-clicks or double-clicks a component?
1.624. How does the class CheckboxMenuItem relate to MenuItem?
1.625. What are some of the subclasses of the Component class?
1.626. If you disable a lightweight component by calling setEnabled(false), can the component still receive MouseEvents?
1.627. While a frame or dialog is running and visible, what method (not a Java method) can be used to print its component hierarchy to the standard output stream?
1.628. Consider a container whose layout manager is constructed with the following statement: new GridLayout(5, 10); How many rows are in the container?
1.629. What are the four arguments for the GridLayout manager’s constructor?
1.630. What does the GridBagConstraints.fill field control?
1.631. How do you add components to a layout controlled by a GridBagLayout layout manager?
1.632. What does the weightx and weighty field of the GridBagConstraints control?
1.633. Assume you have an object called chooser of type JFileChooser. Is it possible to choose a directory path instead of a file path in a swing FileChooser dialog box?
1.634. What interface would you implement to create a custom layout manager?
1.635. When implementing the LayoutManager interface, what are the five methods must you provide implementations for?
1.636. What are the commercial uses of Java?
1.637. Why would you want to have more than one catch block associated with a single try block in Java?
1.638. What is the purpose of garbage collection in Java, and when is it used?
1.639. In Java, what is the difference between an Interface and an Abstract class?
1.640. What is an Interface good for?
1.641. Can you have virtual functions in Java? Yes or No. If yes, then what are virtual functions?
1.642. Give an example of using JDBC access the database.
1.643. What is the difference between an Applet and a Java application?
1.644. What do you mean by static methods?
1.645. Write the Java code to declare any constant (say gravitational constant) and to get its value.
1.646. Can you write Java code for declaration of multiple inheritance in Java?
1.647. What is the difference between a component and a container?
1.648. What is the difference between a constructor and a method?
1.649. What are the advantages and disadvantages of using an AVL tree?
1.650. In Java why we use exceptions?
1.651. What is a package?
1.652. Why is it generally a bad idea to make instance variables of a class public?
1.653. You have defined several methods with the same name. When you invoke one of them, how does the compiler determine which one you intend to invoke?
1.654. To pass parameters to a method, Java uses call by value. However, a method is able to make changes to an object that is visible even when the method returns. Explain this contradiction.
1.655. Explain the difference between the Listener interfaces and the Adapter classes.
1.656. In a multi-threaded application, when does one of the secondary threads normally terminate?
1.657. When an object of a subclass is constructed, is any constructor of the superclass invoked? If so, explain how the appropriate superclass constructor would be chosen.
1.658. What are EJB?
1.659. What are the key features of the EJB technology?
1.660. What is J2EE?
1.661. Why does Java not support function/method pointers/references ala C/C++?
1.662. What is Thread in Java and how you use it?
1.663. What are the different ways of creating a thread?
1.664. What is the difference between sleep(), wait() and suspend()?
1.665. What is the meaning of calling a method or object “thread-safe?”
1.666. Which servelet engine you have used and describe its features?
1.667. How is JavaBeans differ from Enterprise JavaBeans?
1.668. What is a JavaBean?
1.669. What are the main differences between JavaBeans and applets?
1.670. What distinguishes a JavaBean from a Servlet?
1.671. What is the difference between an ActiveX control and a JavaBean component?
1.672. Are there tools to package existing C++ objects as Java Beans?
1.673. How do I ensure that my servlet is thread-safe?
1.674. What is a final method or class?
1.675. What is a JAR file?
1.676. What is a WAR file?
1.677. Define lazy evaluation. Why is this a useful technique?
1.678. Describe the characteristics of interfaces, abstract classes, and concrete classes in Java (i.e. description, when each would be used, and what their contents are limited to).
1.679. What is the difference between a shallow copy of an Object and a deep copy of an Object?
1.680. Name a difference between the TCP/IP protocol and the UDP/IP protocol.
1.681. In Java, does adding a ‘throws’ clause change the signature of a method? Explain.
1.682. Write a simple makefile with a rule that compiles file dammit.c into executable dammit and a separate rule to remove the executable.
1.683. What is the difference between a session bean and an entity bean?
1.684. From JNI, if you want to call a method that is overloaded, how do you specify which method you want to call?
1.685. Why is it generally a bad idea to make instance variables of a class public?
1.686. You have defined several methods with the same name. When you invoke one of them, how does the compiler determine which one you intend to invoke?
1.687. To pass parameters to a method, Java uses call by value. However, a method is able to make changes to an object that are visible even when the method returns. Explain this contradiction.
1.688. Explain the difference between the Listener interfaces and the Adapter classes.
1.689. In a multi-threaded application, when does one of the secondary threads normally terminate?
1.690. When an object of a subclass is constructed, is any constructor of the superclass invoked? If so, explain how the appropriate superclass constructor would be chosen.
1.691. What is an object?
1.692. What is a class?
1.693. What is a method?
1.694. What is the signature of a method?
1.695. What is the difference between an instance variable and a class variable?
1.696. What is the difference between an instance method and a class method?
1.697. How do I create an instance of a class?
1.698. What is an abstract method?
1.699. What is an abstract class?
1.700. What is an object reference?
1.701. What is a subclass?
1.702. What is inheritance?
1.703. What is an overloaded method?
1.704. What does it mean to override a method?
1.705. What is the difference between overloading and overriding?
1.706. Can I override the equals method or clone method from class Object to take a parameter or return a value of the type that I specify?
1.707. What is the super keyword used for?
1.708. Does the Java language provide virtual methods, like C++?
1.709. What is a final class?
1.710. What is an interface?
1.711. How does a class implement an interface?
1.712. Can I instantiate an interface?
1.713. Why does a method in an interface appear to be public even though I didn’t declare it to be public?
1.714. How is an abstract class different from an interface?
1.715. Does the Java language allow multiple inheritance?
1.716. What is the instanceof keyword, and what does it do?
1.717. Why do I get the error message Can’t access protected method c1 one... when I try to clone an object?
1.718. How do I design a class so that it supports cloning?
1.719. What are packages, and what are they used for?
1.720. I have seen both java.applet.Applet and Applet used to refer to the Applet class - what’s the difference?
1.721. Why can I get some simple class names “for free,” without using an import declaration?
1.722. Is there a default access modifier for classes and interfaces? For class members (methods, constructors, and fields)?
1.723. What does protected access mean?
1.724. What is the accessibility of a public method or field inside a nonpublic class or interface?
1.725. What is the difference between Integer and int in Java - why do I get the following error: Can’t convert java.1ang.Integer to int?
1.726. How do I treat all 8 bits of a byte as an unsigned quantity?
1.727. How do I work around Java’s lack of true enums?
1.728. Why is goto a reserved keyword in Java-shouldn’t it be outlawed?
1.729. What are some guidelines for using uppercase and lowercase letters in my identifiers?
1.730. Is there any limit to the length of an identifier?
1.731. Why doesn’t Java have user-defined operator overloading?
1.732. Why do I have to put an f after a floating point constant?
1.733. How and when can I cast from one class to another?
1.734. Can I use C-like data structures in Java?
1.735. Are Java objects pointers?
1.736. In a method invocation, does Java pass arguments by reference or by value?
1.737. If the Java language lacks pointers, how do I implement classic pointer structures like linked lists?
1.738. What does the following error message mean: Can’t make a static reference to nonstatic variable?
1.739. In a class method, how can I get the name of the class, or create a new instance of the class?
1.740. Can I write a method that delivers dynamically (at run time) all public methods of an object?
1.741. Can I invoke methods dynamically, from names (Stri ng instances) that are determined at run time?
1.742. How can I accomplish the equivalent of function pointers in Java, for instance, for use in an array?
1.743. Can I allocate an array dynamically?
1.744. How do I initialize an array of objects?
1.745. If arrays are objects, why can’t I use a 1ength method to determine an array’s size?
1.746. What is an exception?
1.747. Why does the compiler complain about InterruptedException when I try to use Thread’s sleep method?
1.748. Why do methods have to declare the exceptions they can throw?
1.749. What’s the difference between a runtime exception and a plain exception — why don’t runtime exceptions have to be declared?
1.750. Given a method that doesn’t declare any exceptions, can I override that method in a subclass to throw an exception?
1.751. When, and by whom, is the main method of a class invoked?
1.752. What are bytecodes?
1.753. What is javap?
1.754. What does it mean to say that Java is interpreted?
1.755. What kind of garbage collection does the Java Virtual Machine use?
1.756. Is finalization broken—why does my finalize method never seem to get invoked?
1.757. I’m having trouble invoking methods on the objects returned from Cl ass’s forName method—how should I use C1 ass .forName?
1.758. Why do I get verifier errors when loading a class file produced by javac?
1.759. How fast are Java programs compared to equivalent C or C++ programs?
1.760. What is an applet?
1.761. How do applets differ from applications?
1.762. Can I write Java code that works both as an applet and as a stand-alone application?
1.763. How do I put an applet into a web page?
1.764. Can I put more than one applet in a web page?
1.765. How do I use the APPLET tag if I want to show users of non—Java-enabled browsers what they're missing?
1.766. What is the complete syntax for using the APPLET tag?
1.767. What are the different pieces that can make up an applet, and how do I install them?
1.768. Where can I put my applet’s class files, and how do I indicate their location using the APPLET tag?
1.769. Can I put my reusable custom classes in a special place so that many different applets can use them?
1.770. How do I determine the width and height of my applet?
1.771. How do I set the background color within the applet area?
1.772. How can I create a transparent background for my applet?
1.773. Can I put menus and a menu bar on my applet?
1.774. I know that cursors can be changed from within frames, but how do I change the cursor in my applet?
1.775. Several applet methods seem special, in that I need to define them even if my own code doesn’t invoke them—what are the methods, and when (and by whom) are they invoked?
1.776. Should applets have constructors?
1.777. How can my applet tell when a user leaves or returns to the web page containing my applet?
1.778. How do I read number information from my applet’s parameters, given that Appl et’s getParameter method returns a String?
1.779. How can I arrange for different applets on a web page to communicate with each other?
1.780. How do I select a URL from my applet and send the browser to that page?
1.781. Can applets on different pages communicate with each other? No, not directly.
1.782. Can I load an applet dynamically into a Java application, and if so, how does the applet get the parameter information it would normally get from the APPLET tag?
1.783. Do I need any special server software or setup to deliver applets?
1.784. What are the Component and Container classes?
1.785. How do I control the positioning of my interface components?
1.786. What are inset values, and how do I set them?
1.787. Can I exert complete control over the size and placement ofcomponents in my interface?
1.788. What do the invalidate and validate methods do?
1.789. Can I add new A WT components to objects already visible on the screen? Yes, you can change your program’s interface as the program is running.
1.790. Can I add the same component to more than one container?
1.791. How can I place an outline around a group of components to show explicitly how the components are grouped?
1.792. What are A WT peers?
1.793. When are peers created and destroyed?
1.794. How do I specify where a window is to be placed?
1.795. How can I draw at the top-left corner of a frame without it being covered by the frame’s border?
1.796. How do I create a borderless window?
1.797. Several operations in the A WT, such as setting the cursor (in JDK 1.02) or creating a dialog box, require specifying a Frame instance—how do I determine the Frame instance containing the current component?
1.798. How do I use a Fi 1 eDi al og object in my applet or application?
1.799. Can I create nonresizable windows?
1.800. What does Component’s requestFocus method do?
1.801. Does the A WT allow you to control the mouse location from within an application?
1.802. Does the A WT provide a standard way to signal a user error by flashing, beeping, or some other means?
1.803. What fonts are available to my A WT program?
1.804. How can I dynamically change font attributes, for instance, rendering a string in successively larger font sizes?
1.805. What information can be carried in the JDK 1.0.2 by an Event object?
1.806. What information do specific event types in the JDK 1.0.2 carry?
1.807. What is the general model in the JDK 1.02 for distributing and handling events?
1.808. What methods should I use in the JDK 1.02 to handle events?
1.809. What is an action event?
1.810. How does the JDK 1.02 handle events for function keys, arrow keys, and so on?
1.811. My frame doesn’t close when I click on Quit/Close in the main menu— how do Ifix this using JDK 1.0.2?
1.812. How is my program notified when a menu item is selected?
1.813. How is my program notified in the JDK 1.02 when a list item is selected or deselected?
1.814. How do I hook up a scroll bar in the JDK 1.0.2 so that it controls the scrolling of some other component?
1.815. Does the AWT in the JDK 1.02 distinguish between mouse clicks made with different buttons on a two- or three-button mouse?
1.816. What information do specific event types in the JDK 1.1 carry?
1.817. How do I catch events in the JDK 1.1 event model?
1.818. What are the different kinds of event listeners, and what are their methods?
1.819. When should I use an event adapter class?
1.820. Do events propagate in the JDK 1.1 as they did in the older AWT event model?
1.821. Will my code written for the older JDK 1.0.2 event model still run in the JDK l.1 ?
1.822. How do I handle action events in the JDK 1.1 ?
1.823. How do I catch menu item events in the 1.1 AWT event model?
1.824. In the JDK 1.1 A WT event model, how is my program notified when a list item is selected or deselected?
1.825. How do I control scrolling in the 1.1 A WT?
1.826. My frame doesn’t close when I click on Quit/Close in the main menu— how do Ifix this using the JDK 1.1 ?
1.827. Is there an event type that signals when a window is resized?
1.828. How do I handle events for function keys, arrow keys, and so on in the JDK 1.1 event model?
1.829. How does the JDK 1.1 distinguish between mouse clicks made with different buttons on a two- or three-button mouse?
1.830. What is the paint method for, when is it invoked, and by whom?
1.831. What should I put in my paint method?
1.832. What is repai nt for, when is it invoked, and by whom?
1.833. Why do my repeated calls to repai nt not have any effect?
1.834. What is update for, when is it invoked, and by whom?
1.835. What drawing occurs fmy applet or other component reappears after being covered by some other window?
1.836. Can I implement an invisible or partly transparent component?
1.837. How does the XOR drawing mode work?
1.838. How do I load an image from the net into my applet?
1.839. How do I load an image from a file in a stand-alone Java application, rather than in an applet?
1.840. When is an image actually loaded - why not immediately?
1.841. How can I make sure that my images are completely loaded before I check for their data or parameters?
1.842. Why does my call to Graphi cs’s drawImage method fail to show the image?
1.843. Can I force Applet’s getImage method to make a new connection for each image rather than reusing a cached version of the image?
1.844. How do I draw text over a background image?
1.845. How do I load and display a transparent GIF image over a background image?
1.846. How can I create an image from a buffer of raw image data (red, green, and blue values for each pixel)?
1.847. What is double buffering—how can I create and draw to an offscreen image?
1.848. How can I get at the raw data of an image, such as the pixel value at a given coordinate?
1.849. Using the JDK l .0.2, can I clear or reset a clipping rectangle that either I or the system has created?
1.850. Using the JDK 1.02, can I copy a subarea of one image into another image?
1.851. How do I control animation with Memo rylmageSou rce?
1.852. Using the JDK 1. 1, how do I reset a clipping rectangle?
1.853. What is a thread?
1.854. How do I create a thread and start it running?
1.855. How does Thread’s stop method work - can I restart a stopped thread?
1.856. How should I stop a thread so that I can start a new thread later in its place?
1.857. How do I specify pause times in my program?
1.858. Why is thread synchronization important for multithreaded programs?
1.859. What is a monitor?
1.860. How does the synchronized keyword work?
1.861. What objects do static synchronized methods use for locking?
1.862. How do the wait and notifyAl 1 /notify methods enable cooperation between threads?
1.863. How do I achieve the effect of condition variables if the Java platform provides me with only wai t and noti fyAl 1 /noti fy methods?
1.864. How do I make one thread wait for one or more other threads to finish?
1.865. What do I use the yie1d method for?
1.866. Does the Java Virtual Machine protect me against deadlocks?
1.867. Why does my multithreaded program run fine on Windows NT/95 but block on Solaris?
1.868. Why do so many applets run a copy of themselves in a separate thread rather than just running as they are?
1.869. How can it be that putting an applet thread to sleep in the wrong place can block other applets from running?
1.870. Can I have a thread wait on an event from the operating system?
1.871. How do I read a line of input at a time?
1.872. How do I read input from the user (or send output) analogous to using standard input and standard output in C or C++?
1.873. Why do I getgarbage results when I use Data lnputStream' s readInt or read Fl oat methods to read in a number from an input string?
1.874. Is there a standard way to read in i nt, 1long, fI oat, and doubt e values from a string representation?
1.875. When do I need to flush an output stream?
1.876. Why do I see no output when I run a simple process, such as r. exec(“/usr/bin/ 1 s”)?
1.877. What’s the difference between a URL instance and a URLConnecti on instance?
1.878. How do I make a connection to a URL?
1.879. How do I read from a remote file if I have its URL?
1.880. Why do I get a nul 1 result when I use the getHeader ... methods in the URLConnecti on class?
1.881. What is URLConnecti on’s get0utputStream method intended to work with on the server side?
1.882. How do I send data from my Java program to a CGI program?
1.883. Can I write (from my applet) to an external file on a URL?
1.884. How can my Java stand-alone application fetch documents in the same fashion as (partially simulating) a browser?
1.885. Why do I get a security exception when I try to connect to an external URL from an applet? (If I run equivalent code as an application, it works fine.)
1.886. The API doesn’t list any constructors for InetAddress —how do I create an InetAddress instance?
1.887. Is it possible to get the real local host IP?
1.888. How can I create an InetAddress instance from an IP address that has no DNS entry?
1.889. How do I create and use sockets in Java?
1.890. How can I get a server socket and client socket going on a stand-alone machine, not on a network?
1.891. Will raw sockets ever be introduced—and if not, how can I create ICMP messages so that I can do operations like `ping'?
1.892. How do I detect if an input stream belonging to a socket has been terminated by the remote host?
1.893. If the Socket class has no support for firewalls, how can I get my Java program with sockets to work through different firewalls?
1.894. How do I create a nonblocking server socket in Java?
1.895. Is there a standard Java way to specify the address of the host doing the listening when instantiating a ServerSocket?
1.896. How do I send and/or receive datagram packets?
1.897. When will I be able to create a broadcast datagram packet? Starting with the JDK 1.1, you can create broadcast datagram packets.
1.898. Why doesn’t String’s repl ace method have any effect when I apply it to a string?
1.899. How can I access native operating system calls from my Java program?
1.900. Does Java provide standard iterator functions for inspecting a collection of objects?
1.901. The Math. random method is too limited for my needs—how can I generate random numbers more flexibly?
1.902. How do I play sounds in an applet?
1.903. How do I play several audio clips simultaneously?
1.904. Can I tell when an audio clip has finished playing?
1.905. How can I play audio in a stand-alone application?
1.906. What audio formats does the JDK support besides Sun’s . au format? No other ones; the JDK 1.0.2 (and 1.1) supports only the . au format.
1.907. Is there a method for generating sounds of a given frequency, something along the lines of playTone (int frequency, int duration) ?
1.908. What’s the difference between Java and JavaScript?
1.909. How can I obtain a performance profile of my Java program?
1.910. What is the purpose of the executable files that have an extra _g at the ends of their names (e.g., j ava_g)?
1.911. If Java is platform-independent, why doesn’t it run on all platforms?