0% found this document useful (0 votes)
9 views4 pages

Java ch1 6 QA

The document provides a comprehensive overview of Java programming concepts, covering the Java Virtual Machine, data types, control structures, loops, methods, and object-oriented principles. It includes definitions and distinctions between key terms such as bytecode, identifiers, and various types of methods and variables. Each chapter presents questions and answers that clarify fundamental Java concepts for learners.

Uploaded by

aaron banda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Java ch1 6 QA

The document provides a comprehensive overview of Java programming concepts, covering the Java Virtual Machine, data types, control structures, loops, methods, and object-oriented principles. It includes definitions and distinctions between key terms such as bytecode, identifiers, and various types of methods and variables. Each chapter presents questions and answers that clarify fundamental Java concepts for learners.

Uploaded by

aaron banda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter 1

1. What is the Java Virtual Machine (JVM)?


Answer: It is a software component that executes Java bytecode, making Java programs
platform-independent.

2. What file extension do Java source code files use?


Answer: .java

3. What is bytecode?
Answer: The intermediate code generated after compiling Java source code, executed by the JVM.

4. What is an identifier in Java?


Answer: A name given to classes, methods, variables, and other elements defined by the
programmer.

5. What is the purpose of the main method?


Answer: It serves as the entry point for Java applications: public static void main(String[] args).

6. What does println do?


Answer: It prints output to the console and moves the cursor to the next line.

7. What is the difference between a compiler and an interpreter?


Answer: A compiler translates source code into bytecode once, while an interpreter executes
instructions line by line.

Chapter 2
1. What are Java's primitive data types?
Answer: byte, short, int, long, float, double, char, boolean.

2. What is the difference between = and == in Java?


Answer: = assigns a value to a variable, while == compares two values.

3. What happens if you try to divide an integer by zero in Java?


Answer: It throws an ArithmeticException at runtime.

4. What is type casting?


Answer: The process of converting one data type into another.

5. What is string concatenation?


Answer: Joining two or more strings using the + operator.

6. What is the purpose of escape sequences like \n?


Answer: They represent special characters such as newline or tab.

7. What is the difference between pre-increment (++i) and


post-increment (i++)?
Answer: Pre-increment increases the value before use, while post-increment increases it after use.

Chapter 3
1. What is a decision structure?
Answer: A structure that allows a program to make choices and branch accordingly.

2. What is the syntax of an if statement?


Answer: if (condition) { // statements }

3. What is the difference between if-else and if-else-if?


Answer: if-else checks one condition, if-else-if can check multiple conditions sequentially.

4. When is a switch statement preferable over if-else?


Answer: When a single variable is compared against multiple constant values.

5. What is a block of code?


Answer: One or more statements grouped within braces { }.

6. What operator is used for logical AND?


Answer: &&

7. What is short-circuit evaluation?


Answer: When using && or ||, Java may skip evaluating the second condition if the result is already
known.

Chapter 4
1. What is a loop?
Answer: A structure that allows code to repeat until a condition is met.

2. What is the difference between while and do-while loops?


Answer: while checks the condition before execution; do-while executes once before checking.

3. What is a for loop best used for?


Answer: When the number of iterations is known in advance.

4. How can you exit a loop early?


Answer: By using the break statement.

5. How do you skip an iteration in a loop?


Answer: By using the continue statement.

6. What is the purpose of a sentinel value?


Answer: A special value that signals the end of input.

7. How can Java read data from a file?


Answer: By using classes such as Scanner or FileReader.

Chapter 5
1. What is a method?
Answer: A block of code that performs a task and can be reused.

2. What is the difference between a void method and a


value-returning method?
Answer: A void method performs an action without returning a value; a value-returning method
sends back a result.

3. What are method parameters?


Answer: Variables listed inside the method declaration used to pass information.

4. What is method overloading?


Answer: Having multiple methods with the same name but different parameter lists.

5. What does the return statement do?


Answer: It ends the method and optionally sends back a value.
6. What is the difference between local and global variables?
Answer: Local variables are declared inside methods; global variables (class-level) are declared in
a class but outside methods.

7. What is pass by value in Java?


Answer: When arguments are passed to methods, Java passes a copy of the value, not the actual
variable.

Chapter 6
1. What is a class?
Answer: A blueprint for creating objects in Java.

2. What is an object?
Answer: An instance of a class that has state (fields) and behavior (methods).

3. What is a constructor?
Answer: A special method used to initialize objects.

4. What is the purpose of the this keyword?


Answer: It refers to the current object of the class.

5. What is encapsulation?
Answer: The practice of hiding data using private fields and providing access via public methods.

6. What is the difference between a class and an object?


Answer: A class is a template; an object is a specific instance of that template.

7. What is the difference between instance fields and static fields?


Answer: Instance fields belong to objects; static fields belong to the class and are shared among all
objects.

You might also like