0% found this document useful (0 votes)
11 views7 pages

Possible Question Answers For Computer

The document provides a comprehensive overview of Java programming concepts, including variables, data types, classes, objects, constructors, methods, encapsulation, arrays, string handling, input/output, logical operators, and conditional constructs. It includes definitions, examples, and explanations of key terms and functionalities in Java. Additionally, it covers the use of library classes and the importance of encapsulation and wrapper classes.

Uploaded by

contactrudranil
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)
11 views7 pages

Possible Question Answers For Computer

The document provides a comprehensive overview of Java programming concepts, including variables, data types, classes, objects, constructors, methods, encapsulation, arrays, string handling, input/output, logical operators, and conditional constructs. It includes definitions, examples, and explanations of key terms and functionalities in Java. Additionally, it covers the use of library classes and the importance of encapsulation and wrapper classes.

Uploaded by

contactrudranil
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
You are on page 1/ 7

🟩 1.

Revision of Class IX Syllabus

Q1: What is a variable?


A: A variable is a container used to store data values.

Q2: Name the basic data types in Java.


A: int, float, double, char, boolean.

Q3: What is the use of an if statement?


A: It executes a block of code if a specified condition is true.

🟩 2. Class as a Basis of all Computation

Q4: What is a class?


A: A blueprint from which objects are created.

Q5: What is an object?


A: An instance of a class that contains data and behavior.

Q6: What does the new keyword do?


A: It allocates memory dynamically for objects.

🟩 3. Constructors

Q7: What is a constructor?


A: A special method used to initialize objects.

Q8: What are the types of constructors?


A: Default and Parameterized constructors.

Q9: What is constructor overloading?


A: Defining multiple constructors with different parameter lists.

🟩 4. Functions / Methods

Q10: What is a method?


A: A block of code that performs a specific task.

Q11: What are the advantages of using methods?


A: Code reusability, modularity, and easier debugging.

Q12: What is method overloading?


A: Creating multiple methods with the same name but different parameters.

Q13: What are some common Math class methods?


A: sqrt(), pow(), abs(), ceil(), floor(), random().
🟩 5. Using Library Classes

Q14: What is the purpose of the import statement?


A: To include library classes from packages.

Q15: Name two commonly used packages in Java.


A: java.util, java.lang.

Q16: What is the use of the Math class?


A: To perform mathematical operations.

🟩 6. Encapsulation

Q17: What is encapsulation?


A: Wrapping data and code together in a single unit (class).

Q18: Why use the private keyword?


A: To restrict access and protect data.

Q19: What are getters and setters?


A: Methods used to access and modify private variables.

🟩 7. Arrays

Q20: What is an array?


A: A collection of elements of the same type stored in a single variable.

Q21: How are arrays declared in Java?


A: int[] arr = new int[5];

Q22: What are two common sorting algorithms?


A: Bubble Sort and Selection Sort.

🟩 8. String Handling

Q23: What is the difference between String and StringBuffer?


A: String is immutable; StringBuffer is mutable.
Q24: What does charAt() do?
A: Returns the character at a specified index.

Q25: What does substring() do?


A: Extracts part of a string from a specified start index.
Q26: What does equals() do?
A: Compares the content of two strings.

🟩 9. Basic Input/Output

Q27: How do you take input in Java?


A: Using the Scanner class.

Q28: How do you print output?


A: Using System.out.print() or System.out.println().

🟩 10. Logical Operators

Q29: What are the logical operators in Java?


A: && (AND), || (OR), ! (NOT).

Q30: Where are logical operators used?


A: In conditional statements and loops.

🟩 11. Conditional Constructs and Looping

Q31: Name all conditional statements.


A: if, if-else, else-if, switch.

Q32: Name the loop types.


A: for, while, do-while.

Q33: What does break do?


A: Exits a loop or switch.

Q34: What does continue do?


A: Skips the current iteration of a loop.

🟩 12. Simple Library Classes

