0% found this document useful (0 votes)
19 views14 pages

Exam CoreJAVA

Uploaded by

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

Exam CoreJAVA

Uploaded by

andra soldier
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Exam–CoreJAVA –PART1

1. What is Core Java?


A. A programming language
B. A software development framework
C. A subset of the Java Standard Edition
D. A version of Java for mobile devices

2. Which of the following statements about Java is true?


A. Java is a purely functional programming language.
B. Java is an interpreted language.
C. Java is platform-independent.
D. Java programs are compiled to machine code.

3 .What is the main goal of Core Java?


A. Web development
B. Mobile app development
C. General-purpose application development
D. Data analysis

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


A. A hardware component in a computer
B. A virtual computer that runs Java bytecode
C. A tool for writing Java code
D. A web server for Java applications

5. Which of the following is not a feature of Java?


A. Platform independence
B. Automatic memory management
C. Pointers for direct memory access
D. Object-oriented programming

6. What is the significance of the "Write Once, Run Anywhere" slogan in Java?
A. Java programs can be written in any language.
B. Java code can be executed on any operating system.
C. Java code can only be written once.
D. Java is a write-only language.

7. Which part of Java ensures platform independence?


A. Java Compiler
B. Java Virtual Machine (JVM)
C. Java Development Kit (JDK)
D. Java API
8. What is the correct order of the Java development process?
A. Compile, Debug, Run
B. Debug, Compile, Run
C. Run, Debug, Compile
D. Compile, Run, Debug

9 .In Java, which keyword is used to define a class?


A. method
B. class
C. object
D. interface

10. Which of the following is not a primitive data type in Java?


A. int
B. float
C. string
D. char

11.What is the purpose of the "public static void main(String[] args)" method in Java?
A. Entry point of a Java program
B. A utility method for printing text
C. A method for creating objects
D. A method for mathematical calculations
D. private

12.What is the purpose of the "new" keyword in Java?


A. Creating an instance of a class
B. Deleting objects
C. Printing to the console
D. Declaring variables

13 .Which of the following statements is true about Java's exception handling?


A. All exceptions must be caught and handled.
B. Exceptions should never be caught.
C. Checked exceptions are optional.
D. Unchecked exceptions must be caught and handled.

14.In Java, what is the "final" keyword used for?


A. To indicate a class cannot be extended.
B. To specify a class cannot have any methods.
C. To make a variable invisible in other classes.
D. To indicate a method cannot be called.

15.Which of the following is true about a final method in Java?


A. It cannot be overridden in subclasses.
B. It can only be called once.
C. It can be overridden by subclasses.
D. It is automatically called by the JVM.

16.Can a final variable be reassigned once it has been assigned a value?


A. Yes
B. No
C. Only within the same class
D. Only within the same package

17.In the context of inheritance, which access modifier is often used with a final class?
A. public
B. private
C. protected
D. default

18 What is the purpose of using the "final" keyword with a variable in Java?
A. To indicate the variable's data type.
B. To prevent the variable from being modified after initialization.
C. To allow the variable to be accessed without restrictions.
D. To indicate the variable's value.

Certainly! Here are some multiple-choice questions (MCQs) on operators in Java:

19 What is the result of the expression "5 + 3" in Java?


A. 8
B. 53
C. 35
D. Error

20 .Which operator is used for exponentiation in Java?


A. **
B. ^
C. ^^
D. ^^^
21.What does the "==" operator check in Java?
A. Identity
B. Equality
C. Assignment
D. Comparison

22 .What is the result of the expression "10 / 3" in Java?


A. 3.333
B. 3
C. 3.0
D. 4

23.What is the purpose of the "++" operator in Java?


A. Decrement a variable by 1
B. Add 1 to a variable
C. Multiply a variable by 2
D. Assign a value to a variable

24.What is the logical AND operator in Java?


A. &&
B. ||
C. !
D. &

25 .Which operator is used to compare two values and return the maximum of the two
in Java?
A. >
B. >=
C. <
D. <=

26.What is the result of the expression "true && false" in Java?


A. true
B. false
C. Error
D. 0

27 Which operator is used to shift bits to the left in Java?


A. >>
B. <<<
C. <<=
D. <<

28.What does the "%" operator do in Java?


A. Finds the square root of a number
B. Returns the remainder of a division operation
C. Checks for equality
D. Calculates the average of two numbers

29 .Which operator is used to concatenate strings in Java?


A. +
B. -
C. *
D. /

30.What is the result of the expression "5 | 3" in Java?


A. 7
B. 2
C. 8
D. Error

31.What does the "!=" operator check in Java?


A. Identity
B. Equality
C. Assignment
D. Inequality

32.What is the purpose of the "+= " operator in Java?


A. Subtract a value from a variable
B. Multiply a variable by a value
C. Add a value to a variable
D. Assign a value to a variable

33.Which operator is used to compare two values for equality without considering their
data types?
A. ==
B. ===
C. .equals()
D. !=
34.What is type casting in programming?

A. Transforming one data type into another


B. Converting a decimal number to a binary number
C. A way to manipulate text data
D. A method to format output on the console

35.In Java, what is the purpose of explicit type casting (e.g., (int) someDouble)?

A. It changes the value of the variable.


B. It converts a variable of one data type to another.
C. It initializes a variable with a value.
D. It prints the variable's value to the console.

36.Which of the following casting operations may result in data loss?

A. Implicit casting (widening)


B. Explicit casting (narrowing)
C. Both A and B
D. Neither A nor B

37.What is the result of casting a floating-point number to an integer in most


programming languages?

A. The integer part of the floating-point number is retained.


B. The fractional part of the floating-point number is retained.
C. An error is generated.
D. The program crashes.

