Java Programming Fundamentals
Test your knowledge of Java syntax, classes, constructors, and I/O operations along with general programming concepts like refactoring and software design tools.
Questions
Given: 1. public class A { 2. public void doit() { 3. } 4. public String doit() { 5. return “a”; 6. } 7. public double doit(int x) { 8. return 1.0; 9. } 10.} What is the result?
- An exception is thrown at runtime
- Compilation fails because of an error in line 7
- Compilation fails because of an error in line 4.
- Compilation succeeds and no runtime errors with class A occur
Given: 10. class Line { 11. public static class Point { } 12. } 13. 14. class Triangle { 15. // insert code here 16. } Which code, inserted at line 15, creates an instance of the Point class defined in Line?
- Point p = new Point();
- Line.Point p = new Line.Point();
- The Point class cannot be instatiated at line 15
- Line 1 = new Line() ; 1.Point p = new 1.Point();
Given: 10. class Line { 11. public class Point { public int x,y; } 12. public Point getPoint() { return new Point(); } 13. } 14. class Triangle { 15. public Triangle() { 16. // insert code here 17. } 18. } Which code, inserted at line 16, correctly retrieves a local instance of a Point object?
- Point p = Line.getPoint();
- Line.Point p = Line.getPoint();
- Point p = (new Line()).getPoint();
- Line.Point p = (new Line()).getPoint();
Given: 10. class One { 11. public One() { System.out.print(1); } 12. } 13. class Two extends One { 14. public Two() { System.out.print(2); } 15. } 16. class Three extends Two { 17. public Three() { System.out.print(3); } 18. } 19. public class Numbers{ 20. public static void main( String[] argv) { new Three(); } 21. } What is the result when this code is executed?
- 1
- 3
- 123
- 321
When comparing java.io.BufferedWriter to java.io.FileWriter, which capabilities exist as a method in only one of the two?
- Closing the stream
- flushing the stream
- writing to the stream
- writing a line separator to the stream
Output for the below code : int i = 10; while (++i <= 10) { i++; } System.out.print(i);
- 10
- 11
- 12
- Line 5 will be never reached
touch command can be used for ?
- To create a directory
- To change timestamp of a file
- To edit a file
- To create a empty file
Which of the following is NOT a tool used to aid software design?
- Flow charts
- Pseudocode
- Bytecode
- UML
Pointers are a mainstay of C programming but faulty pointer arithmetic can often lead to serious bugs. Which of the following C-derived languages has opted to eliminate C-style pointers altogether?
- C#
- Java
- Objective-C
- C++
Which of the following is a typical activity that takes place during the process of code refactoring?
- Buffer overflows are eliminated
- Variables are renamed to provide more meaningful context
- Exception handlers are added to catch runtime errors
- New features are added based on the latest iterative design changes