Hi, in this post we are going to explore Twinkle Software Solution Java Fresher Interview Questions with Answers. Let us discuss the questions briefly;

Twinkle Software Solution Java Fresher Interview Questions with Answers

1. What is exception handling?except

=>In Java, an exception is an event that disrupts the normal flow of the program. It is an object which is thrown at runtime.
=>Exception Handling is a mechanism to handle runtime errors such as ClassNotFound, IO, SQL, Remote etc.
=>Java exception handling is managed via five keywords: try, catch, throw, throws, and finally.
=>The core advantage of exception handling is to maintain the normal flow of the application. 
=>It helps to propagate error reporting up the call stack of methods.
=>It groups and differentiates various types of errors.

2. What is thread?THREAD

=>A thread, in Java, is the path followed when executing a program.
=>All Java programs have at least one thread, known as the main thread
=>It is created by the Java Virtual Machine (JVM) at the program’s start, when the main() method is invoked with the main thread.
=>Every Java thread is created and controlled by the java.lang.Thread class.
=>Java is a multi-threaded application that allows multiple thread execution at any particular time.
=>The JVM stops executing threads under either of the following conditions:
I. If the exit method has been invoked and authorized by the security manager
II. All the daemon threads of the program have died.

3. What is the difference between stringbuffer and stringbuilder?

The difference between stringbuffer and stringbuilder are as follows:



StringBuffer is present in Java StringBuilder was added in Java 5
StringBuffer is synchronized which means all method which modifies the internal data of StringBuffer is synchronized e.g. append(), insert() and delete(). On contrary, StringBuilder is not synchronized.
Because of synchronization StringBuffer is considered thread safe StringBuilder is not synchronized hence not thread safe.
StringBuffer is less efficient than StringBuilder. StringBuilder is more efficient than StringBuffer.

4. How to handle the exception?

EXCEPTION HANDLING METHODS :Java provides specific keywords for exception handling purposes, which are as follows;
throw – Sometimes, we might want to generate exception explicitly in our code, for example in a user authentication program we should throw exception to client if the password is null. throw keyword is used to throw exception to the runtime to handle it.
throws – When we are throwing any exception in a method and not handling it, then we need to use throws keyword in method signature to let caller program know the exceptions that might be thrown by the method.
try-catch – Try is the start of the block and catch is at the end of try block to handle the exceptions. We can have multiple catch blocks with a try and try-catch block can be nested also. catch block requires a parameter that should be of type Exception.
finally – finally block is optional and can be used only with try-catch block. We might have some resources open that will not get closed, so we can use finally block. finally block gets executed always, whether exception occurred or not.
}catch(IOException e){
System.out.println(“Releasing resources”);

public static void testException(int i) throws FileNotFoundException, IOException{
if(i < 0){
FileNotFoundException myException = new FileNotFoundException(“Negative Integer “+i);
throw myException;
}else if(i > 10){
throw new IOException(“Only supported for index 0 to 10”);



5. Difference between checked and unchecked exception?

=>Checked exception means Compiler checked Exceptions. It means that compiler mandates that such exception to be handled by try-catch block or throws keyword.
=>Unchecked exceptions are the ones for which compiler doesn’t provides any mandate as they can be resolved by developer by coding/programing as the control flow is controllable.
=>The major diffferences between the two is as follows:VS

6. What is database?

=>A database is an organized collection of data.
=>Database handlers create database in such a way that only one set of software program provide access of data to all the users.
=>The main purpose of database is to operate large amount of information by storing, retrieving and managing.
=>There are many database available like MySQL, Sybase, Oracle, Mango DB, Informix, Postgre, SQL Server etc.
=>SQL or Structured Query Language is used to perform operation on the data stored in a database. SQL depends on relational algebra and tuple relational calculus.Java_DB

7. If the program will execute without main function or not?

=>A program can be compiled and executed without main method if we use static initalizer and having System.exit(0); statement at the end lets the program to exit before JVM is looking for main method. However, this can be done only upto JAVA-6 version
=>From Java-7 version the program gets compiled but will not get executed and will show an error message as
“The program compiled successfully, but main class was not found. Main class should contain method: public static void main (String[] args).”
=>Servlets and applets do not require main method for their execution.

8. What is meant by synchronized Thread?sync

=>Thread synchronization is the concurrent execution of two or more threads that share critical resources.
=>Threads should be synchronized to avoid critical resource use conflicts.
=>Otherwise, conflicts may arise when parallel-running threads attempt to modify a common variable at the same time.
=>In Java, two synchronization strategies are used to prevent thread interference and memory consistency errors viz., Synchronized Method and Synchronized Statement