Interview Questions and Answers - Order By Newest Q1861. Why the following code produced this output ?
int x = 5;
int y = x;
y = 10;
System.out.println(x); // prints 5 and not 10 Core Java
Ans. Because when we say y = x, the value of x is copied to another memory location and then y points to that new memory location.
Unlike object references that once assigned point to same object in memory, value is copied in case of variable assignment. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  variable assignment Q1862. In which memory segment - heap or stack, the following stored by JVM
1. static members
2. objects
3. object references
4. local or method variables
Core Java
Ans. static members are stored in method area of heap
objects are stored on heap
object references are stored on stack
local or method variables are stored on stack Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jvm  memory management  stack  heap Q1863. Write a Program to implement stack using LinkedList. Data Structure
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Structure Q1864. Describe how you could use a single array to implement three stacks Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Structure Q1865. How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Stricture   Big O Notation  time complexity Q1866. Write a program to sort a stack in ascending order You should not make any assumptions about how the stack is implemented The following are the only functions that should be used to write this program: push | pop | peek | isEmpty Algorithm
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Data Structures Q1867. How can we convert String into Char array and vice versa ? Core Java
Ans. There is a method toCharArray() within String class that can be used to convert string to char array.
string.toCharArray();
String class has an argument constructor that takes a char array and create a string
new String(charArray); Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  char array Q1868. How can we convert a character or a character array into a String ? Core Java
Ans. String has an argument constructor that take char array as argument and creates a string.
There is no constructor available with String that takes in a character and creates a String. We can use StringBuilder which has a char argument constructor. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  character  char  char array  String  char to String  char array to StringAns. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  generics Asked in 7 Companies Q1870. What is ORM or Object Relationship Mapping ? Database
Ans. ORM is the mapping technique, which maps object with relational data model. As we know that in java we need objects we can not user data in relational(in table form). So ORM is set of guideline which allows us to map relational data model in object form. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  orm Asked in 1 Companies   frequent Q1871. What are the uses of Abstraction ? Core Java
Ans. Loose Coupling
Facilitates designing complex applications by making them modular. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops concepts  abstraction Asked in 1 Companies Q1872. What are the disadvantages of Bean Auto Wiring in Spring ? Spring
Ans. It can always be overridden with explicit wiring. Moreover it's confusing if we use both explicit as well as explicit wiring in the project. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Spring beans  auto wiring  autowiring Q1873. Why is JVM called Virtual machine ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  jvm Q1874. Lets say we have a set "set1" with objects of Class A, Class has a non static string called element1, Write a code ( using lambda expression ) to see if there is any object in the set with element1 = "Hello". Core Java
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent();
or
set1.stream().map(A::getElement1).anyMatch("Hello"::equals) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  lambda expressions  java 8  java8  java 8 filter  findAny() Q1875. Which of the OOP's features facilitate dependency injection ? Design
Ans. Inheritance , Runtime Polymorphism and Composition. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  dependency injection  inversion of control  ioc  oops  oops features Q1876. Is Runtime Polymorphism possible without Inheritance ? Core Java
Ans. Yes, Runtime Polymprohism requires either Class inheritance or Interface implementation. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  runtime polymorphism  object oriented programming (oops)  oops concepts  method overriding  inheritance  object oriented programming (oops)  oops concepts Q1877. Why is Java such an important Programming language ? Core Java
Ans. Because of following features
Object Oriented and hence helps build maintainable and easily enhanceable code.
Platform Independence and hence can be executed anywhere
Fast due to JIT compiler Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Q1878. Why Java is considered more purer object oriented language than C++ ? Core Java
Ans. Because of
lack of use of pointers,
Lack of structural programming and
Lack of Multiple Inheritance Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops  java vc c++ Q1879. Does Wrapper classes produces immutable objects ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  wrapper classes  immutable  immutability Q1880. Why shouldn't we use string concatenation extensively or in a loop ? Core Java
Ans. Because String being an immutable object creates a new object upon each concatenation cycle. If there is any such need , we should use String Builder whose objects are mutable. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string  string immutable  immutability  for loop  control statements  loop statement Asked in 1 Companies Q1881. What do we mean by a Data Type ? Core Java
Ans. if you have similar type of data or objects or entities, then we can give them a type with unique name. And this name will be our Data type. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data type Q1882. As root, if you have to assign the owner for the file and set only read permission for the owner, Write a unix command to do it. Unix
Ans. chmod 477 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  unix commands  setting file permissions  chown  chmod Q1883. In the following code, which text will get printed immediately after Hello
for(int countx=0;countx<10;count++){
System.out.println("World");
for(int countx=0;countx<10;count++){
System.out.println("Friend");
for(int countx=0;countx<10;count++){
System.out.println("Hello");
break;
}
System.out.println("Buddy");
}
}
Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  break statement Q1884. Which of the two - iteration or recursion - is slower ? Core Java
Ans. Any function call is slower than the code in the same method as Java has to maintain stack of meta and function call information. So recursion is slower. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  iteration  recursion  iteration vs recursion Q1885. In case of generic class declared like following , What can T hold
class MyClass<T>{
T element;
} Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  generics Q1886. What features would you like to see in Java 10 ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java10  java 10 Q1887. Can we instantiate the object of derived class if parent constructor is private ? Core Java
Ans. No Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor  private constructor Q1888. How do you design microservices? Design
This question was recently asked at 'Citigroup Bank,Sofi'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  microservices Asked in 2 Companies Q1889. Can an enum extend another enum ? Core Java
Ans. No Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  enum Q1890. Can we have a sub enum within an enum ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  enum  enum within enum