Q35: Name two wrapper classes.


A: Integer, Double.
Q36: Why are wrapper classes used?
A: To convert primitive data types into objects.

Q37: Give an example of autoboxing.


A: Integer obj = 5; // int to Integer
🟩 Flashcards (Extended Set)

1. Q: Define a variable in Java.


A: A variable is a named memory location used to store data of a specific type.

2. Q: List Java primitive data types.


A: byte, short, int, long, float, double, char, boolean.

3. Q: What is a data type?


A: A data type defines the type of data a variable can hold.
4. Q: Differentiate between ‘=’ and ‘==’ operators.
A: ‘=’ is an assignment operator, ‘==’ is a comparison operator.

5. Q: What are the types of operators in Java?


A: Arithmetic, relational, logical, assignment, unary, and conditional operators.

6. Q: What is object-oriented programming?


A: A programming paradigm based on the concept of objects containing data and
behavior.
7. Q: Explain the concept of 'object' in Java.
A: An object is an instance of a class that has state and behavior.

8. Q: How is an object created in Java?


A: Using the new keyword with a class constructor.

9. Q: What is the role of a class in Java?


A: A class serves as a blueprint to create objects.

10. Q: What is a constructor?


A: A special method used to initialize objects.

11. Q: What is a default constructor?


A: A constructor with no parameters, provided by Java if not defined.

12. Q: Can constructors be overloaded?


A: Yes, by defining multiple constructors with different parameter lists.

13. Q: What is a function prototype?


A: The declaration of a method showing its return type and parameters.

14. Q: What are return types in Java?


A: Types of values a method can return, e.g., int, String, void.

15. Q: What is the difference between formal and actual parameters?


A: Formal parameters are in the method definition; actual parameters are in the call.

16. Q: Explain pass by value.


A: Java passes arguments by value, meaning copies of values are passed to
methods.

17. Q: What is java.lang package?


A: A default package in Java that includes essential classes like String and Math.
18. Q: What does Math.random() return?
A: A double value between 0.0 (inclusive) and 1.0 (exclusive).

19. Q: What is the wrapper class for int?


A: Integer.

20. Q: Why are wrapper classes necessary?


A: To use primitive types as objects in collections or generics.

21. Q: How does Java achieve encapsulation?


A: By using private variables with public getters and setters.

22. Q: Give an example of encapsulation.


A: A class with private fields and public methods to access/modify them.

23. Q: How do you declare a 1D array?


A: int[] arr = new int[5];

24. Q: What is array traversal?


A: Accessing each element of the array one by one using loops.

25. Q: How to search for an element in an array?


A: Using a loop to compare each element with the target value.

26. Q: What is bubble sort?


A: A sorting algorithm that repeatedly swaps adjacent elements if out of order.

27. Q: Difference between equals() and == for Strings?


A: equals() compares content; == compares memory references.

28. Q: How to convert String to uppercase?


A: Using toUpperCase() method.

29. Q: What is String immutability?


A: A String's value cannot be changed once created.

30. Q: How to append to a StringBuffer?


A: Using append() method.

31. Q: How to create a Scanner object?


A: Scanner sc = new Scanner(System.in);

32. Q: Which package is needed for Scanner?


A: java.util.
33. Q: What is short-circuiting in logical operators?
A: Java skips evaluation of second condition if the first is sufficient.

34. Q: What is a switch-case used for?


A: Selecting one of many code blocks to execute based on a variable.

35. Q: Syntax of a for loop?


A: for(init; condition; update) { ... }
36. Q: When is a do-while loop used?
A: When the loop must run at least once.

37. Q: Difference between while and do-while?


A: while checks before execution; do-while checks after.

38. Q: How to convert int to Integer?


A: Integer obj = Integer.valueOf(num);

39. Q: How to convert Integer to int?


A: int num = obj.intValue();

40. Q: What does parseInt() do?


A: Converts a String to an int.

You might also like