Java Programming Fundamentals
Test your knowledge of Java programming including OOP concepts, collections, generics, file I/O, and web technologies like Servlets and JSP.
Questions
void main(){ char far *p = 0x417; *p=64; }
- Reboot the Machine
- Disable the print screen key
- Change the default screen color
- puts Capslock on
void main() { int a[2][3]={{1,2,3},{4,5,6}}; printf("%d\n",++**(a+1)); }
- 5
- garbage value
- compile error
- 2
Which of the following operator when used with numbers is not efficient ?
- NOT >
- NOT <
- NOT =
- None of the above
ejbCreate() method of CMP bean returns
- null
- Primary Key class
- Home Object
- Remote Object
Which of the following statements hold true in the following program? package generics; import java.util.ArrayList; import java.util.List; public class Ques04 { public static void main(String[] args) { List<? extends Instrument> allInstruments = new ArrayList(); // -->X allInstruments.add(new Guitar()); allInstruments.add(new Violin()); } } interface Instrument { public void play(); } class Guitar implements Instrument { public void play(){ System.out.println("Playing Guitar."); } } class Violin implements Instrument { public void play(){ System.out.println("Playing Violin."); } }
- The program will not compile.
- The program will compile but will throw run-time exception.
- The statement 'X' manifests that objects of type Instrument as well as sub-types can be added to the list 'allInstruments'.
- It is not possible to add any type of objects to the list 'allInstruments'.
what is the output of compiling an running the following code? import java.util.*; class CheckTest { public static void main(String [] args) { Hashtable ht = new Hashtable<String, String>(); ht.put("chec", "check"); ht.put(1000, "check"); // line 1 ht.put("check", 20.01); // line 2 System.out.print(ht.get("chec") + " "); System.out.print(ht.get(1000) + " "); //line 3 System.out.print(ht.get("check")); //line 4 } }
- Compilation fails due to error at line 1,2,3,4
- Compilation fails due to error at line 3,4
- Compiles fine and exception is thrown at runtime.
- Compiles fine and prints "check check 20.01"
A JSP page is opened in a particular Session. A button is present in that JSP page onclick of which a new Window gets opened.
- The Session is not valid in the new Window
- The Session is valid in the new Window
- The Scope is not valid in the new Window
- The Scope is valid in the new Window
In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object ?
- getServletInfo()
- getInitParameters()
- getServletConfig()
- None of the above
What is the output for the following lines of code? import java.io.*; public class FileHandling { public static void main (String[] arg) throws Exception { File f = new File ("ll.txt"); FileOutputStream s = new FileOutputStream(f); PrintStream p = new PrintStream (s); p.println("hi"); } }
- A. It would fail to compile
- B. It would generate a run-time error on execution.
- C. It would execute, but ask the user to specify the directory in which to create ll.txt.
- D. It would execute without an error and print "hi" to a file called ll.txt
What is the output for the following lines of code? 1: String str = "Welcome"; 2: 3: str.concat(" to Java!"); 4: 5: System.out.println(str);
- A) Strings are immutable, compilation error at line 3.
- B) Strings are immutable, runtime exception at line 3.
- C) Prints "Welcome".
- D) Prints "Welcome to Java!".
What is the output for the following lines of code? 1: class Test 2: { 3: static void show() 4: { 5: System.out.println("Static method in Test"); 6: } 7: } 8: public class Q4 extends Test 9: { 10: void show() 11: { 12: System.out.println("Overridden static method in Q4"); 13: } 14: public static void main(String[] args) 15: { 16: } 17: }
- Compilation error at line 3.
- Compilation error at line 10.
- No compilation error, but runtime exception at line 3.
- No compilation error, but runtime exception at line 10.
What is the output for the following lines of code? 1: public class Q8 2: { 3: int i = 20; 4: static 5: { 6: int i = 10; 7: 8: } 9: public static void main(String[] args) 10: { 11: Q8 a = new Q8(); 12: System.out.println(a.i); 13: } 14: }
- Compilation error, variable "i" declared twice.
- Compilation error, static initializers for initialization purpose only.
- Prints 10.
- Prints 20.
Which method names follow the JavaBeans standard?
- addSize
- getCust
- deleteRep
- putDimensions
class Fizz { int x = 5; public static void main(String[] args) { final Fizz f1 = new Fizz(); Fizz f2 = new Fizz(); Fizz f3 = FizzSwitch(f1,f2); System.out.println((f1 == f3) + " " + (f1.x == f3.x)); } static Fizz FizzSwitch(Fizz x, Fizz y) { final Fizz z = x; z.x = 6; return z; } } What is the result?
- true true
- false true
- true false
- false false
- Compilation fails.
- An exception is thrown at runtime.
Given: class Sixties { public static void main(String[] args) { int x = 5; int y = 7; System.out.print(((y * 2) % x)); System.out.print(" " + (y % x)); } } What is the result?
- 1 1
- 1 2
- 2 1
- 2 2
- 4 1
- 4 2
Given: public class MyOuter { public static class MyInner { public static void foo() { } } } Which, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?
- MyOuter.MyInner m = new MyOuter.MyInner();
- MyOuter.MyInner mi = new MyInner();
- MyOuter m = new MyOuter();
- MyInner mi = new MyOuter.MyInner();
public static void main(String[] args) { Queue q = new LinkedList(); q.add("Veronica"); q.add("Wallace"); q.add("Duncan"); showAll(q); } public static void showAll(Queue q) { q.add(new Integer(42)); while (!q.isEmpty()) System.out.print(q.remove() + " "); }
- Veronica Wallace Duncan
- Veronica Wallace Duncan 42
- Duncan Wallace Veronica
- 42 Duncan Wallace Veronica
- Compilation fails
- An exception occurs at runtime.
Properties meant for protecting a field in a class?
- True
- False
You can not change fields internal implementation over time?
- True
- False
We achieve Encapsulating Type State with Properties?
- True
- False