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
serves a specific purpose in the application.
2. @Autowired: This annotation tells Spring to inject an instance of the specified bean into the annotated field.
3. @Service: This annotation is used to denote a service class. It is used to indicate that the class is responsible for providing some sort of service to the application.
4. @Repository: This annotation is used to denote a data access object. It is used to indicate that the class is responsible for data access operations.
5. @RequestMapping: This annotation is used to map a specific HTTP request to a particular method in a controller class.
6. @Controller: This annotation is used to indicate that a class is a controller. It is used to indicate that the class is responsible for handling requests from the view layer.
Q15.) spring orm and jdbc (implemented methods and persistent methods)
Spring ORM:
Spring ORM is a data access framework that provides an abstraction over JDBC and other ORM frameworks. It offers a consistent programming model for accessing data from relational databases, NoSQL databases, and other data sources. It provides a simple way to access and query data, and can be used to reduce the amount of code needed to access a database.
Implemented methods:
• Data Access Object (DAO) - provides an interface for accessing data from the database.
• Query Interface - provides a way to create, execute, and manage queries.
• Transaction Management - provides an abstraction layer for managing transactions.
• Object-Relational Mapping (ORM) - provides a way to map Java objects to database tables.
• Object/Relational (O/R) Metadata Mapping - provides a way to define relationships between Java objects and database tables.
• Data Access Template - provides a way to easily access and manipulate data in the database.
Persistent Methods:
• Create - allows you to create a new entry in the database.
• Retrieve - allows you to retrieve an existing entry from the database.
• Update - allows you to modify an existing entry in the database.
• Delete - allows you to delete an existing entry from the database.
• Save - allows you to save an existing entry in the database.
• Merge - allows you to merge two existing entries in the database.
Q16.) mvc in spring and springboot
Spring MVC is a web framework built on the core features of the Spring framework. It is a component of the Spring Framework for building web applications and provides an alternative to the Java Enterprise Edition (JEE) framework. Spring MVC provides an easy way to create web applications. It is designed to be extensible and adaptable for a variety of applications, from small personal projects to large enterprise applications.
Spring Boot is a framework for building web applications on top of the Spring Framework. It simplifies the development of applications by providing a ready-made configuration for most common web development tasks. Spring Boot makes it easy to create stand-alone, production-grade Spring-based applications that you can "just run". It also provides a way to package and deploy applications to different environments, such as a cloud platform.
Q17.) spring mvc execution flow
1. User sends an HTTP Request to a web browser.
2. DispatcherServlet, receives the request and checks the web.xml file to identify the appropriate Controller.
3. The DispatcherServlet maps the request to the appropriate Controller and calls its handler methods.
4. The Controller processes the request and generates the Model or view object.
5. The view object is passed to the appropriate View Resolver.
6. The View Resolver identifies the appropriate View Component and prepares the output.
7. The DispatcherServlet passes the output to the web browser.
2. @Autowired: This annotation tells Spring to inject an instance of the specified bean into the annotated field.
3. @Service: This annotation is used to denote a service class. It is used to indicate that the class is responsible for providing some sort of service to the application.
4. @Repository: This annotation is used to denote a data access object. It is used to indicate that the class is responsible for data access operations.
5. @RequestMapping: This annotation is used to map a specific HTTP request to a particular method in a controller class.
6. @Controller: This annotation is used to indicate that a class is a controller. It is used to indicate that the class is responsible for handling requests from the view layer.
Q15.) spring orm and jdbc (implemented methods and persistent methods)
Spring ORM:
Spring ORM is a data access framework that provides an abstraction over JDBC and other ORM frameworks. It offers a consistent programming model for accessing data from relational databases, NoSQL databases, and other data sources. It provides a simple way to access and query data, and can be used to reduce the amount of code needed to access a database.
Implemented methods:
• Data Access Object (DAO) - provides an interface for accessing data from the database.
• Query Interface - provides a way to create, execute, and manage queries.
• Transaction Management - provides an abstraction layer for managing transactions.
• Object-Relational Mapping (ORM) - provides a way to map Java objects to database tables.
• Object/Relational (O/R) Metadata Mapping - provides a way to define relationships between Java objects and database tables.
• Data Access Template - provides a way to easily access and manipulate data in the database.
Persistent Methods:
• Create - allows you to create a new entry in the database.
• Retrieve - allows you to retrieve an existing entry from the database.
• Update - allows you to modify an existing entry in the database.
• Delete - allows you to delete an existing entry from the database.
• Save - allows you to save an existing entry in the database.
• Merge - allows you to merge two existing entries in the database.
Q16.) mvc in spring and springboot
Spring MVC is a web framework built on the core features of the Spring framework. It is a component of the Spring Framework for building web applications and provides an alternative to the Java Enterprise Edition (JEE) framework. Spring MVC provides an easy way to create web applications. It is designed to be extensible and adaptable for a variety of applications, from small personal projects to large enterprise applications.
Spring Boot is a framework for building web applications on top of the Spring Framework. It simplifies the development of applications by providing a ready-made configuration for most common web development tasks. Spring Boot makes it easy to create stand-alone, production-grade Spring-based applications that you can "just run". It also provides a way to package and deploy applications to different environments, such as a cloud platform.
Q17.) spring mvc execution flow
1. User sends an HTTP Request to a web browser.
2. DispatcherServlet, receives the request and checks the web.xml file to identify the appropriate Controller.
3. The DispatcherServlet maps the request to the appropriate Controller and calls its handler methods.
4. The Controller processes the request and generates the Model or view object.
5. The view object is passed to the appropriate View Resolver.
6. The View Resolver identifies the appropriate View Component and prepares the output.
7. The DispatcherServlet passes the output to the web browser.
What is pom.xml ??
What is dependency injection?
In how many ways dependency injection done ??
What is pojo poji bean ??
What is configuration how many ways we can achieve
Setter injection getter injection construction injection
Explain annotations
Spring life cycle
Bean life cycle
Explain stereotype annotations
What is component scan
MVC architecture
Model view controller
What is data binding??
What is IOC ?
Explain different spring containers
Explain path param
Response param
Response body
Response param / body
Tight loose coupling??
What is dependency injection?
In how many ways dependency injection done ??
What is pojo poji bean ??
What is configuration how many ways we can achieve
Setter injection getter injection construction injection
Explain annotations
Spring life cycle
Bean life cycle
Explain stereotype annotations
What is component scan
MVC architecture
Model view controller
What is data binding??
What is IOC ?
Explain different spring containers
Explain path param
Response param
Response body
Response param / body
Tight loose coupling??
Forwarded from SathyaReact