Advance Java Practical
Advance Java Practical
CERTIFICATE
INDEX
1 Implementation of bounded
types with generics.
3 Implementation of Web
Applications.
4 Implementation of Spring
Framework.
5 Implementation Of AOP.
6 Implementation Of JDBC.
Q1) Create a class shape with method Area() create circle and Square
that extends shape. And implement the generics and use area function
accordingly:
CODE:
package something;
import java.util.*;
int r = sc.nextInt();
public void Area()
{
System.out.println("AREA OF CIRCLE: "+3.14*r*r);
int s = sc.nextInt();
public void Area()
{
System.out.println("AREA OF SQUARE: "+s*s);
}
}
}
OUTPUT:
Practical 1
Q2) Create a Interface shape with method Area() create Circle and
CODE:
package something;
import java.util.*;
interface A
{
Scanner sc = new Scanner(System.in);
public void Area();
}
int r = sc.nextInt();
public void Area()
{
System.out.println("AREA OF CIRCLE: "+3.14*r*r);
int s = sc.nextInt();
public void Area()
{
System.out.println("AREA OF SQUARE: "+s*s);
}
}
class triangle
{
public void Area()
{
System.out.println("TRIANGLE");
}
}
}
}
OUTPUT:
Practical 2
package something;
import java.util.*;
class BoundedShape
{
static Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++)
{
int inp = sc.nextInt();
nums.add(inp);
}
Iterator<Integer> it = nums.iterator();
System.out.println("ARRAY IS\n");
while(it.hasNext()) {
System.out.println(it.next());
}
System.out.println(' ');
}
public static void main(String args[])
{
System.out.println(' ');
al();
}
}
OUTPUT:
b. Create a LinkedList of type String add 5 elements and
traverse the list and from both sides
CODE:
package something;
import java.util.*;
class BoundedShape
{
static Scanner sc = new Scanner(System.in);
static void ll()
{
n=sc.nextInt();
for(int i=0;i<n;i++)
{
String inp = sc.next();
li.add(inp);
}
System.out.println("LINK LIST IS\n");
for(String i:li)
{
System.out.println(i);
}
System.out.println(' ');
}
OUTPUT:
package something;
import java.util.*;
class employee {
System.out.print("ID : ");
int id1=sc.nextInt();
System.out.print("NAME : ");String
name1=sc.next();
System.out.print("SALARY : ");Double
salary1=sc.nextDouble();
OUTPUT:
a. Write a Java program using Set interface containing list of items and
perform the following operations: a. Add items in the set. b. Insert
items of one set in to other set. c. Remove items from the set d. Search
thespecified item in the set.
CODE:
package something;
import java.util.*;
System.out.println("\n");
System.out.println("\n");
OUTPUT:
a. Create a class Customer(Account_no Integer, NameSting), Create a
HashMap of type Customer put elements, print elements, check if
element with account number 101 is present or not? What is the value
for Customer 101.
CODE:
package something;
import java.util.*;
}}}
OUTPUT:
a. Write a Java program using Lambda Expression tocalculate the following:
a. Convert Fahrenheit to Celsius b. Convert Kilometers to Miles.
1) Fahrenheit to celcius
CODE:
package something;
interface ftoc
{
public int convert(int c);
}
OUTPUT:
2) Kilometers to miles:
CODE:
package something;
interface ktom
{
public double travel(double c);
}
OUTPUT:
Practical 3
Q1) To design a form and use of JSP Scripting Element and JSP
Directive. Display Grade of a student by accepting marks in five
subjects.
CODE:
a) index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="find.jsp" method="POST">
<h1>Enter Your Name:</h1><input type="text"
name="name"><br>
<h1>Enter Your Marks:</h1><br>
<h2> MFCS: </h2><input type="text"
name="mfcs"><br>
<h2> AJAVA: </h2><input type="text"
name="java"><br>
<h2> ADBMS: </h2><input type="text"
name="dbms"><br>
<h2> SPM: </h2><input type="text"
name="spm"><br>
<h2> WTL: </h2><input type="text"
name="wtl"><br>
<br><br>
<input type="submit" value="SUBMIT"/>
</form>
</body>
</html>
b) grade.jsp
<h1>YOUR GRADE</h1>
<%
String name=request.getParameter("name");
int mfcs = Integer.parseInt(request.getParameter("mfcs"));
int adbms = Integer.parseInt(request.getParameter("dbms"));
int spm = Integer.parseInt(request.getParameter("spm"));
int java = Integer.parseInt(request.getParameter("java"));
int wtl = Integer.parseInt(request.getParameter("wtl"));
int percent; percent=(mfcs+adbms+spm+java+wtl)/5;
%>
<h1><%out.println("Name: "+name);%></h1>
<h2>YOUR GRADE IS: </h2>
<%
if(percent<40){
%>
<h1>F</h1>
<%}
else if(percent>=40&&percent<50){
%>
<h1>D</h1>
<% }
else if(percent>=50 && percent<60){
%>
<h1>B</h1>
<%}
else if(percent>=60 && percent<70){
%>
<h1>A</h1>
<% }
else if(percent>=70 && percent<80){
%>
<h1>A+</h1>
<% }
else{
%>
<h1>O</h1>
<%}
%>
</body>
</html>
OUTPUT:
Rohan Salve
Rohan Salve
Q2) Write a program to design a simple web-based interface to a
currency converter application. The interface should consist of a title,
suitable instructions, and a form for entering the amount to be
converted and an optional currency rate. Use text fields for entering
the amount and rate.
CODE:
a) index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>CURRENCY CONVERTER</title>
</head>
<body>
<form method="post" action="lol.jsp">
<h3>Enter the Value:</h3>
<input type="text" name="va" /><br>
<h3>Enter the rate of currency you want to convert
into</h3>
<input type="text" name="re"/><br><br>
<input type="submit" value="CONVERT" /> <br>
</form>
</body>
</html>
b) conv.jsp
%>
</body>
</html>
OUTPUT:
Q3) Design loan calculator using JSP which accepts Period of Time (in
years) and Principal Loan Amount. Display the payment amount for
each loan and then list the loan balance and interest paid for each
payment over the term of the loan for the following time period and
interest rate:
a. 1 to 7 year at 5.35%
b. 8 to 15 year at 5.5%
c. 16 to 30 year at 5.75%
CODE:
a) index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Loan Calculator</title>
</head>
<body>
<form action = "new.jsp">
<h3>Enter Principle Loan Amount</h3><input type="text"name='pri'/><br>
<h3>Enter Time Period (IN YEARS)</h3><input type="text"name='ti'/><br><br>
b) cal.jsp
OUTPUT:
Q4) Write a program using JSP that displays a webpage consisting of
Application form for change of Study Center which can be filled by any
student who wants to change his/ her study center. Make necessary
assumptions:
CODE:
a) index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action = "change.jsp">
<h2>Enter Your Name:</h2>
<input type="text" name ='name'/><br>
<br>
<h2>Enter Your Roll Number:</h2>
<input type="text" name ='roll'/><br>
<br>
b) change.jsp
OUTPUT:
Rohan Salve
Rohan Salve
Practical 4
Q1) Write a program to print “Hello World” using spring framework:
CODE:
a) Hello.java
package hi;
b) Test.java
package hi;
import org.springframework.beans.factory.BeanFactory;import
org.springframework.beans.factory.xml.*; import
org.springframework.core.io.ClassPathResource;import
org.springframework.core.io.Resource;
hello world=(hello)factory.getBean("disp1");world.dis();
}
}
c) Hi.xml
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/sc hema/beans
http://www.springframework.org/schema/beans/spring- beans-3.0.xsd">
</beans>
OUTPUT:
Q2) Write a program to demonstrate dependency injection via settermethod.
CODE:
a) Data.java
package sat;
{
return roll_no;
}
b)Main.java
package sat;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.*;
@SuppressWarnings("deprecation")
dat e=(dat)factory.getBean("obj");
e.dis();
}
a) Data.xml
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/sc hema/beans
http://www.springframework.org/schema/beans/spring- beans-3.0.xsd">
<property name="name">
<value>Tony Stark</value>
</property>
<property name="roll_no">
<value>27</value>
</property>
<property name="addr">
<value>California</value>
</property>
</bean>
</beans>
OUTPUT:
Q3) Write a program to demonstrate dependency injection viaConstructor.
CODE:
a) Data.java
package cons;
b) Main.java
package cons;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.beans.factory.BeanFactory;
c) Data.xml
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/sc hema/beans
http://www.springframework.org/schema/beans/spring- beans-3.0.xsd">
<bean id="obj" class = "cons.dat">
<constructor-arg value="Atharva Kale" ></constructor-arg>
<constructor-arg value="Kalyan" ></constructor-arg>
<constructor-arg value="27" type="int"></constructor-arg>
</bean>
</beans>
OUTPUT:
Practical 5
Q1) Create class car, bike, airplane, create an aspect engine, create
method drive() in car, ride() in bike, fly in airplane, the engine aspect
has method enginestart() and enginestop(). When you run the
application the enginestart() method should execute before drive(),
ride() and fly() a enginestop() method should run after drive(), ride()
and fly().
CODE:
a. car.java
package some.pro1;
import org.springframework.stereotype.Component;@Component
public class car {
public void drive()
{
System.out.println("CAR STARTED DRIVING");
}
b. bike.java
package some.pro1;
import org.springframework.stereotype.Component;@Component
public class bike {
public void ride()
{
System.out.println("Biker riding bike");
}
}
c. airplane.java
package some.pro1;
import org.springframework.stereotype.Component;@Component
public class airplane {
public void fly()
{
System.out.println("Airplane flying");
}
}
d. engine.java
package some.pro1;
import org.aspectj.lang.annotation.After; import
org.aspectj.lang.annotation.Before;import
org.aspectj.lang.annotation.Aspect;import
org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Component
@Aspect
@EnableAspectJAutoProxy
drive())")
public void enginestart()
{
System.out.println("Enigine started");
}
e. app.java
package some.pro1;
import
org.springframework.context.annotation.AnnotationConfigApplicationCo ntext;
import org.springframework.context.support.AbstractApplicationContext;
{
public static void main( String[] args )
{
AbstractApplicationContext context = new
AnnotationConfigApplicationContext(AppConfig.class);
car c = context.getBean("car",car.class);
c.drive();
bike b = context.getBean("bike",bike.class);
b.ride();
airplane a = context.getBean("airplane",airplane.class);
a.fly();
}
}
OUTPUT:
Q2) Create class car, bike, airplane, create an aspect engine, create method
drive() in car, ride() in bike, fly in airplane, the engine aspecthas method
enginestart() and enginestop(). When you run the application the
enginestart() method should execute before drive(), ride() and fly() a
enginestop() method should run after drive(), ride()and fly() by using
pointcuts.
CODE:
a. car.java
package something.pro2;
import org.springframework.stereotype.Component;@Component
public class car {
b. bike.java
package something.pro2;
import org.springframework.stereotype.Component;@Component
c. airplane.java
package something.pro2;
import org.springframework.stereotype.Component;@Component
d. engine.java
package something.pro2;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Before; import
org.aspectj.lang.annotation.Pointcut;import
org.aspectj.lang.annotation.Aspect; import
org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Component
@Aspect
@EnableAspectJAutoProxy
@Before("getNamePointcut()")
public void enginestart()
{
System.out.println("Engine started");
}
@Pointcut("execution(public void drive())")public void
getNamePointcut(){} @After("getNamePointcut1()")
e. app.java
package something.pro2;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext; import
AnnotationConfigApplicationContext(AppConfig.class);
car c = context.getBean("car",car.class);
c.drive();
bike b = context.getBean("bike",bike.class);
b.ride();
airplane a = context.getBean("airplane",airplane.class);
a.fly();
OUTPUT:
CODE:
a. multiplier.java
package something.pro3;
import org.springframework.stereotype.Component;
@Component
b. AdderAfterReturnAspect.java
package something.pro3;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Before; import
org.aspectj.lang.annotation.Aspect;import
org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Component
@Aspect
@EnableAspectJAutoProxy
c. App.java
package something.pro3;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
AnnotationConfigApplicationContext(AppConfig.class);
multiplier m=context.getBean("multiplier",multiplier.class);
m.mul(5, 5);
}
}
OUTPUT:
Q4) Create a voter class with attribute name and age create an exception check
if age is less than 18 throw exception. Create and aspect illegalVoter with a
method if the voter class throws exceptionthe illegalVoter aspect method
will run
CODE:
a. voter.java
package something.pro4;
import org.springframework.stereotype.Component;@Component
if(age<18)
{
throw new Exception(name+" you are under age!");
}
else
{
System.out.println("Do vote "+name+" as your age is"+age);
}
}
}
b. illegalvoter.java
package something.pro4;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;
@Component
@Aspect
@EnableAspectJAutoProxy
package something.pro4;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
OUTPUT:
Practical 6
CODE:
a. employee.java
package something.datapro1;
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
b. EmployeeDao.java
package something.datapro1;
import org.springframework.jdbc.core.JdbcTemplate;
c. App.java
package something.datapro1;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContex
t;
public class App
ApplicationContext ctx=new
ClassPathXmlApplicationContext("dbd.xml");
EmployeeDao dao=(EmployeeDao)ctx.getBean("edao");
dao.saveEmployee(new employee(1,"Atharva",21));
dao.saveEmployee(new employee(2,"Tony",48));
dao.saveEmployee(new employee(3,"Jarvis",50));
System.out.print("DATA INSERTED");
dao.updateEmployee(new employee(1,"Atharva",20));
System.out.print("DATA UPDATED");
System.out.print("DATA DELETED");
e.setId(3);
dao.deleteEmployee(e);
d. dbd.xml
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value =
"com.mysql.jdbc.Driver" />
<property name="url" value =
"jdbc:mysql://localhost:3306/java" />
<property name="username" value = "COOLBOy" />
<property name="password" value = "hailhydra" />
</bean>
<bean id = "jdbcTemplate" class = "org.springframework.jdbc.core.JdbcTemplate">
<property name = "dataSource" ref = "dataSource" />
</bean>
</beans>
OUTPUT:
Data inserted
Data updated
Data deleted
a. employee.java
package something.datapro2;
}
b. employeetemp.java
package something.datapro2;
import java.sql.PreparedStatement;
import java.sql.SQLException; import
java.util.ArrayList;
import java.util.List; import
java.sql.ResultSet; import
javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate; import
org.springframework.dao.DataAccessException; import
org.springframework.jdbc.core.ResultSetExtractor;import
org.springframework.jdbc.core.PreparedStatementCallback;public class
employeetemp implements EmployeeDao { private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
public Boolean insertPreparedStatmentEmployee(final employeee){
String query="insert into employee_27 (id,name, age) values(?,?,?)";
return jdbcTemplateObject.execute(query,new
PreparedStatementCallback<Boolean>(){
public Boolean doInPreparedStatement(PreparedStatement ps)
throws SQLException, DataAccessException {
ps.setInt(1,e.getId());
ps.setString(2,e.getName()); ps.setInt(3,e.getAge());
System.out.println("Records Inserted Using Prepared Statment");
return ps.execute();
}
});
}
@Override
public void insert(Integer id,String name, Integer age) {
// TODO Auto-generated method stub
}
@Override
public void update(Integer id, String name, Integer age) {
// TODO Auto-generated method stub
}
@Override
public void delete(Integer id) {
// TODO Auto-generated method stub
}}
c. EmployeeDao.java
package something.datapro2;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
d. App.java
package something.datapro2;
import java.util.List;
e. dbd.xml
OUTPUT:
Q3) Write a program in Spring JDBC to demonstrate
ResultSetExtractor Interface.
CODE:
a. employeetemp.java:
package something.datapro3;
import java.sql.PreparedStatement;
import java.sql.SQLException; import
java.util.ArrayList;
import java.util.List; import
java.sql.ResultSet; import
javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate; import
org.springframework.dao.DataAccessException; import
org.springframework.jdbc.core.ResultSetExtractor;import
org.springframework.jdbc.core.PreparedStatementCallback;public class
employeetemp implements EmployeeDao {
private DataSource dataSource;
private JdbcTemplate jdbcTemplateObject;
public String name;
public Integer age;
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplateObject = new JdbcTemplate(dataSource);
}
public List<employee> listEmployeeWithResultSet() {String SQL =
"select * from employee_27";
List <employee> employees = jdbcTemplateObject.query(SQL,
new EmployeeResultsetExtractor());
return employees;
}
@Override
public void insert(Integer id, String name, Integer age) {
// TODO Auto-generated method stub
}
@Override
public void update(Integer id, String name, Integer age) {
// TODO Auto-generated method stub
}
@Override
public void delete(Integer id) {
// TODO Auto-generated method stub
}
}
b. EmployeeDao.ja
va: package
something.datapro3;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
c. App.java:
package something.datapro3;
import java.util.List;
import org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContex
t;
{
public static void main( String[] args )
employeetemp et =
(employeetemp)context.getBean("employeejdbctemp");
}}}
d. employee.java
package something.datapro3;
e. EmployeeResultsetExtractor.java:
package something.datapro3;
import java.util.ArrayList;import
java.util.List; import
java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.dao.DataAccessException; import
org.springframework.jdbc.core.ResultSetExtractor;import
something.datapro3.employee;
public class EmployeeResultsetExtractor implements
ResultSetExtractor<List<employee>> {
public List<employee> extractData(ResultSet rs) throws
SQLException,
DataAccessException {
List<employee> employeeList = new ArrayList<employee>();
System.out.print("Result Extractor Called"); while(rs.next()) {
employee emp = new employee(); emp.setId(rs.getInt("id"));
emp.setName(rs.getString("name"));
emp.setAge(rs.getInt("age")); employeeList.add(emp);
}
return employeeList;
}
}
OUTPUT:
CODE:
a. App.java:
package something.datapro4;
import java.util.List;
import org.springframework.context.ApplicationContext; import
org.springframework.context.support.ClassPathXmlApplicationContext;
}
}
b. Employeetemp.java:
package something.datapro4;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.sql.ResultSet;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.PreparedStatementCallback;
EmployeeRowMaper());
return employees;
c. EmployeeRowMaper.java:
package something.datapro4;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
public class EmployeeRowMaper implements RowMapper<employee>
{
public employee mapRow(ResultSet rs, int rowNum) throws
SQLException {
System.out.println("Row mapper called");employee
employee = new employee();
employee.setId(rs.getInt("id"));
employee.setName(rs.getString("name"));
employee.setAge(rs.getInt("age")); return employee;
}
}
d. EmployeeDao.java:
package something.datapro4;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
OUTPUT:
Practical 7
CODE:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>anything</groupId>
<artifactId>spriboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spriboot</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF- 8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven
defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see
https://maven.apache.org/ref/current/maven-
core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-
bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven- plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-
core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports- plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
b. App.java
package anything.spriboot;
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration public
class App
{
@RequestMapping("/") String
home() {
return "Hello World Spring Boot!";
}
public static void main( String[] args )
throws Exception { SpringApplication.run(App.class, args);
}
}
OUTPUT: