package com.Aman;public class Q27_1 { static int maxConsecutiveOnes(int x){ int count = 0; while (x!=0) { x = (x & (x << 1)); count++; } return count; } public static void main(String[] args) { int x = 10000; System.out.println(maxConsecutiveOnes(x)); }}
Java Hyd Team
https://forms.gle/h4bqyzQtGqUk3LR6A FILL THIS FORM FOR TOMMORROWS MASTERCLASS TIMINGS 10AM-3PM WE WILL COVER EVERYTHING FROM SCRATCH TO ADVANCE LEVEL
Next week will be QUESTIONS and answer from basic to advanced level don't miss to be part of it
import java.util.Scanner;
public class SwapSmallestLargestElement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i, n;
System.out.println("Enter the size of array : ");
n = scanner.nextInt();
int arr[] = new int[n];
System.out.println("Enter the elements to be entered : ");
for(i=0;i<n;i++){
arr[i] = scanner.nextInt();
}
//Call a function Find maximum element of array
int maxElementPos = findMaxElement(arr,n);
System.out.println("The maximum element : "+ arr[maxElementPos]);
//Call a function Find minimum element of array
int minElementPos = findMinElement(arr,n);
System.out.println("The minimum element : "+ arr[minElementPos]);
//Call a function swap maximum and minimum element
swapMaxMinElement(arr, maxElementPos, minElementPos);
// Finally print array after swap
System.out.println("The array after swap is : ");
for(i=0;i<n;i++){
System.out.print(arr[i]+ " ");
}
}
//Find maximum element of array
public static int findMaxElement(int arr[],int n){
int i, pos=0;
int maxVal = arr[0];
for(i=0;i<n;i++){
if(arr[i]>maxVal){
maxVal = arr[i];
pos=i;
}
}
return pos;
}
//Find minimum element of array
public static int findMinElement(int arr[],int n){
int i, pos=0;
int minVal = arr[0];
for(i=0;i<n;i++){
if(arr[i] < minVal){
minVal = arr[i];
pos=i;
}
}
return pos;
}
//Swap maximum and minimum element
public static void swapMaxMinElement(int arr[], int maxElementPos, int minElementPos){
/*To swap max and min numbers, take a temporary variable, and follow the below step,
1) assign maximum number to temporary vaiable.
2) assign minimum number to maximum number.
3) asign temporary vaiable to minimum number*/
int temp;
temp = arr[maxElementPos];
arr[maxElementPos] = arr[minElementPos];
arr[minElementPos] = temp;
}
}
public class SwapSmallestLargestElement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i, n;
System.out.println("Enter the size of array : ");
n = scanner.nextInt();
int arr[] = new int[n];
System.out.println("Enter the elements to be entered : ");
for(i=0;i<n;i++){
arr[i] = scanner.nextInt();
}
//Call a function Find maximum element of array
int maxElementPos = findMaxElement(arr,n);
System.out.println("The maximum element : "+ arr[maxElementPos]);
//Call a function Find minimum element of array
int minElementPos = findMinElement(arr,n);
System.out.println("The minimum element : "+ arr[minElementPos]);
//Call a function swap maximum and minimum element
swapMaxMinElement(arr, maxElementPos, minElementPos);
// Finally print array after swap
System.out.println("The array after swap is : ");
for(i=0;i<n;i++){
System.out.print(arr[i]+ " ");
}
}
//Find maximum element of array
public static int findMaxElement(int arr[],int n){
int i, pos=0;
int maxVal = arr[0];
for(i=0;i<n;i++){
if(arr[i]>maxVal){
maxVal = arr[i];
pos=i;
}
}
return pos;
}
//Find minimum element of array
public static int findMinElement(int arr[],int n){
int i, pos=0;
int minVal = arr[0];
for(i=0;i<n;i++){
if(arr[i] < minVal){
minVal = arr[i];
pos=i;
}
}
return pos;
}
//Swap maximum and minimum element
public static void swapMaxMinElement(int arr[], int maxElementPos, int minElementPos){
/*To swap max and min numbers, take a temporary variable, and follow the below step,
1) assign maximum number to temporary vaiable.
2) assign minimum number to maximum number.
3) asign temporary vaiable to minimum number*/
int temp;
temp = arr[maxElementPos];
arr[maxElementPos] = arr[minElementPos];
arr[minElementPos] = temp;
}
}
import java.util.Scanner;
public class SwapSmallestLargestElement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i, n;
System.out.println("Enter the size of array : ");
n = scanner.nextInt();
int arr[] = new int[n];
System.out.println("Enter the elements to be entered : ");
for(i=0;i<n;i++){
arr[i] = scanner.nextInt();
}
//Call a function Find maximum element of array
int maxElementPos = findMaxElement(arr,n);
System.out.println("The maximum element : "+ arr[maxElementPos]);
//Call a function Find minimum element of array
int minElementPos = findMinElement(arr,n);
System.out.println("The minimum element : "+ arr[minElementPos]);
//Call a function swap maximum and minimum element
swapMaxMinElement(arr, maxElementPos, minElementPos);
// Finally print array after swap
System.out.println("The array after swap is : ");
for(i=0;i<n;i++){
System.out.print(arr[i]+ " ");
}
}
//Find maximum element of array
public static int findMaxElement(int arr[],int n){
int i, pos=0;
int maxVal = arr[0];
for(i=0;i<n;i++){
if(arr[i]>maxVal){
maxVal = arr[i];
pos=i;
}
}
return pos;
}
//Find minimum element of array
public static int findMinElement(int arr[],int n){
int i, pos=0;
int minVal = arr[0];
for(i=0;i<n;i++){
if(arr[i] < minVal){
minVal = arr[i];
pos=i;
}
}
return pos;
}
//Swap maximum and minimum element
public static void swapMaxMinElement(int arr[], int maxElementPos, int minElementPos){
/*To swap max and min numbers, take a temporary variable, and follow the below step,
1) assign maximum number to temporary vaiable.
2) assign minimum number to maximum number.
3) asign temporary vaiable to minimum number*/
int temp;
temp = arr[maxElementPos];
arr[maxElementPos] = arr[minElementPos];
arr[minElementPos] = temp;
}
}
public class SwapSmallestLargestElement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int i, n;
System.out.println("Enter the size of array : ");
n = scanner.nextInt();
int arr[] = new int[n];
System.out.println("Enter the elements to be entered : ");
for(i=0;i<n;i++){
arr[i] = scanner.nextInt();
}
//Call a function Find maximum element of array
int maxElementPos = findMaxElement(arr,n);
System.out.println("The maximum element : "+ arr[maxElementPos]);
//Call a function Find minimum element of array
int minElementPos = findMinElement(arr,n);
System.out.println("The minimum element : "+ arr[minElementPos]);
//Call a function swap maximum and minimum element
swapMaxMinElement(arr, maxElementPos, minElementPos);
// Finally print array after swap
System.out.println("The array after swap is : ");
for(i=0;i<n;i++){
System.out.print(arr[i]+ " ");
}
}
//Find maximum element of array
public static int findMaxElement(int arr[],int n){
int i, pos=0;
int maxVal = arr[0];
for(i=0;i<n;i++){
if(arr[i]>maxVal){
maxVal = arr[i];
pos=i;
}
}
return pos;
}
//Find minimum element of array
public static int findMinElement(int arr[],int n){
int i, pos=0;
int minVal = arr[0];
for(i=0;i<n;i++){
if(arr[i] < minVal){
minVal = arr[i];
pos=i;
}
}
return pos;
}
//Swap maximum and minimum element
public static void swapMaxMinElement(int arr[], int maxElementPos, int minElementPos){
/*To swap max and min numbers, take a temporary variable, and follow the below step,
1) assign maximum number to temporary vaiable.
2) assign minimum number to maximum number.
3) asign temporary vaiable to minimum number*/
int temp;
temp = arr[maxElementPos];
arr[maxElementPos] = arr[minElementPos];
arr[minElementPos] = temp;
}
}
Forwarded from SathyaReact
Convert same example to react single page applications
public class Main {
public static void main(String[] args) {
int a ;
a= 1;
while(a-->=1){
while(a-->=0){}
}System.out.println(a);
}
}
public static void main(String[] args) {
int a ;
a= 1;
while(a-->=1){
while(a-->=0){}
}System.out.println(a);
}
}
//****" Special type programs"
public class Main {
public static void main(String[] args) {
int a = 1;
for(a++;a++<=2;a++){
for(a++;a++<=7;a++){
a++;
}
}
System.out.println(a);
}
}
public class Main {
public static void main(String[] args) {
int a = 1;
for(a++;a++<=2;a++){
for(a++;a++<=7;a++){
a++;
}
}
System.out.println(a);
}
}
public class Main {
public static void main(String[] args) {
int i=1;
while (i<=20){
if (i>4&&i<17)
continue;
System.out.println (i);
i++;
}
}
}
O/p 1,2,3,4
public static void main(String[] args) {
int i=1;
while (i<=20){
if (i>4&&i<17)
continue;
System.out.println (i);
i++;
}
}
}
O/p 1,2,3,4
static char[] swap(String str, int i, int j) { char[] ch = str.toCharArray(); char temp = ch[i]; ch[i] = ch[j]; ch[j] = temp; return ch;}public static void main(String[] args) { String s = "aman";System.out.println(swap(s, 0, s.length() - 1)); System.out.println(s); }public class RemoveDuplicates { public static void main(String[] args) { String str = "sathya"; RemoveDuplicates obj = new RemoveDuplicates(); System.out.println(obj.removeDuplicates(str)); } public String removeDuplicates(String s) { char[] chars = s.toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < chars.length; i++) { String str = String.valueOf(chars[i]); if (!sb.toString().contains(str)) { sb.append(str); } } return sb.toString(); }}๐2
Q1.)what is framework in java?
A framework in Java is a collection of libraries(jar and war files), APIs, and other components that provide a structure for applications and enable developers to quickly build robust, scalable, and maintainable applications. Java frameworks provide a high-level abstraction layer so that developers can focus on the business logic and not the technical details. Popular Java frameworks include Spring, Hibernate, Struts, and AngularJS.
Q2.)what are the types of frameworks in java
Mainly frameworks are distributed in two types :-
1. Invasive framework
2. Non-Invasive framework
Q3.)difference between invasive and non invasive frameworks in java
Invasive frameworks are those which require developers to modify their existing code to fit the framework's standards in order to use it.
these framework force developer to use , extend or implement
Non-invasive frameworks are those which allow developers to use the framework without making any changes to their existing code. Non-invasive frameworks are typically more modern and easier to use.
these frameworks do not force developer to use , extend or implement
1. Model-View-Controller (MVC)
Model-View-Controller (MVC) is an architectural software design pattern that separates the logic of an application into three interconnected parts: model, view, and controller.
The model is responsible for maintaining data and business logic. It is the core of the application, and it stores and retrieves data.
The view is responsible for presenting the model data to the user. It is the user interface and can be implemented in multiple ways.
The controller is responsible for handling user inputs and updating the model accordingly. It is the bridge between the model and the view.
2. Spring Framework
Spring Framework is an open source application framework and inversion of control container for the Java platform. It provides a comprehensive programming and configuration model for modern Java-based enterprise applications. It was designed to simplify Java EE development and make developers more productive.
3. Struts Framework
The Apache Struts framework is an open-source framework for creating Java web applications. It uses and extends the Java Servlet API to encourage developers to adopt an MVC (Model-View-Controller) architecture. Struts provides a complete framework for creating robust, maintainable, and extensible web applications. It also provides support for internationalization and localization.
4. Hibernate Framework
Hibernate is an open source, object-relational mapping framework for Java. It is designed to provide a simple and efficient way to map Java objects to database tables, and to provide a simple query language for retrieving objects from the database. Hibernate also provides a powerful query language (HQL) for retrieving objects from the database. It is an object-relational mapping tool for the Java programming language. Hibernate is used to map Java classes to database tables and Java data types to SQL data types. It also provides data query and retrieval facilities, including a query language, criteria queries, and native SQL.
5. JavaServer Faces (JSF)
6. Google Web Toolkit (GWT)
7. Apache Wicket
Q4.)what is IOC and IOC lifecycle in spring
Inversion of Control (IoC) is an architectural pattern used in software development. It is also known as Dependency Injection (DI). It is a process in which objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean.
The IOC container is at the core of the Spring Framework. It is responsible for instantiating, configuring and assembling the objects (beans) that make up the application. The container gets its instructions on what objects to instantiate, configure and
A framework in Java is a collection of libraries(jar and war files), APIs, and other components that provide a structure for applications and enable developers to quickly build robust, scalable, and maintainable applications. Java frameworks provide a high-level abstraction layer so that developers can focus on the business logic and not the technical details. Popular Java frameworks include Spring, Hibernate, Struts, and AngularJS.
Q2.)what are the types of frameworks in java
Mainly frameworks are distributed in two types :-
1. Invasive framework
2. Non-Invasive framework
Q3.)difference between invasive and non invasive frameworks in java
Invasive frameworks are those which require developers to modify their existing code to fit the framework's standards in order to use it.
these framework force developer to use , extend or implement
Non-invasive frameworks are those which allow developers to use the framework without making any changes to their existing code. Non-invasive frameworks are typically more modern and easier to use.
these frameworks do not force developer to use , extend or implement
1. Model-View-Controller (MVC)
Model-View-Controller (MVC) is an architectural software design pattern that separates the logic of an application into three interconnected parts: model, view, and controller.
The model is responsible for maintaining data and business logic. It is the core of the application, and it stores and retrieves data.
The view is responsible for presenting the model data to the user. It is the user interface and can be implemented in multiple ways.
The controller is responsible for handling user inputs and updating the model accordingly. It is the bridge between the model and the view.
2. Spring Framework
Spring Framework is an open source application framework and inversion of control container for the Java platform. It provides a comprehensive programming and configuration model for modern Java-based enterprise applications. It was designed to simplify Java EE development and make developers more productive.
3. Struts Framework
The Apache Struts framework is an open-source framework for creating Java web applications. It uses and extends the Java Servlet API to encourage developers to adopt an MVC (Model-View-Controller) architecture. Struts provides a complete framework for creating robust, maintainable, and extensible web applications. It also provides support for internationalization and localization.
4. Hibernate Framework
Hibernate is an open source, object-relational mapping framework for Java. It is designed to provide a simple and efficient way to map Java objects to database tables, and to provide a simple query language for retrieving objects from the database. Hibernate also provides a powerful query language (HQL) for retrieving objects from the database. It is an object-relational mapping tool for the Java programming language. Hibernate is used to map Java classes to database tables and Java data types to SQL data types. It also provides data query and retrieval facilities, including a query language, criteria queries, and native SQL.
5. JavaServer Faces (JSF)
6. Google Web Toolkit (GWT)
7. Apache Wicket
Q4.)what is IOC and IOC lifecycle in spring
Inversion of Control (IoC) is an architectural pattern used in software development. It is also known as Dependency Injection (DI). It is a process in which objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean.
The IOC container is at the core of the Spring Framework. It is responsible for instantiating, configuring and assembling the objects (beans) that make up the application. The container gets its instructions on what objects to instantiate, configure and
semble from configuration metadata.
The lifecycle of an IOC container in Spring is as follows:
1. Create the container: The container is created using the ApplicationContext or BeanFactory interface.
2. Register the beans: The beans that make up the application are registered with the container.
3. Configure the beans: The beans are configured using the configuration metadata that was provided.
4. Assemble the beans: The beans are assembled into an application, with the dependencies between the beans resolved.
5. Start the container: The container is started, which causes any initialization logic for the beans to be executed.
6. Use the container: The application can now use the beans within the container.
7. Stop the container: The container is stopped, which causes any destruction logic for the beans to be executed.
Q5.) What is singleton class and rules of singleton class
A singleton class is a class that can only have one object or instance created from it. To create a singleton class, you must ensure that only one instance of the class can ever be created, and that all other objects must be able to access this instance. To do this, the singleton class must have:
1. A private constructor. This constructor prevents other classes from directly creating an instance of the singleton class.
2. A static instance variable. This variable holds a reference to the single instance of the singleton class.
3. A static factory method. This method returns the single instance of the singleton class, creating it if necessary.
4. Private access methods. These methods exist to ensure that only the singleton instance can access and modify the singleton instanceโs data.
Q6.)What is dependency injection and types of dependency injection in spring
Dependency Injection (DI) is a design pattern used to provide loose coupling between the classes and their dependencies. Spring Framework provides support for dependency injection, allowing objects to be injected as dependencies when they are needed.
Types of Dependency Injection in Spring:
1. Constructor-based Dependency Injection
2. Setter-based Dependency Injection
3. Interface-based Dependency Injection
4. Autowiring Dependency Injection
Q7.) types of bean configuration technique in java
1. XML Based Configuration: This is the most common and popular way of configuring the Spring beans. The beans are configured using the XML file, which contains all the bean definitions.
2. Annotation Based Configuration: This type of configuration allows you to create beans using annotations. You donโt need to create an XML file for the beans.
3. Java Based Configuration: This type of configuration uses pure Java classes to configure the beans. The beans are configured using the @Bean annotation.
4. Groovy Based Configuration: In this type of configuration, the beans are configured using the Groovy language. This type of configuration is very similar to Java-Based configuration.
5. AspectJ Based Configuration: This type of configuration uses AspectJ annotations to configure the beans. This type of configuration is used to configure the beans related to Aspect Oriented Programming (AOP).
Q8.) what is annotation and use of annotation in java
Annotations in Java are special types of modifiers or meta-data that can be added to Java source code. They provide information about the code and are used by the compiler and other tools to generate code, XML files, and other files. Annotations can be applied to classes, fields, methods, and other elements of a Java program. Common uses of annotations include providing information about the structure of a program, indicating which methods should be used for testing, and specifying how to handle errors.
Q9.) what is autowiring
Autowiring is a feature of the Spring Framework that provides dependency injection capabilities. It allows developers to inject objects into other objects without having to manually specify the object's dependencies. Autowiring can be configured using ann
The lifecycle of an IOC container in Spring is as follows:
1. Create the container: The container is created using the ApplicationContext or BeanFactory interface.
2. Register the beans: The beans that make up the application are registered with the container.
3. Configure the beans: The beans are configured using the configuration metadata that was provided.
4. Assemble the beans: The beans are assembled into an application, with the dependencies between the beans resolved.
5. Start the container: The container is started, which causes any initialization logic for the beans to be executed.
6. Use the container: The application can now use the beans within the container.
7. Stop the container: The container is stopped, which causes any destruction logic for the beans to be executed.
Q5.) What is singleton class and rules of singleton class
A singleton class is a class that can only have one object or instance created from it. To create a singleton class, you must ensure that only one instance of the class can ever be created, and that all other objects must be able to access this instance. To do this, the singleton class must have:
1. A private constructor. This constructor prevents other classes from directly creating an instance of the singleton class.
2. A static instance variable. This variable holds a reference to the single instance of the singleton class.
3. A static factory method. This method returns the single instance of the singleton class, creating it if necessary.
4. Private access methods. These methods exist to ensure that only the singleton instance can access and modify the singleton instanceโs data.
Q6.)What is dependency injection and types of dependency injection in spring
Dependency Injection (DI) is a design pattern used to provide loose coupling between the classes and their dependencies. Spring Framework provides support for dependency injection, allowing objects to be injected as dependencies when they are needed.
Types of Dependency Injection in Spring:
1. Constructor-based Dependency Injection
2. Setter-based Dependency Injection
3. Interface-based Dependency Injection
4. Autowiring Dependency Injection
Q7.) types of bean configuration technique in java
1. XML Based Configuration: This is the most common and popular way of configuring the Spring beans. The beans are configured using the XML file, which contains all the bean definitions.
2. Annotation Based Configuration: This type of configuration allows you to create beans using annotations. You donโt need to create an XML file for the beans.
3. Java Based Configuration: This type of configuration uses pure Java classes to configure the beans. The beans are configured using the @Bean annotation.
4. Groovy Based Configuration: In this type of configuration, the beans are configured using the Groovy language. This type of configuration is very similar to Java-Based configuration.
5. AspectJ Based Configuration: This type of configuration uses AspectJ annotations to configure the beans. This type of configuration is used to configure the beans related to Aspect Oriented Programming (AOP).
Q8.) what is annotation and use of annotation in java
Annotations in Java are special types of modifiers or meta-data that can be added to Java source code. They provide information about the code and are used by the compiler and other tools to generate code, XML files, and other files. Annotations can be applied to classes, fields, methods, and other elements of a Java program. Common uses of annotations include providing information about the structure of a program, indicating which methods should be used for testing, and specifying how to handle errors.
Q9.) what is autowiring
Autowiring is a feature of the Spring Framework that provides dependency injection capabilities. It allows developers to inject objects into other objects without having to manually specify the object's dependencies. Autowiring can be configured using ann
otations, XML or Java configuration. It makes it easier to maintain and manage applications, as well as reducing code complexity.
Q10.) what is qualifier annotation?
Qualifier annotation is an annotation used in the Spring Framework for more specific bean definition. It is used to create an alias for a bean so it can be autowired easily. It is used to specify a specific implementation of an interface or class.
it is used to add a level of type safety to code
it is used to provide additional info about a variables , methods or class.
Q11.) scope and bean scope modes
Bean Scopes
1. Singleton: The singleton scope is the default scope used in the Spring framework. It creates a single instance of the bean and all requests for that bean use the same instance.
2. Prototype: The prototype scope creates a new instance of the bean every time a request is made.
3. Request: The request scope creates a new instance of the bean for each HTTP request.
4. Session: The session scope creates a new instance of the bean for each HTTP session.
5. Global Session: The global session scope is similar to the session scope, except it is shared across different servlet contexts.
Q12.) what is stereotype annotations and use
Stereotype annotations are a type of annotation used in Java programming to indicate a particular design pattern or programming style. They provide a way to group related classes and help define the roles of each component. Examples of stereotype annotations include
@Component,
@Service, and
@Repository.
These annotations are used to indicate a type of role for a given class, for example an
@Service annotation might be used to indicate a class that provides a business service, while an @Repository annotation might be used to indicate a class that provides data access.
Q13.) what is datatype annotation and use
Data type annotation is the process of assigning a data type to a particular piece of data. This can be done for a variety of reasons such as to ensure data integrity and accuracy, to improve performance, and to simplify programming. Data type annotation is used in many programming languages, such as Java, C++, and Python, to indicate the type of data that is expected to be stored in a particular variable or data structure. It can also be used to provide information to a compiler so that it can tailor code generation to accommodate the data type.
Q14.) @ComponentScan:-
ComponentScan annotation define the locations to search for the annotated components/classes:
@ComponentScan annotation is used to tell Spring where to look for other components, configurations and services in the application. It helps Spring to locate components and services inside a particular package or packages. It also helps Spring to create a dependency graph in the application. The @ComponentScan annotation can be used with the basePackages attribute to specify the packages to scan or with the basePackageClasses attribute to specify the classes to scan.
@Configuration :-
Configuration annotation is an annotation used in Java-based configuration to define the classes used in the configuration. It is used to define the classes that are to be used as beans and the configuration information that is needed to configure the beans. Configuration annotation is used in combination with the other annotations such as Component, Bean, and ComponentScan to specify the bean classes and their configuration information.
@value:-
A value annotation is a form of annotation that is used to provide information about the value of a particular type or element in a software system. Value annotations are typically used to provide information about the meaning or purpose of the element, such as the expected range of values, allowed values, or the expected format of a value. They can also be used to provide information about the impact of changing the value of a particular element.
1. @Component: This annotation indicates that a class is a โcomponentโ. It is used to indicate that the class
Q10.) what is qualifier annotation?
Qualifier annotation is an annotation used in the Spring Framework for more specific bean definition. It is used to create an alias for a bean so it can be autowired easily. It is used to specify a specific implementation of an interface or class.
it is used to add a level of type safety to code
it is used to provide additional info about a variables , methods or class.
Q11.) scope and bean scope modes
Bean Scopes
1. Singleton: The singleton scope is the default scope used in the Spring framework. It creates a single instance of the bean and all requests for that bean use the same instance.
2. Prototype: The prototype scope creates a new instance of the bean every time a request is made.
3. Request: The request scope creates a new instance of the bean for each HTTP request.
4. Session: The session scope creates a new instance of the bean for each HTTP session.
5. Global Session: The global session scope is similar to the session scope, except it is shared across different servlet contexts.
Q12.) what is stereotype annotations and use
Stereotype annotations are a type of annotation used in Java programming to indicate a particular design pattern or programming style. They provide a way to group related classes and help define the roles of each component. Examples of stereotype annotations include
@Component,
@Service, and
@Repository.
These annotations are used to indicate a type of role for a given class, for example an
@Service annotation might be used to indicate a class that provides a business service, while an @Repository annotation might be used to indicate a class that provides data access.
Q13.) what is datatype annotation and use
Data type annotation is the process of assigning a data type to a particular piece of data. This can be done for a variety of reasons such as to ensure data integrity and accuracy, to improve performance, and to simplify programming. Data type annotation is used in many programming languages, such as Java, C++, and Python, to indicate the type of data that is expected to be stored in a particular variable or data structure. It can also be used to provide information to a compiler so that it can tailor code generation to accommodate the data type.
Q14.) @ComponentScan:-
ComponentScan annotation define the locations to search for the annotated components/classes:
@ComponentScan annotation is used to tell Spring where to look for other components, configurations and services in the application. It helps Spring to locate components and services inside a particular package or packages. It also helps Spring to create a dependency graph in the application. The @ComponentScan annotation can be used with the basePackages attribute to specify the packages to scan or with the basePackageClasses attribute to specify the classes to scan.
@Configuration :-
Configuration annotation is an annotation used in Java-based configuration to define the classes used in the configuration. It is used to define the classes that are to be used as beans and the configuration information that is needed to configure the beans. Configuration annotation is used in combination with the other annotations such as Component, Bean, and ComponentScan to specify the bean classes and their configuration information.
@value:-
A value annotation is a form of annotation that is used to provide information about the value of a particular type or element in a software system. Value annotations are typically used to provide information about the meaning or purpose of the element, such as the expected range of values, allowed values, or the expected format of a value. They can also be used to provide information about the impact of changing the value of a particular element.
1. @Component: This annotation indicates that a class is a โcomponentโ. It is used to indicate that the class