Let's learn java programming language with easy steps

Sunday, 8 April 2018

Struts Framework Interview Questions and Answers

Struts Interview Questions

Java Struts Interview Questions

 

Here we are going to see some important struts framework interview questions and answers which is mostly asked in advanced java or j2ee interviews.

Let's see one-by-one java struts interview questions and answers.


(1) What is Struts?

Struts is a framework which is used to create java based web application by using MVC design pattern.

Struts framework is an open source framework and extends servlet API.


(2) Which packages Struts framework use?

Struts framework use some package for developing web application e.g Java Servlets, Java Beans, XML, ResourceBundle, Jakarta packages.


(3) What is MVC?

MVC(Model View Controller) is a design pattern by using this we can design and develop the web application. 

Model represents the data and business logic. 

View used for presentation of the model.

Controller It takes the input from the user and acts as an interface between model and view. 


(4) What are the components of Struts?

There are 3 main components of the struts framework which is used to develop web applications and these are given below.

Model(java file) for containing state and business logic.

View(html, jsp, etc file) for presentation. 

Controller(Servlet or Filter) for handling request from the users.


(5) What is an Interceptor in Struts?

Interceptor is an object which provides the preprocessing and postprocessing logic before and after the action is called.


(6) What is a Configuration file in Struts?

Configuration file is a file in struts where we define action class component and view components and Interceptor also.


(7) What is struts.xml?

Struts framework provide struts.xml file which is called configuration file for mapping of an action class component and view components.


(8) What is multi-configuration in Struts?

In Struts, multi-configuration means we can use more than one .xml file for mapping e.g first.xml and second.xml, struts.xml but we have to define first.xml and second.xml in struts.xml configuration file.


(9) What is Value Stack?

Value stack contains application objects like action and other model objects.


(10) What is ActionInvocation?

It holds the action and interceptor and invokes the action.


(11) Can we create own interceptors in Struts?

Yes, We can create own interceptors in struts framework.


(12) How to create own or custom interceptors in Struts?

We can create own or custom interceptor in java struts framework by implementing Interceptor interface.

(13) What is POJO? 

POJO(Plain Old Java Object) class is simple a action class(java class).

(14) What is the role of Action class? 

An action class act as an adapter between the contents of an incoming request and the corresponding business logic that should be executed to process this request.


(15) What is ActionSupport?

In struts, ActionSupport is a class which implements Action, Validateable, Serializable etc interfaces and overrides execute() method of Action interface.


(16) What is Action?

Action is an interface with execute() method and 5 constants which is given below.

public static final String SUCCESS = "success"
public static final String ERROR = "error"
public static final String LOGIN = "login"
public static final String INPUT = "input"
public static final String NONE = "none"


(17) Why use execute() method?

In Struts , execute() method is used for business logic in action class.


(18) What is Zero Configuration?

Zero configuration means there is no need of configuration files like struts.xml etc. It is possible by using annotation or naming convention.


(19) What are the classes used as part of Struts framework?

There are some classes used in struts e.g Action Servlet, Action Class, Action Form, Action Mapping, Action Forward.


(20) What validate() and reset() method does?

Both methods are defined in the form bean. Validate method is used to validate the request parameter and reset method clear the action form data members.

Visit for more java interview Questions, link given below

Servlet Interview Questions.
JSP Interview Questions.
OOPS Interview Questions.
Top 10 Java Coding Interview Questions.

Here we discussed some most important Struts interview questions and answers in java. It will be useful to you. 


Share:

Sunday, 1 April 2018

What is the difference between C++ and Java

Difference Between C++ and Java 

Difference Between C++ and Java Programming Language

Here we going to see what is the difference between C++ and Java Programming language. Both programming language are used for software development for different-different purpose.

Here we will discuss java vs c++ differences with point-to-point.

Let's start main differences between java and c++ programming language.


Java vs c++ is also important question for both core java interviews and c++ interviews .

C++ Programming Language

  • C++ was developed in 1979.
  • C++ is invented by Bjarne Stroustrup.
  • C++ is platform-dependent programming language.
  • C++ is mainly used for windows applicaton or system or desktop application.
  • C++ supports pointer concept.
  • C++ supports goto statement.
  • C++ supports multiple inheritance.
  • C++ supports structures and union concepts.
  • C++ requires explicit memory management.
  • C++ supports both call by reference and call by value.
  • C++ supports operator overloading concept.
  • C++ is compiled programming language.
  • C++ supports conditional inclusion e.g #ifdef, #ifndef.
  • C++ does not allow documentation comment.
  • C++ does not have built-in support for threads.

