Spring Framework Overview

Spring make it easy to create java enterprise applications,it provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Spring Framework was developed by Rod Johnson in 2003,Spring framework make the easy for java enterprise application. Spring is open source.it has large and active community that provides continuous feedback base on diverse range of real world use cases.

"Spring", means different things in different contexts.Spring Project have been build on top of the Spring Framework.It is divided into modules and at the heart are the modules of the core container, including a configuration model and a dependency injection mechanism. Beyond that, the spring framework provides foundational support for different application architectures, including messaging, transactional data and persistence, and web. It also includes the Servlet-based Spring MVC web framework and, in parallel, the Spring WebFlux reactive web framework.

Spring Framework

We will learn more about these modules in next page.



JSP and Servlet Interview Question Part-1

Q1. What is the servlet?
Ans: Servlet is simple java class and it extending the functionality of a web server and that are execute on the server side.
It requires a servlet container to run .

Q2. Why we used servlet?
Ans:To handle client request and response(mostly in the from of HTTP/HTTPS request)or forward the request to another servlet or jsp

Q3. Explain Servlet Life cycle?
Ans: servlet life cycle controller by Servlet Container and container performs the following steps.
If an instance of the servlet does not exist ,web container
Step 1 :load the servlet class.
Step 2 :Creates an instance of the servlet class and initialize the servlet instance by calling the init() method.
Step 3 :Invokes the serivce method, passing a request and response object.
to the service()  method.
Step 4:If the container needs to remove the servlet,it finilizes the servlet by calling the servlet's destory method.

Q4. What are scope object available?
Ans:Enable sharing information between we application via attributes mentioned in the Scope objectAttributs mentained in scope Object are
access with setAttributs and getAttribute();

Q5. JSP implicity Object?
Ans: Request
        Responce
        PageContext
        Session
        applicaiton
        Out
        Config
        page
        exception

Q6. JSP Scope Object?
Ans:Page Scope   :a Single page
    Request Scope:Pages Processing the same request
    Session Scope:Pages processing the request that are in same session
    Application Scop : all pages in an application

Q 7 .What is Request Dispatcher?
When building a web application ,you want to forward processing to another component. or if you want to include the
processing of another component in the current response.
In Servlet API,we need to use a Request Dispatcher.This is retrieve from the ServletContext.

  public RequestDispatcher  getRequestDispatcher(String path)

The RequestDispatcher is create base on the path used to to obtain it(You must begin with a "/")
  public void forwared(ServletRequest request,ServletResponSe response)
  public void include(ServletRequest request ,ServletResponce response)

Q8. What is difference between SendRediresct and Forward?
Ans: When we used forward method request is transfer to other resource within the same server for further processing.
and in case sendRequest request is transfer is transfer to another resource to differance domain or different server for further processing.
Next difference is visually we are not able to see the forwarded address,it is transparent and in sendRedirect we are see the new redirected address it's not transparent

Spring Boot Interview Question

Q1. What is key advantage of using Spring Boot?
Ans: You can "build a production ready application from scratch in a matter of minuts" Spring boot is a Spring Module which
provide RAD(Rapid Application Deployment) feature to Spring framework.

Q2 Which annotation used in SpringBoot?
Ans: 
     @ Bean:Indicates that a method produces a bean to managed by Spring.
     @ Service :Indicates that an annotatited class is serives class.
     @ Repository :indicates tha an annotated class is repository,Which is abstraction of  data acess and storage.
     @ Configuration -Indicates that a class is configuration class that may contain bean definitions.
     @ Controller : marks the class as web controller,capable of handling the request.
     @ RequestMapping :  Maps HTTP request with a path to controller method.
     @ Autowited :Marks a constructor ,field or setter method to autowited by Spring dependency injection.
     @SpringBootapplicaiton :Enable Spring Boot autoconfiguration and components scanning

Q3. Differance between CommandlineRunner and ApplicaitonRunner in Spring Boot?
Ans: Both are similar in terms of functionality and the deiiferance is that If you need access to ApplicaitonArguments instead of
the row String array conside using ApplicaitonRunner then CommandLineRunner.

Q4. How to used @SpringBootApplication in SpringBoot application?
Ans: @SpringBootApplication annotation is equivalant to using @Configuration,@EnableAtoConfiguratin and @ComponentScan with their
default attributs:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootWebApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootWebApplication.class, args);
    }
}

Bellow paramaters are accepted in the @SpringBootApplication
scanBasePackage -Provide the list of packages that has to be applied for the @ComponentScan.This Paramater added since Spring boot 1.3
scanBasePackageClasses:Provide the list of classess that has to be applicaed for @ComponentScan

exclude :Exclude the list of classes from the auto Configuration. 

JSON Interview Question

Q1. Who is founder of JSON?
Ans: The Founder of the JSON is Douuglas Crockfrord.

Q2. What is JSON Syntax ?
Exp: The JSON Syntaxt is a set of the JavaScript Object and you must follow rules for that when you will create JSON.
- The curly brackets hold objects.
- A data is in name and value paires
- The square bracket holds arrays
- A data is separated by comma
- Json is text base

Q3. Why JSON is popular?
Ans: Becuase the JSON is light weith stander for exchanges infomraiotn:
   - JSON is independent of language
   - It is easy for reading and writing for humans and machine.
   - It is easy for Encoding and Decode.
   - It is mostly used in Mobile application.
   - Most of browse is support like as IE8,Opera 10,Crome and Firefox

Q4. What type of data Supported by JSON?
Ans: Bellow the Data type support by JSON inclide.
  - Array
  - Number
  - Null
  - String
  - Object and
  - Boolean
Q5. What is difference in JSON and JSONP?
Ans:
  - JSON: The json is sample data format used for the communication mudium between other System and
  - JSONP :Yhe JSONP is methodology for using that foramt with cross domain Ajax request while not being affected by same origin policy issue.

Q.6 Sample example on JSON in java ?
Ans:
Step 1: Added bellow entery into you pom.xml file
     >dependency<
        >groupId<com.googlecode.json-simple>/groupId<
        >artifactId<json-simple>/artifactId<
        >version<1.1.1>/version<
     >/dependency<

Step 2:Write the Sampel java Example
SampleJSON.java
    import org.json.simple.JSONArray;
    import org.json.simple.JSONObject;
    import java.io.FileWriter;
    import java.io.IOException;

public class SampleJSON {
     public static void main(String[] args) {
        JSONObject obj = new JSONObject();
        obj.put("name", "java-webWorld.blogspot.in");
        obj.put("age", new Integer(30);
        JSONArray list = new JSONArray();
        list.add("Strong 1");
        list.add("Good 2");
        list.add("Bad 3");
         obj.put("Messages", list);
         try (FileWriter file = new FileWriter("C:\\Sampletest.json")) {
             file.write(obj.toJSONString());file.flush();
         } catch (IOException e) { e.printStackTrace();}
         System.out.print(obj);
     }
}
Step 3:When you will Execute above this java class ,you will get bellow result
 C:\\Sampletest.json
{
                "age":30,
                "name":"java-webWorld.blogspot.in",
                "messages":["Strong 1","Good 2","Bad 3"]

}