Sei sulla pagina 1di 3

Answer Sheet Template

Part – A (Two exercises)

Ans. 1: Java code for programs A and B. [ 2 x 8.75 marks]


Class HelloWorld {
publics
Show 2 Screenshots of output/result of program A and program B in any IDE (Eclipse or NetBeans) or
in Command prompt. [ 2 x 8.75 marks]

Ans. 2: Java code for programs A, B and C. [ 3 x 5.83 marks]

2(A) Input:

Output:
2(B) Input:-

Output:-

2(c) Input

Output:
Part – B (Five questions)

1. Compiling a Java program is very easy after JDK installation. Following are the steps −

 Open a command prompt window and go to the directory where you saved the java
program. Assume it's C:\.
 Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. If there are no
errors in your code, the command prompt will take you to the next line (Assumption: The
path variable is set).

The file is compiled and you can see MyFirstJavaProgram.class file generated in the same folder.

2. JVM or Java Virtual Machine is a specification to provide the runtime environment on which a
bytecode can be executed. JVMs are prepared platform specific and are available for almost all the
hardware and machine.
Features of JVM −
 It provides class loader to load a class.
 It provides bytecode verifier to verify the legality of the bytecode.
 It provides runtime.
 It executes the bytecode.
3. Bytecode is computer object code that is processed by a program, usually referred to as a virtual
machine, rather than by the "real" computer machine, the hardware processor. The virtual machine
converts each generalized machine instruction into a specific machine instruction or instructions that
this computer's processor will understand. Bytecode is the result of compiling source code written in
a language that supports this approach.

4. A class which contains the abstract keyword in its declaration is known as abstract class.
 Abstract classes may or may not contain abstract methods, i.e., methods without body
( public void get();
 But, if a class has at least one abstract method, then the class must be declared abstract.
 If a class is declared abstract, it cannot be instantiated.
 To use an abstract class, you have to inherit it from another class, provide implementations
to the abstract methods in it.
 If you inherit an abstract class, you have to provide implementations to all the abstract
methods in it.
5.

Potrebbero piacerti anche