Java Programming Language

  • Java was developed in 1995.
  • Java is invented by James Gosling.
  • Java is platform-independent programming language.
  • Java is mainly used for web application, desktop application, mobile application and enterprise application.
  • Java does not supports pointer concept.
  • Java does not supports goto statement.
  • Java does not supports multiple inheritance through class but it can be possible by using interface concept in java.
  • Java does not support structure and union concepts.
  • Java provides automatic garbage collection for mamory mangement.
  • Java supports only call by value.
  • Java does not support operator overloading. Supports only method overloading and method overrding.
  • Java is both compiled and interpreted programming language.
  • Java does not support conditional compilationa and inclusion.
  • Java allows documentation comment.
  • Java provides built-in supports for threads.

Here we discussed main differences between java and c++ programming language one by one.


                    Difference between HashSet and HashMap in Java.
                    Difference between String and StringBuffer.
Share:

Monday, 26 March 2018

Binary Search Program in Java

Binary Search in Java Program

Write a Java Program for Binary Search

Here we are gonna to see binary search program in java which is mostly asked in core java interviews.

Binary search is used to search specified element from the list of multiple elements. Binary search algorithm is a algorithm that find the position of a targate value within a sorted array. It compares the targate value to the middle element of the array.

Binary search is also known as half-interval search or binary chop or logarithmic search.

Let's see binary search java example.


Write a Java Program for Binary Search 

This is the simple implementation of binary search using java program. Here we are going to use Scanner class for taking input from the user e.g number of elements, values of elements, and key element for searching.

import java.util.Scanner;
class BinarySearchExample
{
public static void main(String args[])
{
int num, array[], counter, item, first, last, middle;

Scanner sc = new Scanner(System.in);
System.out.println("Enter number of elements");
num = sc.nextInt();

array = new int[num];//creating array and declare number of elements

System.out.println("Enter " +num+ " Elements ");

for(counter = 0; counter < num; counter++)
array[counter] = sc.nextInt();

System.out.println("Enter key element for searching ");
item = sc.nextInt();
first = 0;
last = num - 1;
middle = (first + last)/2;

while(first <= last)
{

if(array[middle] < item )
first = middle + 1;

else if(array[middle] == item)
{
System.out.println(item+ " found at location " + (middle + 1));
break;
}

else
{
last = middle - 1;
}

middle = (first + last)/2;
}

if(first > last)
System.out.println(item+ " not found");
}
}

Output: Enter number of elements
             5
             Enter 5 elements
             14
             65
             89
             91
             96
             Enter key element for searching
             89
             89 found at location 3

There is another way we can perform binary search operationg using java program.


Binary Search Example

This is another java program for binary search by using Arrays.binarySearch() method.

We have to import java.util.Arrays class.

import java.util.Arrays;
class BinarySearch2
{
public static void main(String args[])
{
int elements[] = {14, 65, 89, 91, 96};
int keyElement = 89;

int search = Arrays.binarySearch(elements, keyElement);
if(search < 0)
{
System.out.println(" Element not found ");
}
else
{
System.out.println(" Element is found at index " + search);
}
}
}

Output: Element is found at index 2

You can check other java programs, link given below

Linear Search Program in Java
Bubble Sort Program in Java 
Java Array Programming Interview Questions 

Here we discussed some most important binary search programs in java which will help you in java interviews.


Share:

Sunday, 11 March 2018

JSP Interview Questions and Answers

Interview Questions and Answers on JSP

JSP Interview Questions and Answers

Here we are gonna to discuss some basic and important JSP interview questions and answers. JSP is the most important topic for advance java interviews.

So let's start frequently asked java jsp interview questions.


(1) What is JSP?

JSP is known as 'Java Server Pages'. JSP is a server-side programming language which is used to create dynamic web-pages just like servlet technology. We can use jsp for making web project. In other words, by using JSP technology we can create attractive websites.


(2) Is JSP extension of Servlet?

Yes, Jsp is an extension of servlet technology.


(3) JSP page internally converted into servlet, true of false?

Yes, It is 100% true. Jsp pages internally convert into servlet.


(4) What is life-cycle of jsp?

Jsp life-cycle given below.
  • JSP page translation : Jsp page translate into servlet.
  • JSP page compilation: After translated into servlet, servlet compilation will be performed.
  • Classloading: By the help of classloader .class file of servlet will load.
  • Instantiation of Servlet: Object of servlet will create.
  • Initialization: Container will call jspInit() method only once in this phase.
  • Request Processing : Container will call -jspService() method for each request.
  • Destroy: In the last phase, Container will call jspDestroy() method.

