0% found this document useful (0 votes)
3 views3 pages

Assignment 2

The document outlines a comprehensive assignment focused on Java programming concepts, including operators, control structures, loops, classes, objects, and constructors. It includes theoretical questions and practical programming tasks to demonstrate understanding and application of these concepts. The assignment covers a wide range of topics, ensuring a thorough grasp of Java programming fundamentals.

Uploaded by

gamerhacker284
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)
3 views3 pages

Assignment 2

The document outlines a comprehensive assignment focused on Java programming concepts, including operators, control structures, loops, classes, objects, and constructors. It includes theoretical questions and practical programming tasks to demonstrate understanding and application of these concepts. The assignment covers a wide range of topics, ensuring a thorough grasp of Java programming fundamentals.

Uploaded by

gamerhacker284
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/ 3

Assignment-2

1. What are operators in Java? Why are they important in programming?


2. List and briefly describe the different types of operators available in Java.
3. How does operator precedence affect the evaluation of expressions in Java?
4. What are arithmetic operators in Java? List them with their functions.
5. Explain integer division and floating-point division with an example in Java.
6. Write a Java program to perform basic arithmetic operations (addition, subtraction,
multiplication, division, and modulus).
7. What are bitwise operators in Java? List and explain them.
8. Explain the difference between bitwise AND (&) and logical AND (&&) in Java.
9. Write a Java program to demonstrate bitwise AND, OR, XOR, left shift, and right
shift operations.
10. What are relational operators in Java? How are they used in decision-making?
11. Write a Java program to compare two numbers using relational operators and display
the results.
12. How do relational operators behave when comparing strings in Java?
13. What are logical operators in Java? How are they different from bitwise operators?
14. Explain the concept of short-circuit evaluation in logical operators with an example.
15. Write a Java program to demonstrate the use of logical AND, OR, and NOT
operators.
16. What are assignment operators in Java? Provide examples of compound assignment
operators.
17. Write a Java program to demonstrate different assignment operators (=, +=, -=, *=, /=,
%=).
18. Explain the difference between = and == in Java with an example.
19. What is the ternary (?:) operator in Java? How does it work?
20. Compare the ternary operator with the if-else statement. Which one is more
efficient?
21. Write a Java program to find the largest of two numbers using the ternary operator.
22. What are increment (++) and decrement (--) operators in Java?
23. Differentiate between pre-increment (++i) and post-increment (i++) with examples.
24. Write a Java program to demonstrate the working of increment and decrement
operators.
25. Write a Java program to calculate the square root, power, absolute value, and generate
a random number using Math class methods.
26. What are decision and control structures in Java? Why are they important in
programming?
27. Differentiate between decision-making statements and looping statements in Java.
28. What is the difference between if and if-else statements? Provide an example.
29. What is a nested if statement? How does it work? Explain with an example.
30. Compare if-else and switch statements. When should we use switch over if-
else?
31. Explain the working of the switch statement with an example.
32. Write a Java program to check whether a given number is positive, negative, or zero
using an if-else statement.
33. Write a Java program to determine the grade of a student based on marks using a
switch statement.
34. What are loops in Java? Why are they useful?
35. Explain the syntax and working of the while loop with an example.
36. How does a do-while loop differ from a while loop? Provide an example.
37. Explain the for loop in Java. How does it differ from the while loop?
38. Write a Java program to print the first 10 natural numbers using a for loop.
39. Write a Java program to find the factorial of a number using a while loop.
40. Write a Java program that demonstrates the use of a do-while loop to validate user
input.
41. What is the purpose of the break statement in Java? Explain with an example.
42. How does the continue statement work in Java? Provide a program to demonstrate
its use.
43. Compare break and continue statements in Java. When should each be used?
44. Explain the return statement in Java. How does it work in methods?
45. Write a Java program that demonstrates the use of break inside a loop.
46. Write a Java program to skip printing even numbers using the continue statement.
47. Explain how return is used to exit from a method and return a value. Provide an
example.
48. Write a Java program to demonstrate break, continue, and return in different
scenarios.
49. What are classes and objects in Java? How are they related?
50. How do you define a class in Java? What are its components?
51. What are fields (instance variables) and methods in Java? How do they interact within
a class?
52. Explain the difference between instance variables and local variables with an
example.
53. What are access modifiers in Java? How do they control access to class members?
54. Explain the difference between private, protected, public, and default access
modifiers.
55. Write a Java program to define a class with fields and methods and create an object to
access them.
56. How is an object created in Java? Explain with an example.
57. What is the new keyword in Java? How does it help in object creation?
58. Explain how objects are stored in memory when created in Java.
59. What are the different ways to create an object in Java?
60. Write a Java program to create multiple objects of a class and access their properties.
61. What is the purpose of the this keyword in Java?
62. How does this help in resolving variable name conflicts? Provide an example.
63. Explain how this can be used to call another constructor within the same class.
64. Write a Java program demonstrating the use of this keyword in different scenarios.
65. What is the static keyword in Java? Where can it be used?
66. How does a static method differ from a non-static method?
67. Explain the difference between static and instance variables with an example.
68. Write a Java program to demonstrate the use of static variables and methods.
69. What is method overloading in Java? How is it useful?
70. Explain the rules of method overloading in Java.
71. Can method overloading be done by changing the return type alone? Why or why not?
72. How does Java determine which overloaded method to call?
73. Write a Java program demonstrating method overloading with different parameter
lists.
74. What is a constructor in Java? How does it differ from a method?
75. What are the characteristics of constructors in Java?
76. Explain the purpose of a default constructor. When is it provided automatically?
77. What is a parameterized constructor? How is it different from a default constructor?
78. Write a Java program to define a class with a default constructor and a parameterized
constructor.
79. What is a copy constructor in Java? Does Java provide a default copy constructor?
80. How can we create a copy of an object using a constructor? Provide an example.
81. What are the advantages and disadvantages of using a copy constructor in Java?
82. Write a Java program demonstrating the concept of a copy constructor.
83. How can objects be passed as parameters to methods? Provide an example.
84. Write a Java program where an object is passed to a method and its values are
modified.
85. What is constructor overloading? How is it different from method overloading?
86. How does Java determine which constructor to invoke when multiple constructors
exist?
87. Explain the role of this () in constructor overloading.
88. Write a Java program demonstrating constructor overloading with multiple
constructors.

You might also like