Programming in Java - NPTEL Assignment 1 PDF
Document Details

Uploaded by EducatedCongas2131
Indian Institute of Technology, Kharagpur
2025
Tags
Summary
NPTEL Online Certification Courses document from the Indian Institute of Technology Kharagpur. It contains multiple-choice questions (MCQ) related to Java programming, specifically assignment 1 for the NOC25-CS57 course. The questions cover topics such as Java interpreters, compilers, bytecode, object-oriented programming, and the Java Virtual Machine.
Full Transcript
NPTEL Online Certification Courses Indian Institute of Technology Kharagpur NOC25-CS57 (JAN-2025 25S) PROGRAMMING IN JAVA Assignment 01...
NPTEL Online Certification Courses Indian Institute of Technology Kharagpur NOC25-CS57 (JAN-2025 25S) PROGRAMMING IN JAVA Assignment 01 TYPE OF QUESTION: MCQ Number of questions: 10 Total marks: 10 × 1 = 10 QUESTION 1: Which of the following is true? a. Java uses only interpreter. b. Java uses only compiler. c. Java uses both interpreter and compiler. d. None of the above. Correct Answer: c. Java uses both interpreter and compiler. Detailed Solution: Creating a.class file from.java using javac command is a compilation task, whereas execution of a.class file using java is the process of interpretation. NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 2: A Java file with extension ‘.class’ contains a. Java source code b. HTML tags c. Java Byte code d. A program file written in Java programming language Correct Answer: c. Java Byte code Detailed Solution: A.class file is a complied version of the.java file in byte code (it is a kind of object code with JVM (Java Virtual Machine) as the target machine. NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 3: Which of the following is not an object-oriented programming paradigm? a. Encapsulation b. Inheritance c. Polymorphism d. Dynamic memory allocation Correct Answer: d. Dynamic memory allocation Detailed Solution: Dynamic memory allocation is a memory allocation strategy and not a programming paradigm. NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 4: Java is a platform independent programming language because a. It compiles an intermediate code targeting a virtual machine, which can be interpreted by an interpreter for a given OS. b. The Java compiler translates the source code directly into the machine-level language. c. It follows the concept of “write once and compile everywhere”. d. It is written almost similar to the English language. Correct Answer: a. It compiles to an intermediate code targeting a virtual machine, which can be interpreted by an interpreter for a given OS. Detailed Solution: The compiled code (byte code) can be executed (interpreted) on any platform running a JVM. NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 5: Which of the following is not a Language Processor? a. Assembler b. Compiler c. Interpreter d. Fortran Correct Answer: d. Fortran Detailed Solution: A computer understands instructions in machine code i.e., in the form of 0s and 1s. Special translators are required for this operation like Assembler, Compiler and Interpreter. Fortran is a programming language but not a language processor. NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 6: A platform is the hardware or software environment in which a program runs. Which of the following is/are Java platform component(s)? a. HTML b. Java Virtual Machine c. Javascript d. HotJava Correct Answer: b. Java Virtual Machine Detailed Solution: "A platform is the hardware or software environment in which a program runs. Some of the most popular platforms are Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can be described as a combination of the operating system and underlying hardware. The Java platform differs from other platforms as it is a software-only platform that runs on top of other hardware-based platforms. The Java platform has two components: The Java Virtual Machine The Java Application Programming Interface (API) NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 7: What is the correct sequence of steps to execute a Java program? I. Compile the Program: Use the javac command to compile the code into bytecode. II. Edit the Program: Write the code in a text editor or IDE. III. Run the Program: Use the java command to execute the bytecode. Which of the following options represents this sequence? a. Run → Edit → Compile b. Edit → Run → Compile c. Compile → Edit → Run d. Edit → Compile → Run Correct Answer: d. Edit → Compile → Run Detailed Solution: The Java development process involves writing code (Edit), converting it to bytecode (Compile), and then executing it on the JVM (Run). NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 8: What is the primary difference between javac and java commands? a. javac is used to edit Java code, while java runs Java programs. b. javac compiles Java source code to bytecode, while java executes the bytecode on the JVM. c. javac executes Java programs, while java is used for compilation. d. Both are used for compiling Java programs. Correct Answer: b. javac compiles Java source code to bytecode, while java executes the bytecode on the JVM. Detailed Solution: The javac command converts.java source files into.class bytecode files. The java command executes the.class file using the Java Virtual Machine (JVM). NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 9: Which of the following is not a feature of Java? a. Platform Independence b. Object-Oriented Programming c. Supports Explicit Pointers d. Supports Polymorphism Correct Answer: c. Supports Explicit Pointers Detailed Solution: Java is platform-independent, object-oriented, and secure. It does not support explicit pointers, as they can lead to memory management issues and compromise security. NPTEL Online Certification Courses Indian Institute of Technology Kharagpur QUESTION 10: What is the output of the following code? class NPTEL { public static void main(String[] args) { System.out.println("Hello, World!"); } } a. Hello, World! b. HelloWorld! c. Compilation Error d. Runtime Error Correct Answer: a. Hello, World! Detailed Solution: Java program to print Hello, World!