(5) How many life-cycle methods are of jsp?

There are 3 life-cyle methods of jsp.

  1. jspInit() method.
  2. _jspService(ServletRequest  req, ServletResponse res) method.
  3. jspDestroy() method.

(6) How many implicit objects in jsp?

there are 9 implicit objects in jsp which is given below.

  1. out
  2. request
  3. response
  4. session
  5. config
  6. page
  7. exception
  8. application
  9. pageContext

(7) How to dissable session in jsp?

We can dissable session in jsp by using <% @ page session = "false" %>.


(8) Define all scripting elements in jsp?

1) Scriptlet Tag

By using scriptlet tag we can easily execute java source code in jsp file.

Syntax :

<% java code %>

2) Expression Tag 

By using expression tag we can easily get the value of any variables and methods.

Syntax :

<%= statement %>

3) Declaration Tag

Declaration tag is used to declare the variables and methods.

Syntax :

<%! declaration of variable and method %>


(9) Define all the directives in jsp?

There are 3 kinds of directives.

Jsp directive is responsible how to convert jsp page into servlet.

  1. Page Directive.
  2. Include Directive.
  3. Taglib Directive.

(10) How to declare jsp directive?

The syntax is used to declaring jsp directive,

<%@ directive attribute = "value" %>

for example : <%@ page import = "java.util.date" %>


(11) Write some attribute of jsp page directive.

There are some page directive attribute given below.
  • import
  • extends
  • contentType
  • pageEncoding
  • errorPage
  • isErrorPage
  • session
  • autoFlush
  • buffer
  • language
  • info
  • isThreadSafe
  • isELIgnored

(12) How to insert a comment in jsp page?

We can insert comment in jsp page by using  <% - jsp comment -%>.


(13) Difference between include directive and include action.

There are some differences between include directive and include action which is given below.

Include Directive
  • Include directive is better for static pages.
  • Include directive includes the original page of the content.
  • At the page translation time, It includes the content.

Include Action
  • Include directive is better for dynamic pages.
  • Include directive does not include original content.
  • At the time of a request, It includes the content.

(14) Is that mandatory to configure jsp file in web.xml file?

No, It is optional. We can run web application without configuration of jsp file in web.xml file.


(15) What is the difference between JSP and Servlet?

There are many differences between JSP and Servlet.

JSP(Java Server Pages)
  • JSP is easy to learn.
  • JSP provides some predefine tags such scriptlet tag, custom tag, expression tag, etc.
  • There is no need to configuration of jsp file in web.xml file.
  • Both presentation and business logic are separated in jsp.
  • There is no need to recompile and redeploy of jsp file if we modify any jsp file.
  • JSP provides certain implicit objects.

Servlet
  • Servlet is not easy to learn.
  • Servlet does not provide any tags.
  • We have to configure servlet in web.xml file.
  • Both presentation and business logic are not separated in servlet.
  • If we modify and servlet then we have to recompile and redeploy the project.
  • Servlet does not provide implicit objects.

(16) What is expression language?

Expression language provides simple and easy to access the data from implicit objects and bean.


(17) What is JSTL?

JSTL stands for JSP standard tag library which is the collection of some useful core tags which make the software development easy and fast.

Visit : Servlet Interview questions and answers.
          OOPS Interview questions and answers.
          Java Multithreading Interview Questions.
          Java Collection Interview Questions.
          Struts Framework Interview Questions.
          Top 10 Java Programming Interview Questions for Fresher.

I hope, this java jsp interview questions and answers will help you in java interviews.

Share:

Tuesday, 6 March 2018

Servlet Interview Questions and Answers

Servlet Interview Questions

Servlet Interview Questions

Here we are going to focus on some most useful java servlet interview questions and answers.

Let's start java j2ee interview questions on servlet one-by-one.


(1) What is Servlet?

Servlet is a technology and server-side programming language which is used to create dynamic web pages. For request, Servlet generates dynamic web pages as the response.


(2) What is the Servlet life-cycle in Java?

  • Loading Servlet : Servlet class loaded by servlet container.
  • Instantiation of Servlet : Object of servlet class created.
  • Initialization of Servlet : Initialization of servlet by calling init() method.
  • Calling service() method of Servlet : Calling service() method of servlet for service the client's request.
  • Calling destroy() method of Servlet : Destroy the instance of servlet by calling destroy() method.

(3) Servlet life-cycle methods in Java?

