Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

12 must know Java web basics interview questions and answers

The document outlines 12 essential Java web basics interview questions and answers, focusing on topics like HTTP state management, session tracking, and the structure of HTTP requests and responses. It emphasizes the importance of understanding stateless architecture and AJAX requests in modern web applications. The content is aimed at preparing Java web developers for job interviews by providing key concepts and practical examples.

Uploaded by

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

12 must know Java web basics interview questions and answers

The document outlines 12 essential Java web basics interview questions and answers, focusing on topics like HTTP state management, session tracking, and the structure of HTTP requests and responses. It emphasizes the importance of understanding stateless architecture and AJAX requests in modern web applications. The content is aimed at preparing Java web developers for job interviews by providing key concepts and practical examples.

Uploaded by

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

06/12/2024, 19:52 12 must know Java web basics interview questions and answers

800+ Q&As Menu Contact & reviews Register Login

800+ Big Data & Java Interview FAQs


It pays to prepare & choose from 2-6 offers. Read & Write more code to fast-track & go places with confidence.

Select A to Z of Java & Big Data Techs


search here … Go

Home Why?  Career  Membership 

Home › Quick Prep Java Interview › 150+ Java Architect FAQs 📌 › Architecture - How to › 01: 12 Web basics
every Java web developer must know – Part 1

01: 12 Web basics every Java 300+ Java Interview


Q&As - Quick Prep FAQs

web developer must know – 300+ Java Interview FAQs 📌 

Part 1 150+ Spring & Hibernate


FAQs
150+ Java Architect FAQs 📌


 Posted on August 22, 2014 100+ Java code quality Q&As

150+ Java coding Q&As

Q1. HTTP is a stateless protocol, so how do you maintain state?
How do you store user data between requests?
A1. This is a commonly asked interview question. The “http protocol
is a stateless request/response based protocol”. You can retain the 300+ Big Data Interview
state information between different page requests as follows: Q&As - Quick Prep FAQs

HTTP Session. A session identifies the requests that originate from 300+ Big Data Interview
the same browser during the period of conversation. All the servlets FAQs 📌 

can share the same session. The JSESSIONID is generated by the 250+ Scala Interview FAQs 
server and can be passed to client through cookies, URL re-writing (if 250+ Python interview
cookies are turned off) or built-in SSL mechanism. Care should be FAQs 📌 

taken to minimize size of objects stored in session and objects


stored in session should be serializable. In a Java servlet the
session can be obtained as follows:
Key Areas & Companion
Techs FAQs
1 HttpSession session = request.getSession(true); //returns a c
16+ Tech Key Areas FAQs 
2
3 //To put/get a value in/from the session 10+ Companion Tech Q&As 
4 Name name = new Name(“Peter”);
5 session.setAttribute(“Firstname”, name); //session.putValue(…
6
7 session.getAttribute(“Firstname”);//get a value. session.getV
8
9 //If a session is no longer required e.g. user has logged out 
10 session.invalidate();
https://www.java-success.com/web-basics-interview-questions-and-answers/ 1/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers
11 800+ Enterprise & Core
Java Q&As

300+ Core Java Q&As 

300+ Enterprise Java Q&As 

Java & Big Data Tutorials

Web basics Tutorials - Golang 

Tutorials - Big Data 

Tutorials - Enterprise Java 


Q. Session tracking uses cookies by default. What would you do if
the cookies are turned off?
A. If cookies are turned off, you can still enable session tracking
using URL rewriting. This involves including the session ID within the
link as the name/value pair as shown below.

1 http://localhost:8080/myWebCtxt/purchase.do;jsessionid=4FB6131

Adding session ID to each and every link is cumbersome and hence


is simplified by the following methods:

1 response.encodeURL(givenURL)

to associate a session ID with a given URL and if you are using


redirection then:

1 response.encodeRedirectURL(givenURL)

When you invoke the method encodeURL(givenURL) with the


cookies turned on, then session ID is not appended to the URL. Now
turn the cookies off and restart the browser. If you invoke the
encodeURL(givenURL) with the cookies turned off, the session ID is
automatically added to the URL

Hidden Fields on the pages can maintain state and they are not
visible on the browser. The server treats both hidden and non-hidden
fields the same way.

1 <input name="Firstname" type="hidden" value="Peter">


2 <input name="Lastname" type="hidden" value="Smith">
3 
https://www.java-success.com/web-basics-interview-questions-and-answers/ 2/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

The disadvantage of hidden fields is that they may expose sensitive


or private information to others.

URL re-writing will append the state information as a query string to


the URL. This should not be used to maintain private or sensitive
information.

1 Http://MyServer:8080/MyServlet?Firstname=Peter&Lastname=Smith

Cookies: A cookie is a piece of text that a Web server can store on a


user’s hard disk. Cookies allow a website to store information on a
user’s machine and later retrieve it. These pieces of information are
stored as name-value pairs. The cookie data moves in the following
manner:

– If you type the URL of a website into your browser, your browser
sends the request to the Web server. When the browser does this it
looks on your machine for a cookie file that URL has set. If it finds it,
your browser will send all of the name-value pairs along with the
URL. If it does not find a cookie file, it sends no cookie data.

– The URL’s Web server receives the cookie data and requests for a
page. If name-value pairs are received, the server can use them. If no
name-value pairs are received, the server can create a new ID and
then sends name-value pairs to your machine in the header for the
Web page it sends. Your machine stores the name value pairs on
your hard disk.

Cookies can be used to determine how many visitors visit your site.
It can also determine how many are new versus repeated visitors.
The way it does this is by using a database. The first time a visitor
arrives; the site creates a new ID in the database and sends the ID as
a cookie. The next time the same user comes back, the site can
increment a counter associated with that ID in the database and
know how many times that visitor returns. The sites can also store
user preferences so that site can look different for each visitor.

Q2. Are states bad? if yes, why?


A2. State isn’t bad, it’s a necessity. But favor stateless architecture
for the number of reasons described below.

— You should ALWAYS make your systems not only as simple as


possible, but also as scalable as possible. In a clustered or load
balanced environment with multiple servers, maintaining of states
requires the user to always return to the same server using sticky 
https://www.java-success.com/web-basics-interview-questions-and-answers/ 3/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

sessions or else the whole system breaks down. The answer to this
problem is using sticky sessions which force the load balancer to
send traffic for a given user to the same server every time. The LB is
hardly balancing load if it can’t decide who gets the traffic. There are
other more complicated methods for sharing sessions across
multiple servers via true clustering, but getting this right is more
complicated and time consuming.

State can also be problematic from a security point of view due to


sharing the state between the client and server. There are methods
around this problem using encryption and other techniques, but
again can complicate your solution.

— The single page RIA (i.e. Rich Internet Application) making a


number of RESTFul web services via AJAX requests is a very popular
architecture. Making server side RESTful web services stateless is a
central tenant of REST. A truly stateless RESTful web service is not
only incredibly flexible and scalable thing, but also takes
responsibility for handling security and deciding who can access
what in the system. Since there is very little “under the covers stuff”
happening to try to make this stuff “easier”, you are free to
implement security however makes sense for your system.

Q3. What is the structure of an HTTP request and response?


A3. HTTP a stateless protocol, and communication between a host
and a client occurs, via a request/response pair. The client initiates
an HTTP request message, which is serviced through a HTTP
response message in return.

HTTP Request and Response


https://www.java-success.com/web-basics-interview-questions-and-answers/ 4/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

Q4. What is your understanding of HTTP URLs, HTTP Verbs, and


HTTP status codes?
A4 The heart of web communications is the request message, which
are sent via Uniform Resource Locators (URLs).

URL

URLs reveal the identity of the particular host with which we want to
communicate, but the action that should be performed on the host is
specified via HTTP verbs. A client can perform a number of actions
like GET (fetch an existing resource), POST (create a new resource),
PUT (update an existing resource,), DELETE (delete an existing
resource), etc.

