Java Interview Questions and Answers | Java Tutorial | Java Online Training | Edureka
25. What is string in java?
String is a sequence of characters, for e.g. “Hello” is a string of 5 characters. In java, string is an immutable object which means it is constant and cannot be changed once it has been created.
Core Java interview questions
There are some differences between Java and C++ as follows:
|C++ supports both Procedural Oriented Programming and Object-oriented Programming models.||Java Supports only object-oriented programming models.|
|C++ can easily access the native libraries inside the system.||There’s no direct call support in Java.|
|C++ is a platform-dependent programming language. Therefore, it is not portable.||Java is a portable programming language as it is platform-independent.|
|C++ is a language that is only compiled.||Java is a programming language that is both compiled and interpreted.|
|The management of memory in C++ is manual.||The JRE controls memory management in java.|
Q5. What are wrapper classes in Java?
Wrapper classes convert the Java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below which displays different primitive type, wrapper class and constructor argument.
What is the Daemon Thread?
Daemon thread is used to perform tasks like garbage collection in the program’s background. It is a low-priority thread in java that provides services to the user thread. The life of Daemon Thread depends on the mercy of user threads, which means when all the user threads die, JVM will terminate Daemon Thread too. Collection of garbage in java and finalizer are some of the examples of Daemon Thread.
5. What is servlet in Java?
A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. For such applications, Java Servlet technology defines HTTP-specific servlet classes.
All servlets must implement the Servlet interface, which defines life-cycle methods. When implementing a generic service, you can use or extend the GenericServlet class provided with the Java Servlet API. The HttpServlet class provides methods, such as doGet and doPost, for handling HTTP-specific services.
110. What will this return 3*0.1 == 0.3? true or false?
This is one of the really tricky questions and can be answered only if your concepts are very clear. The short answer is false because some floating-point numbers can not be represented exactly.
A single try block and multiple catch blocks can co-exist in a Java Program. Explain.
Yes, a single try block and multiple catch block co-exist in a Java program.
• Every try should and must be associated with at least one catch block.
• The priority for the catch block would be given based on the order in which the catch block is defined when an exception object is identified in a try block.
• Highest priority is always given to the first catch block.
• Immediately, the next catch block is considered if the first catch block cannot be the identified exception object.