background preloader

Java

Facebook Twitter

Spring MVC Interview Questions with Answers - HowToDoInJava. These Spring MVC interview questions and answers have been written to help you prepare for the interviews and quickly revise the concepts in general. I will strongly suggest you to go deeper into each concept if you have extra time. The more you know, more you are confident. Table of Contents What is Spring MVC framework? What is DispatcherServlet and ContextLoaderListener? What is the front controller class of Spring MVC? How to use Java based configuration? What is Spring MVC framework? The Spring web MVC framework provides model-view-controller architecture and ready components that can be used to develop flexible and loosely coupled web applications.

Clear separation of roles -- controller, validator, command object, form object, model object, DispatcherServlet, handler mapping, view resolver, etc. What is DispatcherServlet and ContextLoaderListener? After receiving an HTTP request, DispatcherServlet consults the HandlerMapping (configuration files) to call the appropriate Controller. Microsoft SQL Server Index Architecture. Spring MVC 4.0 RESTFul Web Service JSON Response with @ResponseBody | ProgrammingFree. Article Recognitions* A mention about this article in official spring blog here.Big Link in Dzone This tutorial is a continuation of my previous tutorial titled Spring MVC 4.0 RESTFul Web Service Simple Example. I explained the basics of how Spring MVC can be used to build RESTFul Web Services with a simple example that returns greeting message in the form of plain text. Let us extend that example to see how to use Spring MVC REST functionality to return json response from server.

As I mentioned in my previous article, we can eliminate the usage of ViewResolver as Spring provides an out of the box functionality wrapped inside @ResponseBody annotation. In this tutorial, I am going to explain with an example, on how to build Spring RESTFul Web Service that would return user information in JSON format from an underlying MySql table. Lets get started with our sample application, 1. 2. 3. 4. 5. 6. 7. 8. Spring MVC 4.0: Consuming RESTFul Web Services using RestTemplate | ProgrammingFree. This article is a continuation of my previous article on Spring MVC 4.0 RESTFul web services. So far I have written two articles on how to create restful web service using Spring MVC 4.0.

Last tutorial explained how to create a RESTFul web service in spring that would return user information from mysql table in JSON format. Let us now implement a Spring MVC application that issues web service requests and fetches the response returned by the web service. In this tutorial, we will extend our previous example to include a class that fetches user data from the spring service we had already created and display it in a jsp page (view). Spring MVC is a complete framework with lot of inbuilt features that facilitates easy and quick web development, including a template class - 'RestTemplate' for consuming web services. I assume that you have gone through my previous article and have created a web service as explained. RestTemplate Enough of theory, now let us proceed with the sample application.

Java JSON parser Example. JSON is a simply text format that facilitates reading and writing. It is a widely used data-interchange language because its parsing and its generation is easy for machines. In Java language there are some ways for JSON processing. In this example we are going to use a common Java toolkit for JSON – JSON.simple – and we will find out how to parse every type of a json file. 1.

Set the Environment Before start coding we have to set a proper environment for the compiler, in order to recognize the JSON's classes. If you want to built your project via Maven, you should add the following dependency to your pom.xml: Otherwise, you have to add the newest version of json-simple-1.1.1.jar in your CLASSPATH. 2. As we mentioned, we will show how we can parse a json file, so we will make our own .json file.

JsonTestFile.json: Now create a java file in your project, named JsonParseTest. JsonParseTest.java: Now lets explain the code above. You can see the output of the execution below. Output: Spring MVC 4.0 RESTFul Web Service JSON Response with @ResponseBody | ProgrammingFree. Spring Restful Web Service Example with JSON, Jackson and Client Program | JournalDev. Getting Started · Building a RESTful Web Service. In Spring’s approach to building RESTful web services, HTTP requests are handled by a controller. These components are identified by the @RestController annotation, and the GreetingController shown in the following listing (from src/main/java/com/example/restservice/GreetingController.java) handles GET requests for /greeting by returning a new instance of the Greeting class: package com.example.restservice; import java.util.concurrent.atomic.AtomicLong; import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController; @RestControllerpublic class GreetingController { private static final String template = "Hello, %s!

"; private final AtomicLong counter = new AtomicLong(); @GetMapping("/greeting") public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) { return new Greeting(counter.incrementAndGet(), String.format(template, name)); }} Sample Program - Java String Manipulation, String creation in Java, charArray to String in Java, isEmpty() & length() in Java, Different way to use concat() in Java, charAt(), indexOf() & lastIndexOf() in Java, compareTo() & compareToIgnoreCase() in Java,

Spring MVC + jQuery Autocomplete example. In this tutorial, we show you how to integrate jQuery autocomplete plugin with Spring MVC. Tools and Libraries used : Spring MVC 3.2jQuery autocomplete plugin – githubMaven 3Eclipse IDE Review the tutorial’s flows : An HTML page, with a textbox.If the user is tying on the textbox, it will fire an Ajax request (via autocomplete plugin) to Spring controller.Spring process the user input and return the search result (in JSON format).The “autocomplete plugin” process the returned result and display the autocomplete suggestion box. See figure above. 1. Review the final project directory structure, a standard Maven project. 2. Declares Spring, JSTL and Jackson(JSON result). pom.xml <properties><spring.version>3.2.2.RELEASE</spring.version><jstl.version>1.2</jstl.version><jackson.version>1.9.10</jackson.version></properties><dependencies><!

3. A Spring controller, if user issue a “/getTags” request, Spring will filter out the result with user input and return it in JSON format. MainController.java #1. Spring Tutorial 05 - ApplicationContext and Property Initialization. Spring MVC Interview Questions with Answers - HowToDoInJava.

Design Patterns

Abstract Factory Design Pattern in Java. Back to Abstract Factory description Abstract Factory classes are often implemented with Factory Methods, but they can also be implemented using Prototype. Abstract Factory might store a set of Prototypes from which to clone and return product objects. Factory Method: creation through inheritance. Prototype: creation through delegation. Virtual constructor: defer choice of object to create until run-time. D:\Java\patterns> java FactoryFmProto "short" "lie" "old" "my way, or the highway" "take test, deal with the results" D:\Java\patterns> java FactoryFmProto 1 "vertically challenged" "factually inaccurate" "chronologically gifted" "do it your way, any way, or no way" "you pass, self-esteem intact" Read next This article is taken from our book Design Patterns Explained Simply.

All of the design patterns are compiled there. We distribute it in PDF & EPUB formats so you can get it onto your iPad, Kindle, or other portable device immediately after your purchase. Learn more.