With URLs and verbs, the client can initiate requests to the server. In
return, the server responds with status codes and message
payloads. The status code is important and tells the client how to
interpret the server response. The most common code is 200 OK,
which tells the client that the request was successfully processed.

3xx: like 301, 302, etc indicate redirection, which requires the client to
take additional action. The most common use-case is to jump to a
different URL in order to fetch the resource.

4xx: like 404. etc means Client Error. These codes are used when the
server thinks that the client is at fault, either by requesting an invalid
resource or making a bad request.

5xx: like 501, 503, etc means Server Error. This class of codes are
used to indicate a server failure while processing the request. The
most commonly used error code is 500 Internal Server Error.

Q5. What is your understanding of the following terms … forward,


redirect (aka sendRedirect), and post-back?
A5.

Forward

— a forward or include is performed internally by the servlet on the


server side.

— The browser is completely unaware that it has taken place, so its
https://www.java-success.com/web-basics-interview-questions-and-answers/ 5/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

original URL remains intact.


— You can set request attributes from the forwarding request (e.g.
Servlet) to the resource to which it is forwarded (e.g. another Servlet
or JSP).

forward, redirect and postback

Redirect

— A redirect is a two step process, where the web application


instructs the browser to fetch a second URL, which differs from the
original.
— A browser reload of the second URL will not repeat the original
request, but will rather fetch the second URL. This makes the second
resource link book markable.
— A redirect can be marginally slower than a forward as it requires
two browser requests as opposed to one with the forward.
— Any attributes placed in the original request scope are not
available to the second request, since it is a new request.

Post-back

— The HTTP verb POST is used to send data to the server in the
body, with XML, JSON, or form fields.
— The term “back” really means that you retrieved the page initially
with a GET verb to show user the <form> elements, and at the end
you’re sending data back. So, a PostBack is a POST request for a
page that is not the first request.

Q6. What exactly is an AJAX request?


A6. AJAX is a browser (i.e. client side) technology, which stands for
Asynchronous Javascript And XML, and an AJAX call is an
asynchronous request initiated by the browser that does not directly
result in a page transition. An AJAX request is sometimes called an
XHR request or “XmlHttpRequest”, which is the name most browsers
give the object used to send an AJAX request send/receive XML, 
https://www.java-success.com/web-basics-interview-questions-and-answers/ 6/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

JSON, plain text or HTML. So, the “X”, AJAX was coined to send and
receive XML messages asynchrously, but it can send/recive JSON,
plain text, etc.

Conventional web application trasmit information to and from the


sever using synchronous requests. This means you fill out a form, hit
submit, and get directed to a new page with new information from
the server. With AJAX when submit is pressed, JavaScript will make
a request to the server, interpret the results and update the current
screen. In the purest sense, the user would never know that anything
was even transmitted to the server. So, AJAX is Data-driven as
opposed to the conventional page-driven approach.

The modern Rich Internet Applications (RIA) use the design concept
of “single page web design“, where a single rich page makes AJAX
based service calls to render different sections of a page instead of
the traditional approach of loading a new page of each user action.
The “single page web design” can make use of client side and server
side technologies.

Q07 to Q12: 12 Web basics every Java web developer must know –
Part 2.

‹ 05: 9 Java multithreading Q&As on concepts like blocking, sequencing, preempting, time slicing

& daemon threads

03: 21+ Java Servlet interview Q&As ›

About Latest Posts

Arulkumaran Kumaraswamipillai
Mechanical Engineer to self-taught Java engineer in 1999. Contracting since 2002 as a Java Engineer &
Architect and since 2016 as a Big Data Engineer & Architect. Preparation & key know-hows empowered me
to attend 150+ job interviews, choose from 130+ job offers & negotiate better contract rates. Author of the
book "Java/J2EE job interview companion", which sold 35K+ copies & superseded by this site with 3.5K+
registered users Amazon.com profile | Reviews | LinkedIn | LinkedIn Group | YouTube Email: java-
interview@hotmail.com


https://www.java-success.com/web-basics-interview-questions-and-answers/ 7/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

How to take the road less travelled?