38.In Java, what happens if you try to cast an object of one class to another class if they
are not related by inheritance?

A. The casting operation is allowed, and it creates a new object.


B. It results in a compilation error.
C. It produces a runtime error.
D. The casting operation is automatically handled by the JVM.
39.What is the purpose of type casting in C when dealing with pointers?

A. To convert a pointer to an integer value


B. To change the address stored in a pointer
C. To transform a string into a character
D. To convert a constant to a variable

40 .In C#, which casting method is used to cast from a base class to a derived class?

A. Explicit casting
B. Implicit casting
C. is/as casting
D. Safe casting

41.Which of the following programming languages supports both implicit and explicit
type casting?

A. Python
B. Java
C. C++
D. JavaScript

42.What is the primary reason for using type casting in programming?

A. To confuse programmers
B. To save memory
C. To improve code readability
D. To enable flexibility when working with different data types

43 .Write a Java program to compare two numbers using relational operators.


Determine and print whether the first number is greater than, less than, or equal to the
second number.

Code :

import java.util.Scanner;

class CompareTwoNumbers {
public static void main(String[] args) {
int num1;
int num2;
Scanner s=new Scanner(System.in);
System.out.println("Enter number 1:");
num1=s.nextInt();
System.out.println("Enter number 2:");
num2=s.nextInt();
if(num1==num2)
{
System.out.println(num1 +" and "+ num2 +"are equal");
}
if(num1<num2)
{
System.out.println(num1 +" is lessthan "+ num2);
}
if(num1>num2)
{
System.out.println(num1+" is Greaterthan "+num2);
}
}
}

Output :
44.Write a Java program that takes two boolean values as input. Implement logical AND,
OR, and NOT operations on these values and display the results.

Code:

import java.util.Scanner;

class LogicalOperators {
public static void main(String[] args) {
Boolean x;
Boolean y;
Scanner s=new Scanner(System.in);
System.out.println("Enter x value (true/false):");
x=s.nextBoolean();
System.out.println("Enter y value (true/false):");
y=s.nextBoolean();
Boolean result_AND=x&&y;
System.out.println("Logical AND result is:\n"+result_AND);
Boolean result_OR=x||y;
System.out.println("Logical OR result is:\n"+result_OR);
Boolean result_NOT=!x;
System.out.println("Logical NOT result is:\n"+result_NOT);
}
}

Output:
45 .Write a Java program that demonstrates the use of the increment (++) and
decrement (--) operators. Use these operators to increase and decrease a variable's
value and display the results.

Code:

import java.util.Scanner;

class IncrementAndDecrement {
public static void main(String[] args) {
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x value:");
x=s.nextInt();
int PostInc=x++;
System.out.println("X value After Post Increment: "+PostInc);
int PreInc=++x;
System.out.println("X value After Pre Increment: "+PreInc);
int PostDec=x--;
System.out.println("X value After Post Decrement: "+PostDec);
int PreDec=--x;
System.out.println("X value After Pre Decrement: "+PreDec);

}
}

Output:
46.Write a Java program that takes two numbers as input and uses the conditional
operator to find and display the maximum of the two numbers.

Code:

import java.util.Scanner;

class MaximumOfTwoNumbers {
public static void main(String[] args) {
int num1;
int num2;
Scanner s=new Scanner(System.in);
System.out.println("Enter number 1:");
num1=s.nextInt();
System.out.println("Enter number 2:");
num2=s.nextInt();
int max=(num1>num2)?num1:num2;
System.out.println("The Maximum number is:\n"+max);
}
}

Output:
47.Write a Java program that demonstrates the use of bitwise AND, OR, XOR, left shift,
and right shift operators on integer values. Display the results of each operation.

Code:

import java.util.Scanner;
class BitwiseOperators {
public static void main(String[] args) {
int x;
int y;
Scanner s=new Scanner(System.in);
System.out.println("Enter x value:");
x=s.nextInt();
System.out.println("Enter y value:");
y=s.nextInt();
int result_AND=x&y;
System.out.println("Bitwise AND result is:\n"+result_AND);
int result_OR=x|y;
System.out.println("Bitwise OR result is:\n"+result_OR);
int result_XOR=x^y;
System.out.println("Bitwise XOR result is:\n"+result_XOR);
int Left_Shift=x<<2;
System.out.println("Bitwise Left Shift result is:\n"+Left_Shift);
int Right_Shift=x>>2;
System.out.println("Bitwise Right Shift result is:\n"+Right_Shift);
}
}

Output:
48.Write a Java program that uses various assignment operators, such as +=, -=, *=, /=,
and %=, to modify the values of variables and display the results.

Code:

import java.util.Scanner;

class AssignmentOperator {
public static void main(String[] args) {
int x;
Scanner s=new Scanner(System.in);
System.out.println("Enter x value:");
x=s.nextInt();
x+=10;
System.out.println("after using +=,the x value is: "+x);
x-=20;
System.out.println("after using -=,the x value is: "+x);
x*=19;
System.out.println("after using *=,the x value is: "+x);
x/=10;
System.out.println("after using /=,the x value is: "+x);
x%=3;
System.out.println("after using %=,the x value is: "+x);

}
}

Output:
49.Write a Java program that demonstrates the order of precedence of operators in a
complex expression. Create an expression that involves arithmetic, relational, and
logical operators, and display the result.

Code:

public class OperatorPrecedence {


public static void main(String[] args) {
int a = 10;
int b = 5;
int c = 15;
boolean d = true;
boolean result = (a + b < c) && (b != c) || d;
System.out.println("Result of the expression: " + result);
}
}

Output:

50 Write a Java program to implement a simple permission system using bitwise


operators. Define permission flags for read, write, and execute and set or check
permissions for a user.

Code:

You might also like