Wittybrains Software Technologies
SasteGhar.com Interview Questions and Answers
Q1. Wap where n=2, power=3, output=8 using recursion
A Java program to calculate the power of a number using recursion.
Create a recursive function that takes two parameters: the number and the power.
If the power is 0, return 1.
If the power is 1, return the number.
Otherwise, recursively call the function with the number multiplied by itself and the power decreased by 1.
Return the result.
Q2. Wap to print prime number between 1-100 alternately?
Print prime numbers between 1-100 alternately using Java.
Create a function to check if a number is prime or not.
Use a loop to iterate through numbers 1-100.
Alternate between printing prime and non-prime numbers.
Use a boolean variable to keep track of whether the last printed number was prime or not.
Q3. Wap to print prime number between 1-100?
A program to print prime numbers between 1-100.
Iterate from 1 to 100
For each number, check if it is divisible by any number from 2 to itself-1
If not divisible by any number, it is a prime number
Q4. how to create thread
To create a thread in Java, you can extend the Thread class or implement the Runnable interface.
Extend the Thread class and override the run() method
Implement the Runnable interface and pass an instance to the Thread constructor
Start the thread using the start() method
Example: Thread thread = new Thread(() -> System.out.println("Hello World")); thread.start();
Q5. Overloading vs Overriding
Overloading is having multiple methods with the same name but different parameters. Overriding is having a method in a subclass with the same name and parameters as a method in its superclass.
Overloading is compile-time polymorphism while overriding is runtime polymorphism
Overloading is used to provide different ways of calling a method with different parameters
Overriding is used to provide a specific implementation of a method in a subclass
Overloading can be done in the same...read more
Q6. Methods in thread
Methods in thread are used to perform tasks concurrently.
Thread.start() method is used to start a new thread.
Thread.sleep() method is used to pause the execution of a thread.
Thread.join() method is used to wait for a thread to finish its execution.
Thread.yield() method is used to give a chance to other threads to execute.
Top Java Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month