
Brane Enterprises

Brane Enterprises Java Developer Interview Questions and Answers
Static variables and methods belong to the class rather than instances of the class.
Static variables are shared among all instances of a class.
Static methods can be called without creating an instance of the class.
Example: public static int count = 0; public static void incrementCount() { count++; }
For loop is used when the number of iterations is known, while While loop is used when the condition is true.
For loop is used when the number of iterations is known beforehand.
While loop is used when the condition is true.
For loop has initialization, condition, and increment/decrement in one line.
While loop only has a condition to check before each iteration.
Example: for(int i=0; i<5; i++) { //code }
Example: int i = 0; while(i < 5) { //code i++; }
A do-while loop is a control flow statement that executes a block of code at least once, and then repeatedly as long as a specified condition is true.
The code block is executed first before checking the condition.
The condition is checked after the code block is executed, and if it is true, the code block is executed again.
The loop continues until the condition becomes false.
Example: do { System.out.println('Hello'); } while (condition);
Q4. What is static variable and method
Static variables and methods belong to the class rather than the instance of the class.
Static variables are shared among all instances of the class
Static methods can be called without creating an instance of the class
Static variables and methods are accessed using the class name, not an instance variable
Example: Math.PI is a static variable in the Math class
Example: Math.sqrt() is a static method in the Math class
Q5. Difference between while loop and for loop
While loop is used when the number of iterations is unknown, whereas for loop is used when the number of iterations is known.
While loop checks the condition before executing the code block, whereas for loop checks the condition after executing the code block
For loop is more concise and readable when the number of iterations is known
While loop is more flexible and can be used for infinite loops or when the number of iterations is not known
Example of while loop: while(i < 10) {...read more
Q6. What is do while loop
A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given condition.
The loop body is executed at least once before the condition is checked
The loop continues to execute until the condition becomes false
Syntax: do { // code block } while (condition);
Example: do { System.out.println(i); i++; } while (i < 5);
Q7. Write any code
Code to print 'Hello World' in Java
Create a class with a main method
Use System.out.println() to print 'Hello World'

Top Java Developer Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

