Thursday, 5 September 2024

What is the purpose of @SpringBootApplication annotation?

                                         JAVA with Silan Software

@SpringBootApplication annotation represent that the corresponding application is a spring boot application. It is working for three annotations like @Configuration, @EnableAutoConfiguration, and @ComponentScan.

@Configuration : It is a class level annotation indicating that an object is a source of bean definitions. @Configuration classes declare beans through @Bean annotated method.

@EnableAutoConfiguration : It enables to spring boot to auto-configure the application context. So it automatically creates and registers beans based on both the included jar files in the class path and the beans defined by us.

@ComponentScan : It is used for auto detecting and registering spring managed components like beans, controllers, repository, services etc.

Java Spring Boot First Example in Spring Tool Suite(STS)

 

JAVA with Silan Software

First Spring Boot Application in STS

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

         <modelVersion>4.0.0</modelVersion>

         <parent>

                  <groupId>org.springframework.boot</groupId>

                  <artifactId>spring-boot-starter-parent</artifactId>

                  <version>3.3.3</version>

                  <relativePath/> <!-- lookup parent from repository -->

         </parent>

         <groupId>com.iter</groupId>

         <artifactId>SpringBootFirstExample</artifactId>

         <version>0.0.1-SNAPSHOT</version>

         <name>SpringBootFirstExample</name>

         <description>My First Spring Boot Example</description>

         <url/>

         <licenses>

                  <license/>

         </licenses>

         <developers>

                  <developer/>

         </developers>

         <scm>

                  <connection/>

                  <developerConnection/>

                  <tag/>

                  <url/>

         </scm>

         <properties>

                  <java.version>17</java.version>

         </properties>

         <dependencies>

                  <dependency>

                           <groupId>org.springframework.boot</groupId>

                           <artifactId>spring-boot-starter-web</artifactId>

                  </dependency>

 

                  <dependency>

                           <groupId>org.springframework.boot</groupId>

                           <artifactId>spring-boot-devtools</artifactId>

                           <scope>runtime</scope>

                           <optional>true</optional>

                  </dependency>

                  <dependency>

                           <groupId>org.springframework.boot</groupId>

                           <artifactId>spring-boot-starter-test</artifactId>

                           <scope>test</scope>

                  </dependency>

         </dependencies>

 

         <build>

                  <plugins>

                           <plugin>

                                    <groupId>org.springframework.boot</groupId>

                                    <artifactId>spring-boot-maven-plugin</artifactId>

                           </plugin>

                  </plugins>

         </build>

 

</project>

 

TestController.java

package com.soa.controller;

 

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

 

@RestController

public class TestController {

        

         @GetMapping("/hello")

         public String display()

         {

                  return "Welcome to Java Spring Boot";

         }

        

 

}

 

 




Thursday, 9 March 2023

JAVA program to find the reverse of a string value and check whether the given string is palindrome or not !

 //JAVA program to find the reverse of a string value and check whether the given string is palindrome or not

import java.util.*;

class ReverseString

{

public static void main(String[] args)

{

String str,rev="";

int l;


Scanner s=new Scanner(System.in);

System.out.println("enter the string value:");

str=s.nextLine();


l=str.length();

for(int i=l-1;i>=0;i--)

{

rev=rev+str.charAt(i);

}


System.out.println("The reverse is:"+rev);


if(str.equals(rev))

{

System.out.println("palindrome");

}

else

{

System.out.println("not palindrome");

}

}

}

Output : 






Wednesday, 10 August 2022

JAVA 8 Interview Question-2022 : What is Optional and why it is used ?

 Optional in JAVA 8:

Optional is a built in class present in java.util package also called as container class specifically used to represent optional values that exist or do not exist.

The main advantage is to avoid null. Here there is no NullPointerException will arise at the run time in the form of result.


Note: For getting JAVA, Python, Machine Learning, Deep Learning tutorial in detail, follow:

www.pythontpoints.com


                               -----------------------------Thank You----------------------------



Regards:

Trilochan Tarai  | Associate Manager, Delivery, Majesco India 

+91-9439202111

JAVA Interview Questions-2022 : JAVA 8 new Features !

 JAVA 8 newly Features:

1. Lambda Expression

2. Functional Interface

3. Method References

4. Stream API

5. Date Time API

6. Method References

7. Optional class present in java.util package

8. Nashorn : Highly improved JavaScript engine which enables the execution of JavaScript in JAVA.


                             -------------Thank You----------------- 


Regards:

Trilochan Tarai | Associate Manager, Delivery, Majesco India

+91-9439202111

Friday, 22 July 2022

What is @RequestMapping Annotation in JAVA Spring? : JAVA Interview Question-2022

 @RequestMapping Annotation:

This is one of the basic annotations in Spring that maps HTTP requests with methods. This is used to map the request into the specific method in Spring.

The method is run every time an end-user makes an HTTP request. The mapping can also be done at the method or class level.

@RequestMapping("/hello")

public class HelloController() 

{

        @RequestMapping("/helloworld")

        public String show() 

        {

        return "JAVA means Silan Software";

        }

        @RequestMapping("/helloall")

        public String display() 

        {

        return "javabytrilochan";

        }

}


From here, the 
/hello is assigned on the class level. And each method has separate mappings and this allows to have a prefix before creating the mapping.


Regards:

Trilochan Tarai

Associate Manager-Senior Lead Engineer,

Majesco India

+91-9439202111




Thursday, 21 July 2022

What is the difference between HashMap and Hashtable in JAVA ? : Mphasis JAVA Interview Question-2022

 

HashMap  vs.  Hashtable:

Both HashMap and Hashtable are two implementation class of Map interface which contains pair. In a pair, one is key and one is value.

There are many differences between HashMap and Hashtable.

                HashMap

 Introduced in 1.2 version

HashMap is not synchronized, that means it is not in thread safe.

HashMap allows one null key and multiple null values.

HashMap is faster.

We can traverse HashMap by Iterator.

                 Hashtable

Introduced in 1.0 version, that’s why it is called as legacy.

Hashtable is synchronized, that means it is thread safe.

Hashtable not allowed any null key or value.

Hashtable is slow.

We can traverse Hashtable by Enumerator and Iterator.



Our Services:
JAVA Training  ||  JAVA Projects  ||  JAVA Internship  || JAVA Placements || Python Training  || AI & Machine Learning with Python Training  || Data Science Training
Call to : 0674-2361252