Home » Author Archives: Michael Scharhag

Author Archives: Michael Scharhag

Michael Scharhag
Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.

Java EE 8 MVC: Global exception handling

java-interview-questions-answers

In the previous previous posts we learned about various ways to access request information (e.g. query or path parameters) in Java EE MVC. This post shows how to apply global exception handling to an MVC application. Assume we have a controller method that might throw an IllegalArgumentException: @Controller @Path("illegal-argument") public class ExceptionController { [email protected]   public String doWork() {     // code that might throw an IllegalArgumentException   } } We could now add a ...

Read More »

Simplifying nested loops with Java 8 Lambdas

java-logo

This is just a quick tip for everyone who often has to work with multi dimensional arrays in Java 8 (or newer). In this case you might often end with code similar to this: float[][] values = ... for (int i = 0; i < values.length; i++) {   for (int k = 0; k < values[i].length; k++) {     float value = values[i][k];     // do something with i, k and value   } } If you are lucky you can replace the loops with for-each loops. However, often the indices are required for ...

Read More »

Retry handling with Spring-Retry

spring-interview-questions-answers

Whenever software components communicate with each other, there is a chance for temporary self-correcting faults. Such faults include the temporary unavailability of a service, momentary loss of network connectivity, or timeouts that arise when a service is busy. In such situations a proper retry handling can reduce the problems these faults might cause. In this post we will see how ...

Read More »

Java EE 8 MVC: Working with bean parameters

java-interview-questions-answers

In the last posts we saw how to access query, path and form parameters in MVC Controllers. This post shows how multiple parameters can be mapped to an object using the @BeanParam annotation. Let’s reuse the simple HTML form from the post about form parameters: <form action="submit" method="post">   <label>ID:</label>   <input type="text" name="id" />   <label>Name:</label>   <input type="text" name="name" />   <label>Role:</label>   <select name="role"> <option value="admin">Admin</option> <option value="reporter">Reporter</option> <option value="accountant">Accountant</option>   </select>   <input type="submit"/> </form> This defines ...

Read More »

Converting Markdown to PDF or DOCX with Pandoc

software-development-2-logo

Markdown is a popular text formatting syntax among developers these days. Popular Sites like Github or Bitbucket use Markdown for project documentation and various other types of user generated content. These sites automatically convert markdown syntax to HTML, so it can be displayed in a browser. However, maybe you want to use Markdown as document format without using a platform ...

Read More »

Java EE 8 MVC: Working with form parameters

java-interview-questions-answers

In the previous two posts we saw how to work with query and path parameters in the upcoming Java EE MVC framework. This post focuses on form parameters. When you submit a web form using a post request, the form values are send as part of the request body. The media type (or content type) defines the format that is ...

Read More »

Java EE 8 MVC: Working with Path Parameters

java-interview-questions-answers

In the previous post we saw how to work with query parameters in Java EE MVC. This post continues with a very similar topic: path parameters. Path parameters are a dynamic part of the request path and can be specified with the @Path annotation. For example: @Controller @Path("path-params") public class PathParamsController { @GET @Path("/date/{year}/{month}") public String pathParamDate(@PathParam("year") int year, @PathParam("month") ...

Read More »

Java EE 8 MVC: Working with query parameters

java-interview-questions-answers

In the previous post about the new Java EE MVC Framework we had a detailed look on Controllers. In this and the following posts we will see how to access various types of request data in MVC Controllers. Java EE MVC makes heavy use of JAX-RS and most of the things we will see in this and the next posts ...

Read More »

Java EE 8 MVC: A detailed look at Controllers

java-interview-questions-answers

Java EE MVC is a new action based MVC framework planned for Java EE 8 and specified in JSR-371. This is the second post of my Java EE 8 MVC tutorial. The first post covered the basics and shows how to get started with Ozark, the Java EE 8 MVC reference implementation. In this post we will have a more ...

Read More »

Resource versioning with Spring MVC

spring-interview-questions-answers

When serving static resources, it is common practice to append some kind of version information to the resource URL. This allows the browser to cache resources for an unlimited time. Whenever the content of the resource is changed, the version information in the URL is changed too. The updated URL forces the client browser to discard the cached resource and ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns