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

CBSE_Class12_IT_Java_PYQs

The document outlines frequently asked questions (PYQs) related to Java programming for CBSE Class 12 Information Technology. It covers basic concepts, control statements, loops, arrays, functions, object-oriented programming, and exception handling, providing definitions, syntax, and example code snippets. Each section includes specific questions and answers to aid in understanding Java programming principles.
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)
2 views3 pages

CBSE_Class12_IT_Java_PYQs

The document outlines frequently asked questions (PYQs) related to Java programming for CBSE Class 12 Information Technology. It covers basic concepts, control statements, loops, arrays, functions, object-oriented programming, and exception handling, providing definitions, syntax, and example code snippets. Each section includes specific questions and answers to aid in understanding Java programming principles.
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

CBSE Class 12 - Information Technology (Code 802)

Most Frequently Asked Java Programming PYQs

1. Basic Java Concepts

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

A compiler translates the whole program at once, while an interpreter translates it line-by-line.

Q2. Define a variable and mention its syntax in Java.

A variable stores data. Syntax: dataType variableName = value;

Q3. What are the data types in Java? Give examples.

Examples: int (10), float (10.5f), char ('A'), boolean (true/false), String ("Hello").

2. Control Statements

Q4. Write a Java program to find the largest of three numbers using if-else.

if(a > b && a > c) { largest = a; } else if(b > c) { largest = b; } else { largest = c; }

Q5. Write a Java program to check whether a number is even or odd using if-else.

if(num % 2 == 0) System.out.println("Even"); else System.out.println("Odd");

Q6. What is the difference between if-else and switch statement?

if-else is used for conditions; switch is used for selecting from multiple options.

3. Loops in Java

Q7. Write a Java program to print numbers from 1 to 10 using a while loop.

int i=1; while(i<=10) { System.out.println(i); i++; }


CBSE Class 12 - Information Technology (Code 802)

Most Frequently Asked Java Programming PYQs

Q8. Write a program to print the multiplication table of a number using a for loop.

for(int i=1; i<=10; i++) { System.out.println(num + " x " + i + " = " + (num*i)); }

Q9. Explain the use of break and continue with examples.

"break" exits the loop; "continue" skips the current iteration.

4. Arrays

Q10. Declare and initialize an array in Java.

int[] arr = {1, 2, 3, 4, 5};

Q11. Write a program to find the sum of elements in an integer array.

int sum = 0; for(int num : arr) sum += num;

Q12. How can you sort an array in Java?

Use Arrays.sort(arr); from java.util package.

5. Functions/Methods

Q13. Write a function in Java to calculate the factorial of a number.

int factorial(int n) { int fact = 1; for(int i=1; i<=n; i++) fact *= i; return fact; }

Q14. What is method overloading? Give an example.

Two or more methods with the same name but different parameters.
CBSE Class 12 - Information Technology (Code 802)

Most Frequently Asked Java Programming PYQs

Q15. Explain the difference between call by value and call by reference.

Java uses call by value, meaning copies of variables are passed.

6. Object-Oriented Programming

Q16. What is a class and object in Java? Explain with an example.

A class is a blueprint; an object is an instance. Example: Student s = new Student();

Q17. Define constructor. How is it different from a method?

Constructor initializes an object. No return type and same name as class.

Q18. Write a Java class to represent a Student.

class Student { int rollNo; String name; void display() { System.out.println(rollNo + " " + name); } }

7. Exception Handling

Q19. What is exception handling in Java?

It is the process of handling runtime errors using try-catch blocks.

Q20. Write a simple try-catch block to handle divide-by-zero exception.

try { int x = a / b; } catch(ArithmeticException e) { System.out.println("Cannot divide by zero"); }

You might also like