preloader

Springboot is extend part of spring framework along with embedded server.it is standalone application

SpringBoot

  • COURSES

    02 Month

  • DURATION

    01 Hours

Difference between Spring vs SpringBoot

Spring SpringBoot
Spring is good for j2ee/JDBC application. SpringBoot is good for restful web services.
Dependency injection is an important part Springboot Autoconfiguration is important aspect
Spring is structure based framework Springboot is annotation based framework
Spring is loosely coupled application SpringBoot is stand alone application
Spring use boilerplate code to make application loosely coupled SpringBoot does not use boilerplate code
Spring boot is xml based application where property must be defined under pom.xml SpringBoot is starter based application where starter itself take care for configuration
Embadded server such as tomcat ,jetty must be defined explicitly SpringBoot already included with tomcat embedded server no need to define explicitly

Difference btw @RestController and @Controller

@RestController @Controller
It is combination of controller and response body do not need to define explicitly Controller convert data to human readable format, Response body need to defined explicitly
Convert data to json and xml both Convert data to xml format only

Define @RequestMapping in springboot application

It is a generic annotation using with class and method in order to map the data to the controller
When used with class it must include URL of API ,but when used with method of rest API
it must include Request method along with it.

Difference between @RequestMapping vs @GetMapping

@RequestMapping @GetMapping
RequestMapping is generic annotation, which is used map the web request. @Getmapping is class level annotation with specific to get call.
Along with RequestMapping we need to define request method @GetMapping do not need request method separately.

what are different interface of SpringBoot?

Four interface of Springboot are:
  • Springboot starter
  • Springboot CLI
  • Springboot Actuator
  • Springboot Autoconfiguration

Define @SpringbootApplication annotation

This annotation is combination of three annotation @EnableAutoConfiguration, @componentScan and @configuration ,it is used by spring boot in main class of application.

✓ @EnableAutoConfiguration: – it auto configures the class according to starter, create the bean and register it to the jar

✓ @componentScan: - Scan the package for us configure component, service and repository

✓ @configuration: – Handel basic configuration to maintain the code flow

Define @Require annotation

This annotation is used to detect property which must be checked by JVM at the time of compilation.

How to change the port no from 8080 to 8032 in SpringBoot?

For changing the port no in Springboot we can change it application.
properties file present in resources folder by server. port = 8032

How to change default embedded server to other server?

Springboot support three embedded servers i.e.

  • Apache Tomcat
  • Jetty
  • Underflow

Apache Tomcat is default server that comes along with Springboot. For changing it to tomcat to jetty

  • Exclude the property of starter-tomcat.
  • Include the property of starter-jetty.

How to connect SQL in Springboot?

  • Create database in MySQL.
  • Open the SpringBoot project.
  • Add SpringBoot Web, JDBC, MySQL connector dependencies under pom.xml.
  • Configure db properties under application.Properties.
  • Run application as java application/springboot application
spring.datasource.url= jdbc:mysql://localhost:3306/medicomart
        spring.datasource.username=root
        spring.datasource.password=admin
        spring.jpa.generate-ddl=true

What are different Stereotype annotation?

  • @Entity: Used to define basic entity, also entity class.
  • @Component: Generic annotation type which used for define common class level
  • @Service: Service class is defined where all service method is called
  • @Repository: define repository which implements JPA repository.

Difference between Intermediate and Terminal

Intermediate Terminal
Intermediate operations return a stream Terminal operations return non-stream values
like primitive or object or collection
Chained together to form a pipeline of operations Terminal operations can not be chained together
Lezy by nature Execute as soon as created
They don’t produce end result. They produce end result.
  • map()
  • filter()
  • distinct()
  • sorted()
  • limit()
  • skip()
  • forEach()
  • toArray()
  • reduce()
  • collect()
  • min()
  • max()
  • count()
  • anyMatch()
  • allMatch()
  • noneMatch()
  • findFirst()
  • findAny()

Difference between map vs Flatmap

Map Flatmap
processes stream of values. processes stream of stream of values.
It does only mapping. It performs mapping as well as flattening.
It’s mapper function produces
single value for each input value.
It’s mapper function produces
multiple values for each input value.
It is a One-To-One mapping. It is a One-To-Many mapping
Data Transformation : From Stream to Stream Data Transformation : From Stream of Stream
to Stream
List<String> namesOfInstitutes
            = instituteList.stream().map(Institute::
            getName).collect(Collectors.toList());
Set<String> locationsOfInstitutes
                = instituteList.stream()
                .flatMap(institute -> institute.getLocations().stream()).
                collect(Collectors.toSet());

Difference between Collection and Steam

