In this session we will discuss the interview questions of Cognizant for Java Full Stack Developer profile.
Q. What you know about String?
Ans
String is a class available inside the lang package.
String is final class so it can't be extended by any of the classes.
String object are immutable in nature – it means once string object is created it can't be changed latter on.
Q. How you can create the String object?
Ans : Two way to create the object
with using new keyword – String s1 = new String('xadmin');
without new keyword – String s2 = "xadmin" ;
Q. Do you know how String internal store its reference in memory?
Ans: String uses special memory location for reusing string literals and this memory location is called as String Constant Pool.
if we create String object with new keyword
Firstly, it will check whether the corresponding literal is available inside string constant pool or not. If it is not available then it will create new string literal inside string constant pool and come out and will create another literal outside the string constant pool and that reference will be assign to the corresponding reference variable.
When we create string object with a new operator and if that string literal is already available then it will not create new literal inside string constant pool
It will come out and create one literal outside string constant pool and that string reference will be assign to that corresponding reference variable.
if we create String object without new keyword
When you create string object without new keyword then firstly ,it will check whether that string literal is available inside string pool or not.
If that literal is not present inside string constant pool then it will create string literal inside pool and it will point to that created literal.
if string literal is present inside SCP then it will point to that literal itself and it is not going to create new literal inside or outside SCP.
Q. As you said earlier that String is immutable – So do you know how you can create and custom immutable class in java?
Ans:
Step 1 – Declare the class as final – so can't be extended further.
Step 2 – Declare all the fields as final – so field value can't be changed once it is assigned.
Step 3 – Declare all the fields as Private – so can't access from outside the class
Step 4 – Don't provide any method which can change the state of the object , for example the setter method which changes the value of the instance variable. Only provide getter method.
Step 5 A parameterized constructor should initialize all the fields performing a deep copy so that data members can’t be modified with an object reference.
Q. What is the difference between ClassNotFoundException and NoClassDefFoundError?
Ans:
ClassNotFoundException – An exception that occurs when you try to load a class at run time using class.forName() or load class method and mention class is not found in the class path is called ClassNotFoundException.
NoClassDefFoundError – An exception that occurs when a particular class is present at compiletime but was missing at run time is called NoClassDefFoundError.
Q. What is an exception in java and how you handle exception in java?
Ans: An exception is a failure condition that occurs during the execution of a program and disrupt the normal flow of the program. It has to be handled properly – failing to do this – will terminate program abruptly.
We can handle exception by using try and catch block.
Q. is finally block always be executed?
Ans: Finally block is always executed but there is one scenario when finally block does not execute – by using system.exit(1) in try or catch block because it will terminate the running java virtual machine.
Q. What are the https methods?
Ans: Get , Post, Put, Delete, Head, Option, Patch
Q. Difference between GET and PUT method.
Ans – GET – Data goes with URL . Not safe
POST – Data goes with request body. More safe
How much you are comfortable in MYSQL?
Q. SQl Query to fetch the name of employee who earn the hightest salary.?
Ans: Select firstname,salary from employee where salary = (select max (salary) from employee.
Q. What are joins?
Ans – Joins are used to fetch the data from multiple tables and it is used with select statement
Types of joins:
inner join (simple join)
left outer join
right outer join
Q What are the Bean scope in Spring?
Ans –
1. Singletone single instance will be created per spring IOC container
2. Prototype – Multiple instance will be created
3. request – scope of the bean will be to the particular http request.
4. session – scope of a bean will be for per http session.
5. global –session – scope of a bean will be global to http session.
#cognizant #interview #fullstackdeveloper