Java Answers
Java Answers
}
}
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