My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Java Questions
Posted Date: 16 May 2008 Resource Type: Articles/Knowledge Sharing Category: Placement Papers
|
Posted By: Shanthi M Member Level: Diamond Rating: Points: 1
|
|
|
|
Java Sample Questions
• Can a abstract method have the static qualifier? Answer: No
• What are the different types of qualifier and What is the default qualifier? Answer: public, protected, private, package (default)
• What is the super class of Hashtable? Answer: Dictionary
• What is a lightweight component? Answer: Lightweight components are the one which doesn't go with the native call to obtain the graphical units.They share their parent component graphical units to render them.Example, Swing components
• What is a heavyweight component? Answer: For every paint call, there will be a native call to get the graphical units.Example, AWT.
• What is an applet? Answer: Applet is a program which can get downloaded into a client environment and start executing there.
• What do you mean by a Classloader? Answer: Classloader is the one which loads the classes into the JVM. • What are the implicit packages that need not get imported into a class file? Answer: java.lang
• How are this() and super() used with constructors? Answer: Othis() is used to invoke a constructor of the same class.super() is used toinvoke a superclass constructor
• Difference between Swing and Awt? Answer: AWT are heavy-weight componenets.Swings are light-weight components.Hence swing works faster than AWT.
• What is the base class for Error and Exception? Answer: Throwable
• What is the byte range?? Answer: 128 to 127
• Is JVM a compiler or an interpreter? Answer: Interpreter
• When you think about optimization, what is the best way to findout the time/memory consuming process? Answer: Using profiler
• Write a for loop that will print out all the multiples of 3 from 3 to 36, that is: 3 6 9 12 15 18 21 24 27 30 33 36. Answer: Here are two possible answers.Assume that N has been declared to be a variable of type int: for ( N = 3;N <= 36;N = N + 3 ) { System.out.println( N ); } or for ( N = 3;N <= 36;N++ ) { if ( N % 3 == 0 ) System.out.println( N ); }
• Fill in the following main() routine so that it will ask the user to enter an integer, read the user's response, and tell the user whether the number entered is even or odd.(You can use TextIO.getInt() to read the integer.Recall that an integer n is even if n % 2 == 0.) public static void main(String[] args) { } Answer: The problem already gives an outline of the program.The last step, telling the user whether the number is even or odd, requires an if statement to decide between the two possibilities. public static void main (String[] args) { int n; TextIO.put("Type an integer: "); n = TextIO.getInt(); if (n % 2 == 0) System.out.println("That's an even number."); Else System.out.println("That's an odd number."); }
• Show the exact output that would be produced by the following main() routine: public static void main(String[] args) { int N; N = 1; while (N <= 32) { N = 2 * N; System.out.println(N); } } Answer: The exact output printed by this program is: 2 4 8 16 32 64
• What output is produced by the following program segment? Why? String name; int i; boolean startWord; name = "Richard M.Nixon"; startWord = true; for (i = 0; i < name.length(); i++) { if (startWord) System.out.println(name.charAt(i)); if (name.charAt(i) == ' ') startWord = true; else startWord = false; } Answer: This is a tough one! The output from this program consists of the three lines: R M N
• Consider a subroutine processData that has the header static void processData() throws IOException Write a try...catch statement that calls this subroutine and prints an error message if an IOException occurs. Answer: try { processData(); } catch (IOException e) { System.out.println( "An IOException occurred while precessing the data."); }
• What is the purpose of the following subroutine? What is the meaning of the value that it returns, in terms of the value of its parameter? static String concat( String[] str ) { if (str == null) return ""; String ans = ""; for (int i = 0; i < str.length; i++) { ans = ans + str[i]; return ans; }
• Write a complete subroutine that finds the largest value in an array of ints.The subroutine should have one parameter, which is an array of type int[].The largest number in the array should be returned as the value of the subroutine. Answer: public static int getMax(int[] list) { int max = list[0]; for (int i = 1; i < list.length; i++) { if (list[i] > max) max = list[i]; } return max; }
• Is "abc" a primitive value? Answer: The String literal "abc" is not a primitive value. It is a String object.
• What restrictions are placed on the values of each case of a switch statement? Answer: During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.
• What modifiers may be used with an interface declaration? Answer: An interface may be declared as public or abstract.
• Is a class a subclass of itself? Answer: A class is a subclass of itself.
• What is the difference between a while statement and a do statement? Answer: A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.
• What modifiers can be used with a local inner class? Answer: A local inner class may be final or abstract.
• What is the purpose of the File class? Answer: The File class is used to create objects that provide access to the files and directories of a local file system.
• Can an exception be rethrown? Answer: Yes, an exception can be rethrown.
• When does the compiler supply a default constructor for a class? Answer: The compiler supplies a default constructor for a class if no other constructors are provided.
• If a method is declared as protected, where may the method be accessed? Answer: Classes or interfaces of the same package or may only access a protected method by subclasses of the class in which it is declared.
• Which non-Unicode letter characters may be used as the first character of an identifier? Answer: The non-Unicode letter characters $ and _ may appear as the first character of an identifier.
• What restrictions are placed on method overloading? Answer: Two methods may not have the same name and argument list but different return types.
• What is casting? Answer: There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
• What is the return type of a program's main() method? Answer: A program's main() method has a void return type.
• What class of exceptions are generated by the Java run-time system? Answer: The Java runtime system generates RuntimeException and Error exceptions.
• What class allows you to read objects directly from a stream? Answer: The ObjectInputStream class supports the reading of objects from input streams.
• Is "abc" a primitive value? Answer: The String literal "abc" is not a primitive value. It is a String object.
• What restrictions are placed on the values of each case of a switch statement? Answer: During compilation, the values of each case of a switch statement must evaluate to a value that can be promoted to an int value.
• What modifiers may be used with an interface declaration? Answer: An interface may be declared as public or abstract.
• Is a class a subclass of itself? Answer: A class is a subclass of itself.
• What is the difference between a while statement and a do statement? Answer: A while statement checks at the beginning of a loop to see whether the next loop iteration should occur. A do statement checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the body of a loop at least once.
• What modifiers can be used with a local inner class? Answer: A local inner class may be final or abstract.
• What is the purpose of the File class? Answer: The File class is used to create objects that provide access to the files and directories of a local file system.
• Can an exception be rethrown? Answer: Yes, an exception can be rethrown.
• When does the compiler supply a default constructor for a class? Answer: The compiler supplies a default constructor for a class if no other constructors are provided.
• If a method is declared as protected, where may the method be accessed? Answer: Classes or interfaces of the same package or may only access a protected method by subclasses of the class in which it is declared.
• Which non-Unicode letter characters may be used as the first character of an identifier? Answer: The non-Unicode letter characters $ and _ may appear as the first character of an identifier.
• What restrictions are placed on method overloading? Answer: Two methods may not have the same name and argument list but different return types.
• What is casting? Answer: There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference. • What is the return type of a program's main() method? Answer: A program's main() method has a void return type.
• What class of exceptions are generated by the Java run-time system? Answer: The Java runtime system generates RuntimeException and Error exceptions.
• What class allows you to read objects directly from a stream? Answer: The ObjectInputStream class supports the reading of objects from input streams.
• What is the difference between a field variable and a local variable? Answer: A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.
• How are this() and super() used with constructors? Answer: this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
Important Program in Java Technology: 1. Write a program using switch case by accessing input from user? 2. Write a program using multiple catch statements. 3. When you click the button add the text field item to list box? 4. Write a program to display number of time the button clicked? 5. Write a program using overloading and overriding? 6. Write a program using packages? 7. Write a program using java event handling mechanism? 8. Program to create thread using both way? 9. Design a form using checkbox and list box. 10. Write a program to create window and file dialogs in java ?
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
Watch TV Channels
Watch Asianet TV onlineKairali TV in InternetSurya TV onlineAmritha TV Channel
|