There are 3 life-cycle methods of Servlet.

  1. init(ServletConfig config) method.
  2. service(ServletRequest req, ServletResponse res)throws ServletException, IOException method.
  3. destroy() method.

(4) What is Container in Java?

Server container is the container which provides runtime environment to manage an application component developed according to API specification and to provide access to the J2EE API.


(5) What is the work of container?

There is some work which is performed by the container.
  • Life-cycle management of servlet.
  • Communication support.
  • Providing multithreading support for handling multiple requests at the same time.
  • Manage web.xml file.
  • Security support.

(6) When servlet object is created?

At the time of the first request, servlet object is created.

(7) How many objects of a servlet is created?

At the time of the first request, Only one object is created by the web container.


(8) What is the difference between get() and post() method?

Method get()
  • We can send the limited amount of data through get() method.
  • This method is not fully secured because data is exposed in the URL bar.
  • This method is faster than post() method.
  • This method allows bookmarking of the resources.
  • This method is not good important and confidential data like password, personal documents, etc.  
Method post()
  • We can large amount of data through post() method. There is no limitation.
  • This method is fully secured because data is not exposed in the URL bar.
  • This method is slower than get() method.
  • This method does not allow bookmarking of the resources.
  • This method is good for important and confidential data like password, personal documents, etc.

(9) Difference between GenericServlet and HttpServlet?

GenericServlet class is protocol independent i.e It can work other protocols just like HTTP.

HttpServlet is protocol dependent i.e It can work only HTTP protocol not other.


(10) When servlet is loaded?

When web container receives the first request from the client(web browser).


(11) What is the use of web.xml file in servlet?

Web.xml file is also known as deployment descriptor in a web application. Web.xml file contains all the information of web project components like servlet name, servlet class, URL pattern etc. The container receives all the information from this deployment descriptor file to execute particular servlet class for the given URL pattern.

We can map multiple servlets in a single web.xml file.


(12) What is ServletConfig?

  • ServletConfig is an interface.
  • There is one ServletConfig object per servlet.
  • Use it to pass deploy time information to servlet that you do not want to hardcode into the servlet.
  • Parameters are configured in the deployment descriptor. 

(13) What is ServletContext?

  • ServletContext is an interface.
  • There can be only one ServletContext object per web application.
  • Use it as kind of application bulletin board where you can put up messages that other part application can access.
  • Parameter is also configured in the deployment descriptor.

(14) Difference between ServletConfig and ServletContext?

One ServletConfig object per servlet in the web application project whereas one ServletContext object per web application.

(15) Why use welcome-file-list?

It is used to define welcome file for the project. We can define welcome-file-list in web.xml file.


(16) Why use load-on-startup in servlet?

The load-on-startup is used to fast response of request because it loads the servlet at the time of deploying the project or server start. We can define load-on-startup in web.xml file.

<load-on-startup>1</load-on-startup> 

We can pass negative value also.


(17) What is session tracking in servlet?

Session tracking is used to track a session of a particular interval of time. Session tracking is used to maintain the state of a user to recognize to the particular user.

(18) How many ways session tracking can be performed in servlet? 

There are 4 ways we can perform session tracking in java servlet.
  • Cookies
  • URL rewriting
  • Hidden form field
  • HttpSession

(19) What is a war file?

War file (web archive) file specifies all the web components. All the web component or elements(servlet, jsp, etc) compressed into a single file called war file and then we can deploy this war file to the server.


(20) What is Servlet Collaboration?

When one servlet connects with another servlet is known as servlet collaboration.


(21) What is RequestDispatcher?

RequestDispatcher is an interface in servlet and it is used to dispatch the request to another resource e.g html, servlet, jsp, etc.

(22) Difference between forward() and sendRedirect() method in servlet?

Method forward()
  • This method sends same requests to another resource.
  • This method works at the server side.
  • This method is faster than sendRedirect() method.
Method sendRedirect()
  • This method sends the new request.
  • This method works at the client side.
  • This method is slower than forward() method. 

(23) Can we call jsp from a servlet?

Yes.

(24) Can we define a constructor in servlet?

Yes.

(25) Can we call destroy() method inside init() method of servlet?

Yes.

(26) What is filter?

Filter is an object which is invoked either at the pre-processing or post-processing of the request.

Check out more java interview questions : 

OOPS interveiw questions in java
Java collection interview questions.
String programming interview questions in java.

The above all the java servlet interview questions and answers are quite useful for both fresher and experienced.

Share:

Facebook Page Likes

Follow javatutorial95 on Google+

Follow javatutorial95 on twitter

Popular Posts

Translate