Keyword

Result: 158 questions

What is a Servlet ?

Answer:

The servlet is a Java programming language class used to process client requests and generate dynamic web content. Servlets are mostly used to process or store data submitted by an HTML form, provide dynamic content and manage state information that does not exist in the stateless HTTP protocol.

View

What is the difference between GenericServlet and HttpServlet ?

Answer:

GenericServlet is a generalized and protocol-independent servlet that implements the Servlet and ServletConfig interfaces. Those servlets extending the GenericServlet class shall override the service method. Finally, in order to develop an HTTP servlet for use on the Web that serves requests using the HTTP protocol, your servlet must extend the HttpServlet instead. Check Servlet examples here.

View

How do you find out what client machine is making a request to your servlet ?

Answer:

The ServletRequest class has functions for finding out the IP address or host name of the client machine. getRemoteAddr() gets the IP address of the client machine and getRemoteHost() gets the host name of the client machine. See example here.

View

What is the structure of the HTTP response ?

Answer:

The HTTP response consists of three parts:

  • Status Code: describes the status of the response. It can be used to check if the request has been successfully completed. In case the request failed, the status code can be used to find out the reason behind the failure. If your servlet does not return a status code, the success status code, HttpServletResponse.SC_OK, is returned by default.
  • HTTP Headers: they contain more information about the response. For example, the headers may specify the date/time after which the response is considered stale, or the form of encoding used to safely transfer the entity to the user. See how to retrieve headers in Servlet here.
  • Body: it contains the content of the response. The body may contain HTML code, an image, etc. The body consists of the data bytes transmitted in an HTTP transaction message immediately following the headers.
View

What is a cookie ? What is the difference between session and cookie ?

Answer:

A cookie is a bit of information that the Web server sends to the browser. The browser stores the cookies for each Web server in a local file. In a future request, the browser, along with the request, sends all stored cookies for that specific Web server.The differences between session and a cookie are the following:

  • The session should work, regardless of the settings on the client browser. The client may have chosen to disable cookies. However, the sessions still work, as the client has no ability to disable them in the server side.
  • The session and cookies also differ in the amount of information the can store. The HTTP session is capable of storing any Java object, while a cookie can only store String objects.
View

What is a JSP Page ?

Answer:

A Java Server Page (JSP) is a text document that contains two types of text: static data and JSP elements. Static data can be expressed in any text-based format, such as HTML or XML. JSP is a technology that mixes static content with dynamically-generated content. See JSP example here.

View

How are the JSP requests handled ?

Answer:

On the arrival of a JSP request, the browser first requests a page with a .jsp extension. Then, the Web server reads the request and using the JSP compiler, the Web server converts the JSP page into a servlet class. Notice that the JSP file is compiled only on the first request of the page, or if the JSP file has changed.The generated servlet class is invoked, in order to handle the browser’s request. Once the execution of the request is over, the servlet sends a response back to the client. See how to get Request parameters in a JSP.

View

Given two tables created as follows

create table test_a(id numeric);

create table test_b(id numeric);

insert into test_a(id) values
  (10),
  (20),
  (30),
  (40),
  (50);

insert into test_b(id) values
  (10),
  (30),
  (50);

Write a query to fetch values in table test_a that are and not in test_b without using the NOT keyword.

Answer:

In SQL Server, PostgreSQL, and SQLite, this can be done using the except keyword as follows:

select * from test_a
except
select * from test_b;

In Oracle, the minus keyword is used instead.

MySQL does not support the except function, so it is necessary to use not in.

View

Can we share sockets between processes to enable load balancing over server cores in NodeJS?

Answer:

Yes

Child processes can be spawned by using our child_process.fork() API, and are designed to be easy to communicate with. Built upon that same interface is the cluster module that helps us to share the sockets bettween processes to enable load balancing over server cores.

View

What is the problem in the code below? What would be an alternate way of implementing this that would avoid the problem?

size_t sz = buf->size();
while ( --sz >= 0 )
{
    /* do something */
}

Answer:

The problem in the above code is that --sz >= 0 will always be true so you’ll never exit the while loop (so you’ll probably end up corrupting memory or causing some sort of memory violation or having some other program failure, depending on what you’re doing inside the loop).

The reasons that --sz >= 0 will always be true is that the type of sz is size_tsize_t is really just an alias to one of the fundamental unsigned integer types. Therefore, since sz is unsigned, it can never be less than zero (so the condition can never be true).

One example of an alternative implementation that would avoid this problem would be to instead use a for loop as follows:

for (size_t i = 0; i < sz; i++)
{
	/* do something */
}
View

How many times will this loop execute? Explain your answer.

unsigned char half_limit = 150;

for (unsigned char i = 0; i < 2 * half_limit; ++i)
{
    // do something;
}

Answer:

If you said 300, you would have been correct if i had been declared as an int. However, since i was declared as an unsigned char, the corrct answer is that this code will result in an infinite loop.

Here’s why:

The expression 2 * half_limit will get promoted to an int (based on C++ conversion rules) and will have a value of 300. However, since i is an unsigned char, it is rerepsented by an 8-bit value which, after reaching 255, will overflow (so it will go back to 0) and the loop will therefore go on forever.

View

Markup validation

Consider the following markup:

<figure>
   <picture>
      <source media="(min-width: 40em)"
      srcset="large.jpg 1024w, medium.jpg 640w, small.jpg 320y">
      <img src="medium.jpg" alt="London by night">
   </picture>
   <figcaption>A landscape of London by night</figcaption>
</figure>

Is it valid? If not, can you explain why?

Answer:

The markup uses the picture element, which is a pretty new addition to the specification. The code is all valid apart from the last image specified in the srcset attribute; 320y isn’t a valid value. If the y is replaced with a w, it becomes valid though.

View

The main element

Can you explain the definition of the main element? What is its goal? Are the two specifications (WHATWG and W3C) in agreement on its definition?

Answer:

The main element has two different definitions depending on the specification used.

The W3C specification describes it as the main content of the page, that is, the content that describes the main topic of a page or is the central functionality of an application. The specification also states that a document must not include more than one main element.

The WHATWG specification doesn’t assign any semantic value to the main element and describes it as a container for the dominant contents of another element. Also, according to WHATWG, you don’t have a limit in the number of times you can use the main element in a single document. If you have multiple article elements on a page, you may want to markup the main content of each article with a separate main element.

View

WAI-ARIA

Consider the following snippet:

<header>
   <h1>Main title</h1>
   <form action="/" method="get">
      <input type="search">
      <input type="submit">
   </form>
</header>
<ul>
   <li><a href="/">Home</a></li>
   <li><a href="/products">Products</a></li>
   <li><a href="/about">About</a></li>
</ul>
<main>
   <article>
      <h1>Main title</h1>
      <p>This is the content of this section</p>
   </article>
</main>
<footer>
   <small>Copyright &amp;copy; Aurelio De Rosa 2014</small>
</footer>

Can you improve its accessibility using WAI-ARIA roles where appropriate, taking into account older technologies?

Answer:

The code can be rewritten as follows:

<header role="header">
  <h1>Main title</h1>
  <form action="/" method="get" role="search">
     <label for="search">Search:</label>
     <input id="search" type="search">
     <input type="submit">
  </form>
</header>
<nav role="navigation">
  <ul>
     <li><a href="/">Home</a></li>
     <li><a href="/products">Products</a></li>
     <li><a href="/about">About</a></li>
  </ul>
</nav>
<main role="main">
  <article role="article">
     <h1>Main title</h1>
     <p>This is the content of this section</p>
  </article>
</main>
<footer role="contentinfo">
  <small>Copyright &amp;copy; Aurelio De Rosa 2014</small>
</footer>

To improve the accessibility, the main navigation list has been wrapped with a nav element. To improve the accessibility in older technologies that don’t support the new semantic elements, the role of headernavigationmainarticle, and contentinfo have been added to the headernavmainarticle, and footer elements respectively.

Other improvements have been made on the search form. First of all the form has been marked using the search role. Then, an explicit label element has been added to give context for the input field, and it has been associated with the input through the use of the for attribute.

View

The small element

Describe when it’s appropriate to use the small element and provide an example.

Answer:

In HTML 4.01 the small element was a presentational element to mark up smaller text. In HTML5 it should be used semantically to represent legal disclaimers, caveats, and so on. The text may well be “small”, but this isn’t required.

An example of its use is shown below:

London by night
The copyright of this image is owned by Aurelio De Rosa
View

Images and accessibility

Is the alt attribute mandatory on img elements? If not, can you describe a scenario where it can be set to an empty value? Does an empty value affect accessibility in any way?

Answer:

The alt attribute is mandatory on img elements but its value can be empty (i.e. alt=""). An empty value is recommended when the image shown is used for decorative purposes only and therefore isn’t part of the content of the page. With regards to accessibility, if the alt attribute is empty, screen readers will ignore the image. This is highly recommended because using a value of something like “Content separator” will only disturb the user when this text is spoken.

View

The time element

Is it possible to express a date range using a single time element?

Answer:

No, it isn’t possible. The information can be expressed using two time elements though. For example to describe a time interval ranging from November 6, 2014 to November 9, 2014, a developer can write:

6-
9 November 2014
View

meter and progress

What’s the difference between the meter element and the progress element?

Answer:

The meter element represents a scalar measurement within a known range, or a fractional value. This element isn’t a good fit to measure something like external temperature because it doesn’t have a fixed range. However, meter can be used to describe the occupied memory of a hard disk.

The progress element is used to show the completion progress of a task. Unlike the meter element, the progress described by progress can be indeterminate. For example you could describe that a given task is progressing but that it is unknown when the task will be completed.

View

The longdesc attribute

What is the longdesc attribute? Can you explain its purpose?

Answer:

The longdesc attribute of the img element has been around since HTML 4 and is also valid in HTML5. This attribute is designed to provide a more detailed description of an image, compared to the information offered in the alt attribute. The interesting thing is that instead of providing a description by itself (like the alt attribute does), longdesc points to a hyperlink containing the description.

An example of the use of longdesc is presented below:

Italy

The shown map of Italy illustrates its division in regions...

View

The mark element

What is the mark element? Can you describe an example of use for this element?

Answer:

The mark element represents highlighted text. A typical use is to highlight every instance of the keyword or keywords searched by a user.

View

© 2017 QuizBucket.org