COLLEGE FOR LEGAL STUDIES (CLS), YOLA
DEPARTMENT OF COMPUTER SCIENCE
(AN AFFILIATE OF UNIVERSITY OF MAIDUGURI)
Course Title: Intro to Programming using Java II Duration: 3 Hours
Course code: DCS 211 Date:
DIPLOMA II
Instruction: Attempt All Questions in Section “A” and any two questions in Section “B”.
Section A carry 30 marks and section B carry 40 marks.
SECTION A (OBJECTIVES)
1. How does Java achieve platform independence?
a) By using native compilers for each platform.
b) By compiling source code to bytecode, which is then executed by the JVM.
c) By requiring recompilation on every different operating system.
d) By only running on specific hardware certified by Oracle.
2. What component executes the Java bytecode?
a) The Java Compiler (javac)
b) The Java Virtual Machine (JVM)
c) The Java Development Kit (JDK)
d) The Java Runtime Environment (JRE)
3. Which feature of Java helps in making it "robust" (reliable)?
a) Pointers
b) Multiple inheritance
c) Garbage collection and exception handling
d) Manual memory allocation
4. What feature allows Java to execute multiple parts of a program concurrently?
a) Polymorphism
b) Multithreading
c) Encapsulation
d) Platform Independence
5. The portability of Java is primarily due to its:
a) Simple syntax
b) Platform-independent bytecode
c) Garbage collector
d) Security features
6. What is the primary role of the Java Virtual Machine (JVM)?
a) To write Java source code.
b) To compile Java source code.
c) To execute Java bytecode.
d) To package Java applications.
7. Is the JVM itself platform-dependent or platform-independent in its implementation?
a) Always Platform-Independent
1
b) Platform-Dependent (each OS needs its own JVM implementation)
c) Depends on the Java version
d) Neither
8. What is bytecode in the context of Java?
a) Native machine code for a specific processor.
b) An intermediate, platform-independent representation of Java code.
c) The Java source code itself.
d) A type of encryption used by Java.
9. What does JDK stand for?
a) Java Virtual Kit
b) Java Runtime Kit
c) Java Development Kit
d) Java Deployment Kit
10. Which of these components is typically part of the JDK?
a) Compiler (javac)
b) Web Browser
c) Word Processor
d) Operating System Kernel
11. What does JRE stand for?
a) Java Development Environment
b) Java Runtime Environment
c) Java Resourcae Executor
d) Java Release Edition
12. If you only want to run Java programs, but not develop them, which component is
sufficient to install?
a) JDK
b) JRE
c) JVM only
d) javac only
13. What is the function of the Garbage Collector in Java?
a) To compile Java code.
b) To enforce security rules.
c) To automatically reclaim memory occupied by objects that are no longer
referenced.
d) To manage network connections.
14. Can programmers explicitly delete objects in Java using a 'delete' keyword?
a) Yes, using the delete keyword.
b) Yes, using the free() method.
c) No, garbage collection handles object deletion automatically.
d) Only in specific enterprise editions.
15. What is the Classpath used for?
a) Defining the order of execution in a program.
b) Specifying the location where the JVM and compiler look for .class files.
2
c) Storing user credentials for Java applications.
d) Managing thread priorities.
16. Which OOP principle is mentioned as an advantage of Java?
a) Global variables
b) Goto statements
c) Encapsulation, inheritance, polymorphism
d) Direct memory access
17. Why might Java performance be slower compared to languages like C++?
a) Because Java code is shorter.
b) Because Java has more keywords.
c) Due to the overhead of the JVM and automatic garbage collection.
d) Because Java does not support multithreading.
18. What potential drawback is associated with Java's automatic memory management?
a) Increased risk of memory leaks caused by programmers.
b) Can lead to slower performance and increased memory usage in some cases.
c) Makes the code harder to read.
d) Requires manual intervention frequently.
19. Which component includes development tools like the compiler?
a) JDK
b) JRE
c) JVM
d) Classpath
20. Which component includes libraries needed to run Java applications plus the JVM?
a) JDK
b) JRE
c) Just the JVM
d) The source code
21. What is the primary "Use Case" for the JRE according to the table?
a) Writing and compiling Java code.
b) Running a Java application on a system.
c) Converting bytecode into source code.
d) Debugging Java code.
22. The working of the JDK involves compiling a .java file into what?
a) A .jvm file
b) An executable .exe file
c) A .class file containing bytecode
d) A library .jar file
23. What does the Bytecode Verifier do during runtime?
a) Executes the bytecode.
b) Checks the bytecode for security and correctness.
c) Loads classes from disk.
d) Converts source code to bytecode.
24. The JVM is also known as an interpreter because it:
a) Writes Java code.
3
b) Compiles Java code.
c) Can execute the Java program line by line (interpreting bytecode).
d) Verifies the Java code.
25. Which three activities is the JVM mainly responsible for, according to the
diagram/text?
a) Compiling, Debugging, Running
b) Writing, Saving, Compiling
c) Loading, Linking, Initialization
d) Verifying, Optimizing, Executing
26. What is a Java identifier?
a) A reserved keyword.
b) A primitive data type.
c) A name given to a variable, class, method, etc.
d) An operator symbol.
27. Can a Java identifier start with a number (digit)?
a) Yes, always.
b) Yes, if it also contains letters.
c) No, identifiers cannot start with a digit.
d) Only if the number is 0.
28. Are the identifiers myVariable and myvariable considered the same in Java?
a) Yes, Java identifiers are case-insensitive.
b) No, Java identifiers are case-sensitive.
c) It depends on the compiler settings.
d) Only if they are declared in different classes.
29. Is there a strict limit on the length of a Java identifier?
a) Yes, it must be 8 characters or less.
b) Yes, it must be 32 characters or less.
c) No, there is no strict limit (though a reasonable length is advised).
d) Yes, it depends on the data type it names.
30. Can you use a reserved word like class or int as an identifier?
a) Yes, if you capitalize it (e.g., Class).
b) Yes, if it's enclosed in quotes.
c) No, reserved words cannot be used as identifiers.
d) Only for local variables.
31. Which of the following is a VALID Java identifier?
a) 123geeks
b) my Variable
c) a+c
d) $myvariable
32. What is the general purpose of reserved words in a programming language?
a) To serve as comments.
b) To represent built-in functionalities or predefined values.
c) To define variable names only.
d) To specify the author of the code.
4
33. Are the keywords const and goto currently used in Java according to the note?
a) Yes, they are fundamental keywords.
b) const is used, but goto is not.
c) goto is used, but const is not.
d) No, they are reserved but not currently used.
34. What are true, false, and null technically classified as in Java?
a) Keywords
b) Literals
c) Identifiers
d) Operators
35. Can true, false, or null be used as variable names?
a) Yes, they are not reserved.
b) Only null can be used.
c) Only true and false can be used.
d) No, even though literals, they cannot be used as identifiers.
36. Which keyword is used to define a blueprint for creating objects?
a) object
b) struct
c) class
d) new
37. Which keyword refers to the current object within an instance method or constructor?
a) this
b) super
c) current
d) object
38. What is the purpose of the import keyword?
a) To define a new class.
b) To export a package.
c) To reference classes or interfaces from other packages.
d) To create an object.
39. Which access specifier allows access from anywhere?
a) public
b) protected
c) private
d) global
40. Java is described as a "statically typed" language. What does this mean?
a) Variables can change type during execution.
b) The type of a variable is checked at compile-time.
c) All variables must be declared static.
d) Data types are defined by the user only.
41. What are the two main categories of data types in Java mentioned?
a) Simple and Complex
b) Primitive and Non-Primitive (or Reference)
5
c) Static and Dynamic
d) Numeric and Textual
42. Which of the following is NOT a primitive data type in Java?
a) int
b) boolean
c) char
d) String
43. What values can a boolean variable hold?
a) 0 or 1
b) "true" or "false" (as strings)
c) true or false (as boolean literals)
d) Any integer value
44. What is the size of the double data type?
a) 16 bits
b) 32 bits
c) 64 bits
d) 128 bits
45. What is the default value for the char primitive type?
a) ' ' (space)
b) null
c) \u0000 (null character)
d) 0
46. What is the "State" of an object represented by?
a) Its methods
b) Its attributes (variables)
c) Its class name
d) Its memory location
47. What is an Array in Java?
a) A primitive data type.
b) A collection of different types of variables.
c) A group of like-typed variables referred to by a common name.
d) A dynamic list that can change size automatically.
48. Are arrays in Java dynamically allocated?
a) Yes.
b) No.
c) Only if declared final.
d) Only for primitive types.
49. How do you find the length of an array in Java?
a) Using the size() method.
b) Using the sizeof operator.
c) Using the length member variable (e.g., myArray.length).
d) Using the getLength() function.
50. What is the starting index of an array in Java?
a) 1
6
b) -1
c) 0
d) It depends on the declaration.
51. What is the direct superclass of any array type in Java?
a) Array
b) Collection
c) Object
d) There is no superclass.
52. What is a variable in Java?
a) A fixed value that never changes.
b) A Java keyword.
c) A container (or named memory location) for storing data values.
d) An operation performed on data.
53. Where is a Local Variable defined?
a) Outside any class.
b) Inside a class but outside any method.
c) Within a method, constructor, or block.
d) Only in static methods.
54. What is the scope of a local variable?
a) The entire class.
b) The entire program.
c) Only within the block, method, or constructor where it is declared.
d) Accessible from any package.
55. Is initialization mandatory for local variables before use?
a) Yes.
b) No, they have default values.
c) Only if they are final.
d) Only for numeric types.
56. Is initialization mandatory for instance variables?
a) Yes, always.
b) No, they have default values (e.g., 0, 0.0, false, null).
c) Only if they are private.
d) Only if the class is public.
57. What is another name for Static Variables?
a) Local Variables
b) Instance Variables
c) Class Variables
d) Method Variables
58. Which keyword is used to declare a static variable?
a) instance
b) class
c) static
d) global
7
59. If operators have the same precedence, what rule determines the order of evaluation?
a) Random order
b) Always left-to-right
c) Always right-to-left
d) Associativity (either left-to-right or right-to-left depending on the operator)
60. In the expression a = b + c * d;, which operation is likely performed first based on
standard precedence?
a) a = b
b) b + c
c) c * d
d) (b+c)*d
SECTION B (ESSAY)
Instruction: Answer only two (2) questions in this section
QUESTION ONE
a. Explain “Write Once, Run Anywhere" (WORA) in the context of Java.
b. Define Object-Oriented Programming (OOP) and list the four main concepts
associated with OOP.
QUESTION TWO
a. What is a Java identifier?
b. List and explain the rules that must be followed when naming identifiers in Java.
Provide examples of valid and invalid identifiers based on these rules.
QUESTION THREE
a. What are Arithmetic Operators in Java?
b. Provide examples of at least four different arithmetic operations.
Goodluck!!!