Collection Stream
Part of JDK 1.2 Part of JDK 1.8
Used to store different type of object in a single entity. Streams are mainly used to perform operations on data.
used for finite value of data. used for infinite value of data.
add or remove elements from collections can’t add or remove elements from streams
Collections can be traversed multiple times Streams are traversable only once.
Collections are eagerly constructed. Streams are lazily constructed.
Example :-List, Set, Map Example : –filtering, mapping

Difference between Iterator vs Splitor

Iterator Splitor
iterator is part of JDK 1.2 splitor is part of JDK1.8
iterator part of collection Api Splitor is part of steam Api
Only Sequential order Both Parallel and Sequential order
it is pure Iterator it is unpure Iterator

StringJoiner in Java8

Joining the strings or concatenating the strings is the frequent
operation while programming any kind of applications.

  • java.util.StringJoiner class
  • String.join() method
  • Collectors.joining() method
StringJoiner Example : Joining the strings with delimiter
import java.util.StringJoiner;
 
            public class Java8StringJoiner 
            {
                public static void main(String[] args) 
                {
                    StringJoiner stringJoiner = new StringJoiner(" | ");
                     
                    stringJoiner.add("Facebook");
                     
                    stringJoiner.add("Twitter");
                     
                    stringJoiner.add("YouTube");
                     
                    stringJoiner.add("WhatsApp");
                     
                    stringJoiner.add("LinkedIn");
                     
                    System.out.println(stringJoiner);
                }
            }
            Output :
            
            Facebook | Twitter | YouTube | WhatsApp | LinkedIn
StringJoiner Example : Joining the strings with delimiter, prefix and suffix
import java.util.StringJoiner;
 
                public class Java8StringJoiner 
                {
                    public static void main(String[] args) 
                    {
                        StringJoiner stringJoiner = new StringJoiner(", ", "[", "]");
                         
                        stringJoiner.add("Facebook");
                         
                        stringJoiner.add("Twitter");
                         
                        stringJoiner.add("YouTube");
                         
                        stringJoiner.add("WhatsApp");
                         
                        stringJoiner.add("LinkedIn");
                         
                        System.out.println(stringJoiner);
                    }
                }
                
                Output :
                
                [Facebook, Twitter, YouTube, WhatsApp, LinkedIn]
String.join() Method Example : Joining the strings
public class Java8StringJoinMethod 
                    {
                        public static void main(String[] args) 
                        {
                            String joinedString = String.join(" | ", "Facebook", "Twitter", "YouTube", "WhatsApp", "LinkedIn");
                             
                            System.out.println(joinedString);
                        }
                    }
                    
                    Output :
                    
                    Facebook | Twitter | YouTube | WhatsApp | LinkedIn
String.join() Method Example : Joining an array of strings
public class Java8StringJoinMethod 
                        {
                            public static void main(String[] args) 
                            {
                                String[] strArray = new String[] {"Facebook", "Twitter", "YouTube", "WhatsApp", "LinkedIn"};
                                 
                                String joinedString = String.join(" | ", strArray);
                                 
                                System.out.println(joinedString);
                            }
                        }
                        
                        Output :
                        
                        Facebook | Twitter | YouTube | WhatsApp | LinkedIn
String.join() Method Example : Joining list of strings
import java.util.Arrays;
                            import java.util.List;
                             
                            public class Java8StringJoinMethod 
                            {
                                public static void main(String[] args) 
                                {
                                    List<String> listOfStrings = Arrays.asList("Facebook", "Twitter", "YouTube", "WhatsApp", "LinkedIn");
                                     
                                    String joinedString = String.join(" | ", listOfStrings);
                                     
                                    System.out.println(joinedString);
                                }
                            }
                            
                            output:
                            Facebook | Twitter | YouTube | WhatsApp | LinkedIn

What is Method Reference

Method reference used to refer to the method of functional interface.
It can be used to replace Lambda Expression while referring to a method.

Lembda Expression Equivalent Method Reference
(String s)->integer.parseInt integer::parseInt
(String s)->s.toLowerCase String::toLowerCase
(int i)->System.out.println(i) System.out::println
(Student s)->s.getName(); Student::getName
()->s.getName() s::getName
()->new Student() Student::name
import java.util.function.Function;

                public class Java8MethodReferences {
                    public static void main(String[] args) {
                        //Calling parseInt() method using lambda
                
                        Function < String, Integer > lambdaFunction = (String s) - > Integer.parseInt(s);
                        System.out.println(lambdaFunction.apply("12"));
                
                        //Calling parseInt() method using method reference
                
                        Function < String, Integer > referenceFunction = Integer::parseInt;
                        System.out.println(referenceFunction.apply("12"));
                    }
                }

Related Course

course thumb

Basic Java

All basic level question for java covered in this section

Visit
course thumb

OOP Concept

Inheritance,Polimorphism,Abstraction and Encapsulation

Visit
course thumb

Core Java

Core java, OOP concept, Multithreading, Collection and Exception Handling

Visit