Adv Java

1. What Is the Java Technology 2. Points to keep in mind for pyramid. 3. Java Pyramid Program on type 1 4. Java Pyramid Program on type 2 5. Java Pyramid Programs on Type 3 6. Java Pyramid Programs on type 4 7. Java Pyramid Programs on type 5 8. Classes and Objects 9. Recursive functions 10. Constructors in Java 11. Method Overloading 12. Constructor Overloading 13. Inheritance in Java 14. Interface in Java 15. Method Overriding and Hiding Method 16. The final keyword 17. Exception Handling 18. Properties, System & Runtime Class in Java 19. Building Java GUI 20. Layout Managers 21. Menu Bar 22. Applets 23. Threading 24. Java Netwoking 25. Programs for Science and Engineer 26. Prg to demonstrate pre and post increment 27. Prg to convert Farenheit to Celsius temperature 28. Prg to convert kilogram to different units 29. Prg to calculate surface area and volume of sphere 30. Prg to calculate frequency 31. Prg to determine co-ordinate points 32. Prg to determine Equilateral, Isosceles or Scalene triangle 33. Prg to demonstrate conditional operator 34. Prg to calculate Final and initial interest amount 35. Prg to separate entered number 36. Prg to examine while loops and conditions 37. Prg to calculate number of year 38. Prg to find Armstrong number or not 39. Prg to find all Armstrong number 40. Prg to find limited Armstrong number 41. Prg to find Armstrong number using user defined function 42. Prg to find frequency of student 43. Prg to find maximum and minimum number 44. Prg to print number triangle 45. Prg to print vertical number triangle 46. Prg to print number triangle 47. Prg to print binary right angle triangle 48. Prg to print * triangle 49. Prg to to print rhombus 50. Prg to print entered number triangle 51. Prg to to find nCr and nPr 52. Prg to enter an element in array 53. Prg to sort number using array 54. Prg to find the position of element in array 55. Prg to find the position of element in array using boolean flag 56. Prg to add one extra element in an array 57. Prg to find the equation of line 58. Prg to find the common element from two array 59. Prg to find the highest scorer 60. Prg to create a square of number 61. Prg to create Pascal triangle 62. Prg to subtraction, multiplication and division using methods and classes 63. Prg to determine salary grade 64. Prg for complex number 65. Prg to calculate area 66. Prg for Greatest Common Divisior 67. Prg for displaying studenta mark sheet 68. Prg for demonstrating inheritance 69. Prg to calculate area of triangle 70. Prg for calculating volume of sphere or hemisphere 71. Prg for demonstrate classes 72. Prg for employee details 73. Prg for demonstrating super and base class 74. Prg for Bank Account 75. Prg for professor and student details 76. Prg for Addition, Multiplication and finding Transpose of two matrix 77. Prg for counting number of words in a string 78. Prg to count number of vowels and consonants in a string 79. Prg to fine number of upper case, lower case, white spaces and digit in a string 80. Prg to fine number of upper case, lower case, white spaces and digit in a string without inbuilt function 81. Prg to arrange a string in alphabetic order 82. Prg to count the number of character occurrence in a string 83. Prg to find the string length and character position 84. Prg for converting first character of word into upper case 85. Prg for demonstrating vectors for manipulating records 86. Prg for manupulting items record using vectors 87. Prg for bank transaction 88. Prg for counting number of days between any two different date 89. Prg for exception handling 90. Prg for throwing exception 91. Prg for exception 92. Prg to throw exception when number is invalid 93. Prg for renaming the current thread 94. Prg for demonstrating strat method of thread 95. Prg to demonstrate sleep and and join method of thread 96. Prg to demonstrate yield method of thread 97. Prg for demonstrating thread in class inheritance 98. Threading program using runnable interface 99. Thread program using sleep 100. Java Applet program for creating fancy round eye 101. Java Applet program for creating fancy face 102. Java Applet program for drawing string 103. Java Applet program for creating fancy face 104. Java Applet program for displaying fancy fonts 105. Java Applet program for drawing and filling rectangle 106. Java Applet program for creating house 107. Java Applet program to show lifecycle of applet 108. Java Applet program for creating polygon 109. Java Applet program for creating rectangle 110. Java Applet program for drawing line 111. Java Applet program for getting applet width and height 112. Interview Question & Answer part 1 113. Interview Question & Answer part 2 114. Interview Question & Answer part 3 115. Interview Question & Answer part 4 116. Interview Question & Answer part 5 117. Interview Question & Answer part 6 118. Interview Question & Answer part 7 119. Interview Question & Answer part 8 120. Interview Question & Answer part 9 121. Interview Question & Answer part 10 122. Interview Question & Answer part 11
Pr.Pg Next Pg

JAVA Interview Questions and Answers Part 5


41. Why do we need wrapper classes?

  • It is sometimes easier to deal with primitives as objects. Moreover most of the collection classes store

  • objects and not primitive data types. And also the wrapper classes provide many utility methods also. Because of these resons we need wrapper classes.

  • And since we create instances of these classes we can store them in any of the collection classes and pass them around as a collection. Also we can pass them around as method parameters where a method expects an object.


42. What are checked exceptions?

  • Checked exception are those which the Java compiler forces you to catch. e.g. IOException are checked Exceptions.


43. What are runtime exceptions?

  • Runtime exceptions are those exceptions that are thrown at runtime because of either wrong input data or because of wrong business logic etc. These are not checked by the compiler at compile time.


44. What is the difference between error and an exception?

  • An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime.

  • While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist.

  • Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.).


45. How to create custom exceptions?

  • Your class should extend class Exception, or some more specific type thereof.


46. If I want an object of my class to be thrown as an exception object, what should I do?

  • The class should extend from Exception class. Or you can extend your class from some more precise

  • exception type also.


47. How does an exception permeate through the code?

  • An unhandled exception moves up the method stack in search of a matching When an exception is thrown from a code which is wrapped in a try block followed by one or more catch blocks, a search is made for matching catch block.

  • If a matching type is found then that block will be invoked. If a matching type is not found then the exception moves up the method stack and reaches the caller method. Same procedure is repeated if the caller method is included in a try catch block. This process continues until a catch block handling the appropriate type of exception is found. If it does not find such a block then finally the program terminates.


48. What are the different ways to handle exceptions?

  • There are two ways to handle exceptions,

    1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions.

    2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions.

49. 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?

  • In the first approach as a programmer of the method, you urself are dealing with the exception. This is fine if you are in a best position to decide should be done in case of an exception. Whereas if it is not the responsibility of the method to deal with it's own exceptions, then do not use this approach. In this case use the second approach.

  • In the second approach we are forcing the caller of the method to catch the exceptions, that the method is likely to throw. This is often the approach library creators use. They list the exception in the throws clause and we must catch them. You will find the same approach throughout the java libraries we use.


50. Is it necessary that each try block must be followed by a catch block?

  • It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.

Pr.Pg border                                              Next Pg