0% found this document useful (0 votes)
21 views

Java Answers

The document contains questions and answers related to various programming concepts like ORM, JPA, Hibernate, Spring, Java, Git, Docker, Jenkins, SQL, and Servlets. It discusses ORM stands for Operation Relation Model, JPA stands for Java Persistence API, how to declare an entity class, save objects to the database, retrieve objects from the database, customize table and column names, advantages of JPQL queries, and more.

Uploaded by

Shrey Parekh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Java Answers

The document contains questions and answers related to various programming concepts like ORM, JPA, Hibernate, Spring, Java, Git, Docker, Jenkins, SQL, and Servlets. It discusses ORM stands for Operation Relation Model, JPA stands for Java Persistence API, how to declare an entity class, save objects to the database, retrieve objects from the database, customize table and column names, advantages of JPQL queries, and more.

Uploaded by

Shrey Parekh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Ques: What ORM stand for

Ans: Operation Relation Model


Ques: What JPA Stand for
Ans: Java persistence api
Ques: How to declare class as Entity
Ans: @Entity
Ques: How to save Object in database
Ans: entityManager.persist(obj);
Ques: How to get Employee details whose id is 100 in jpa
Ans: em.find(Employee.class,100);
Ques: How to give custom name to table in jpa
Ans: {Both are correct}
Ques: What is Advantage of JPQL QUERY?
Ans: Database independent Query
Ques: How to remove record from database in jpa
Ans: Em.remove(obj);
Ques: Why H2 database not used in production
Ans: it light weight db stores data in memory
Ques: how to rename or give custom name to column in jpa
Ans: @Column
Ques: Id in entity
Ans: Jpa needs unique identifier work if did find ID
Ques: How many table will be created for 2 entity which following
OneToOne in birectional (means both table have this @OneToOne )
Ans: 3
Ques: Can we use Native Sql query in jpa
Ans: Yes
Ques: How to change join table name
Ans:
Ques: How to update record with jpa (Em=EntityManager)
Ans: Em.merge();
Ques: What maven
Generate War or jar file
Clean target folder
Compiler source code
Ans: All of the above
Ques: Can Jenkins pull code from git repository automatically, and can give
a build once we change the code and push the code in git
Ans: Yes
Ques: What is docker file?
Ans: It is just template like class file, based on this container will be created
Ques: What is correct statement about docker?
Ans: Code run in one system and does not run in other system or client
machin this issue will be resolved with docker
Ques: Limitation of micro services
Ans: Its expensive as its need more resources
Ques: What is git?
Ans: Version controlling tool
Ques: Command to push code
Ans: git push origin main
Ques: what ignore any file in git?
Ans: .gitignore
Ques: What do you mean by committing code?
Ans: Committing to local branch
Ques: Which statement is true about git?
Ans: Tool used to manage code
Ques: What is Junit Testing?
Ans: Testing specific functionality by isolating
Ques: What is mock?
Ans: Create fake Object
Ques: Can we Test all method with Mockito
Ans: No
Ques: Can we mock final class with Mockito
Ans: No
Ques: Can we create fake Object of Interface Mockito
Ans: Yes
Ques: Advantages of Power Mockito
Ans: We can mock static private final method
Ques: What is the use of @Before and @After?
Ans: it execute Before each Test and After Each Test
Ques: What is the advantage of Parameterized Test?
Ans: We can execute the one test case with different parameter with input
and expected output
Ques: Why Testing is important
Ans: To make sure code is giving expected output for provided input
Ques: How to verify the method get call in Mockito
Ans: Mockito.verify(obj,Mockito.times(1)).method_name();
Ques: How clone any repository
Ans: git clone repository_url
Ques: what is untracked file in git?
Ans: file which is newly created or no record in git
Ques: what is stashing in git
Ans: saving changes to local repository
Ques: how to add file to local repository with git
Ans: git add file_name
Ques: git push origin branch_name what this command do
Ans: push changes from local branch to remote branch
Ques: What is Advantage of Dependency Injection?
Ans: Code are loosely Coupled
Ques: How many types of IOC Container we have in spring
Ans: 2
Ques: What is the Limitation of Constructor Injection?
Ans: Partial Dependency Not Possible
Ques: How to configure java bean in spring
Ans: Using Annotation or Using XML {Both are true}
Ques: Where we can use @Bean
Ans: On Method
Ques: Where we can use @Component
Ans: On Class
Ques: What is Autowiring?
Ans: Injecting Bean Implicitly
Ques: Which of the following is not the Type of Autowiring
Ans: interface
Ques: what happens if we used Both setter Injection and Constructor
Injection
Ans: Setter Injection Override the Constructor Injection
Ques: What happens if I specify the scope as Prototype
Ans: Its create new Object every time when you ask spring to inject Object
Ques: Advantages of Hibernate
Ans: It create table automatically
Ques: When to use @Primary annotation
Ans: Used when we have 2 similar bean in container
Ques: Which one will execute First in Bean Life Cycle
Ans: constructor
Ques: Example for IOC Container
Ans: Bean Factory
Ques: Which method is execute First in AOP
Ans: @Before
Ques: What @Id represent in JPA
Ans: Primary Key
Ques: What to specify table name JPA
Ans: @Entity(table_name)
Ques: How to specify Column Name
Ans: @Column(columne_name)
Ques: Where to specify Properties in Spring boot Project
Ans: Both are true
Application.properties
Application.yml
Ques: @Controller specify
Ans: Controller in Spring mvc
Ques: Select correct statement about java
Ans: Both are true
Compiled
Interpreted
Ques: Select features of java
Ans: All are true
Object Oriented
Thread Based
Platform Independent
Ques: What is component of java from below list?
Ans: All are true
JDK
JRE
JVM
Ques: Can we access local variable outside the block/method?
Ans: False
Ques: Which one is a valid declaration of a boolean?
Ans: boolean b=true
Ques: Which of the following is not an OOPS concept in Java?
Ans: Compilation
Ques: Which one of the following is not an access modifier?
Ans: void
Ques: What is the extension of java code files?
Ans: .java
Ques: Which component is use to compile program?
Ans: javac
Ques: Class Demo{
Int a=10;
Public static void main(Strin[] arg){

}
}
Ans: compilation error
Ques: what is finally
Ans: Block
Ques: Why Interface introduced in java
Ans: Both
To Support Multiple Inheritance
To Achieve 100% Abstraction
Ques: What is the use of throw keyword?
Ans: To Throw Custom Exception
Ques: Can we override constructor
Ans: No
Ques: What is the use java command?
Ans: To see details of java classes
Ques: public class Demo {
public static void main(String[] args) {
for(int i=1;i<=10;i++) {
if(i>3 && i<9) continue;
System.out.print(i+",");
}
}
}
Ans: 1,2,3,9,10,
Ques: Which is not correct statement about array in java?
Ans: None
Ques: output of the following code
public class Demo {
public static void main(String[] args) {
System.out.println(new Emp());
}
}
Ans: EMP@randam Value
Ques: output of the following code
public class Demo {
static int a=10;
public static void main(String[] args) {
int a;
System.out.println(a);
}
}
Ans: Compilation Error
Ques: what is Class?
Ans: Blue print of an Object
Ques: output of the following code
public class Demo {
public static void main(String[] args) {
new Exception();
}
}
Ans: No output (Program Run Fine)
Ques: What Abstraction
Ans: hiding internal implementation
Ques: select access specifier among the following option
Ans: public
Ques: how to handle Runtime Exception
Ans: try-catch block
Ques: how to throw Exception
Ans: throw new Exception()
Ques: output of the following code
public class Demo {
public static void main(String[] args) {
System.out.println(new Emp(12).i);
}
}
class Emp{
int i;
Emp(int i){
i=i;
}
}
Ans: 0
Ques: how we can iterate (access) element from Arraylist
Ans: All are true
for loop
foreach loo
Iterator
Ques: what is the synchronization?
Ans: Thread execute one by one
Ques: output of the following code
public class Demo {
public static void main(String[] args) {
Emp e1=new Emp();
System.out.println(e1.i);
}
}
class Emp{
private int i=10;
}
Ans: Compilation error
Ques: Need store element in sorted order
Ans: TreeSet
Ques: Is null Allowed in TreeSet
Ans: No
Ques: what are the method need implement in Custom class to store
unique Object in Set
Ans: equals() and hashCode()
Ques: what funcational interface can have?
Ans: only one abstract method with static and default method
Ques: example for Marker Interface
Ans: Serializable
Ques: output of the following code
public class Demo {
public static void main(String[] args) {
Runnable r1=new Runnable() {
@Override
public void run() {
System.out.println(Thread.currentThread().getName
());
}
};
r1.run();
}
}
Ans: Main
Ques: which of the following class allow duplicate element
Ans: HashSet
Ques: what ResultSet in jdbc
Ans: it will give data from database after executing query
Ques: how to load driver
Ans:
Ques: query to get record based on id=20
Ans: select * from emp where id=20;
Ques: what is the output of the following code?
public class Demo {
int i=10;
public static void main(String[] args) {
System.out.println(i);
}
}
Ans: Compilation error
Ques: Who will Instantiate the Servlet?
Ans: By Server
Ques: In following option, which is not, the life cycle hooks of Servlet
Ans: Servlet Context()
Ques: Which method is more secure?
Ans: Post()
Ques: What is Web.xml file?
Ans: It is Deployment Descriptor
Ques: How do I get data in servlet, which passed from html?
Ans: Reqeust.getParameter();
Ques: Which method you will use to send large data to servlet
Ans: Post
Ques: What is the purpose of Request Dispatcher?
Ans: To forward Request
Ques: Where I can access init-param
Ans: Within the Servlet
Ques: How to Remove a Particular Attribute from session
Ans: request.getSession().removeAttribute(Attribute_name);
Ques: what is advantage of jsp over servlet?
Ans: it will compile automatically
Ques: what is the life cycle methods of servlet?
Ans: Init()
Ques: following is not the way to track session
Ans: servlet
Ques: what is filters?
Ans: it is used filter request and response
Ques: which one from following is the life cycle method of filter?
Ans: DoFilter()
Ques: What is the difference between Scriptlet <%... %> and Declaration
<%!...%>
Ans: Scriptlet is defines to local scope for service()
Ques: What is Expression <%=variable %>
Ans: It used to print on the browser
Ques: Which one is the implicit Object in Jsp?
Ans: Exception
Ques: How many scopes are there in jsp?
Ans: 4
Ques: What Model in mvc design pattern
Ans: Java Bean class

You might also like