Practicing & brushing up a few Q&As each day on broad number of main stream categories can make a huge impact in 3-12
months.

"You are paid to read & write lots of code & solve business problems in a
collaborative environment"
100+ Free Java Interview FAQs
100+ Free Big Data Interview FAQs

Don't be overwhelmed by the number of Q&As. Job interviews are not technical contests to see who gets most number of questions right.
Nobody knows everything. The Clarity of the answers you give with real-life examples will go a long way in getting you multiple job offers.
It pays to brush-up & choose from 2-6 job offers. Experienced interviewers can easily judge your real experience from a few open-ended
questions & the answers you provide.

If you are pressed for time, popular categories are pinned 📌


for you to prioritise based on the job description. Here are my top career
making know-hows & tips to open more doors as a Java/Big Data Engineer, Architect or Contractor.

1. Feeling stagnated?
2. How to earn more?
3. Freelancing Vs contracting?
4. Self-taught professional?
5. Job Interview Tips
6. Resume Writing Tips

Top 12 popular posts last 30 days


300+ Java Interview Q&As with code, scenarios & FAQs
300+ Core Java Interview Q&As 01. Ice breaker Tell us about yourself? 02. Ice Breaker 8 Java real life scenarios…
(6,858)

300+ Big Data Interview Q&As with code, scenarios & FAQs
100+ SQL Interview Q&As 01. 50+ SQL scenarios based interview Q&As – What is wrong with this SQL code? 02.…
(2,429)

00: Top 50+ Core Java interview questions & answers for 1 to 3 years experience
Top 50 core Java interview questions covering core Java concepts with diagrams, code, examples, and scenarios. If you don't get…
(1,977)

Java 8 String streams and finding the first non repeated character with functional programming
Q1.Find the first non repeated character in a given string input using Java 8 or later? A1.Extends Find the first…
(1,676)

18 Java scenarios based interview Q&As for the experienced – Part 1


Let's look at scenarios or problem statements & how would you go about handling those scenarios in Java. These scenarios…
(1,543)

Membership Levels
Membership prices listed below are in Australian Dollars (A$). If you purchase in other currencies like Indian rupees, the equivalent…
(718) 
https://www.java-success.com/web-basics-interview-questions-and-answers/ 8/9
06/12/2024, 19:52 12 must know Java web basics interview questions and answers

30+ Java Code Review Checklist Items


This Java code review checklist is not only useful during code reviews, but also to answer an important Java job…
(524)

8 real life Java scenarios with Situation-Action-Result (i.e. SAR) technique


The SAR (Situation-Action-Result) technique is very useful to tackle open-ended questions like: 1. What were some of the challenges you…
(523)

01: 30+ Java architect interview questions & answers – Part 1


One of the very frequently asked open-ended interview questions for anyone experienced is: Can you describe the high-level architecture of…
(482)

15 Ice breaker interview Q&As asked 90% of the time


Most interviews start with these 15 open-ended questions. These are ice breaker interview questions with no right or wrong answers…
(414)

0: 50+ SQL scenarios based interview Q&As – What is wrong with this SQL code?
This extends 18+ SQL best practices & optimisation interview Q&As. You can practice these SQLs by setting up the data…
(370)

02: 10 Java String class interview Q&As


Java Collection interview questions and answers and Java String class interview questions and answers are must know for any Java…
(360)

Disclaimer
The contents in this Java-Success are copyrighted and from EmpoweringTech pty ltd. The EmpoweringTech pty ltd has the right to correct or enhance the current content without

any prior notice. These are general advice only, and one needs to take his/her own circumstances into consideration. The EmpoweringTech pty ltd will not be held liable for any

damages caused or alleged to be caused either directly or indirectly by these materials and resources. Any trademarked names or labels used in this blog remain the property of

their respective trademark owners. Links to external sites do not imply endorsement of the linked-to sites. Privacy Policy

© 2024 800+ Big Data & Java Interview FAQs Responsive WordPress Theme powered by CyberChimps

Top


https://www.java-success.com/web-basics-interview-questions-and-answers/ 9/9

You might also like