Interview Questions & Answers - JFS
Interview Questions & Answers - JFS
A1: Java is a high-level, object-oriented programming language designed for portability across
platforms. It was developed by Sun Microsystems (now owned by Oracle) in 1995. Java uses
the "write once, run anywhere" philosophy, meaning compiled Java code can run on any
platform that has a Java Virtual Machine (JVM).
● Simple: Java syntax is easy to understand, and it removes complex features like
pointers.
● Object-Oriented: Java follows the OOP paradigm, making code more reusable and
modular.
● Platform Independent: Code can run on any system with JVM installed.
● Secure: Java offers features like bytecode verification and runtime security checks.
● Multithreaded: Java has built-in support for multithreading, allowing multiple tasks to
run simultaneously.
● Robust: Java provides strong memory management and exception handling, reducing
errors.
● Portable: Java bytecode can be executed on any platform.
● byte: 1 byte
● short: 2 bytes
● int: 4 bytes
● long: 8 bytes
● float: 4 bytes
● double: 8 bytes
● char: 2 bytes
● boolean: 1 bit
● Arithmetic Operators: +, -, *, /
● Relational Operators: ==, !=, >, <
● Logical Operators: &&, ||, !
● Assignment Operator: =
● Unary Operators: ++, --, +, -
● Implicit Casting (Widening): Automatically converting smaller data types to larger ones
(e.g., int to long).
● Explicit Casting (Narrowing): Manually converting larger data types to smaller ones
(e.g., double to int).
Q10: How can you pass arguments to a Java program from the command line?
A10: Command-line arguments are passed to the main method as a string array.
Example:
package com.myapp;
public class MyClass {
// class implementation
}
class Animal {
void eat() { System.out.println("Eating"); }
}
class Dog extends Animal {
void bark() { System.out.println("Barking"); }
}
class Animal {
void sound() { System.out.println("Animal sound"); }
}
class Dog extends Animal {
void sound() { super.sound(); System.out.println("Barking"); }
}
● Scrollable Result Set: Allows you to move the cursor in any direction, including
backward.
● Updatable Result Set: Allows you to update the data in the database directly through
the result set.
conn.setAutoCommit(false);
try {
// execute queries
conn.commit();
} catch (SQLException e) {
conn.rollback();
}
● JAR (Java Archive): Contains Java class files and related resources, used for
packaging libraries.
● WAR (Web Archive): Contains a web application, including servlets, JSPs, and web
resources.
● EAR (Enterprise Archive): Used for packaging enterprise applications, including web
and EJB modules.
Q42: What is the difference between a web server and an application server?
A42:
● Web Server: Handles HTTP requests and serves static content (e.g., HTML, images).
● Application Server: Supports dynamic content, often using Java EE technologies like
servlets, JSPs, and EJBs. It can include a web server.
1. Initialization: The init() method is called when the servlet is first loaded.
2. Request Handling: The service() method handles client requests.
3. Destruction: The destroy() method is called when the servlet is unloaded.
Q49: How can you invoke other web resources (e.g., servlets or JSPs) from a servlet?
A49: You can invoke other resources using RequestDispatcher or
HttpServletResponse.sendRedirect().
Example:
RequestDispatcher rd = request.getRequestDispatcher("anotherServlet");
rd.forward(request, response);
67.Q: What are JSP and property files used for in Spring MVC?
A: JSPs are used to render dynamic content, while property files are used to store
messages and content for internationalization (i18n) and localization, which can be
resolved by Spring's MessageSource.
85.Q: What is the naming convention for base packages in Spring Boot?
A: In Spring Boot, the base package should be named in a way that reflects the
application’s structure. Typically, the main class annotated with
@SpringBootApplication should be placed in the root package, and sub-packages
should contain other components like services, controllers, and repositories.
98.Q: How do you use the Spring Starter Wizard in STS IDE?
A: In STS, the Spring Starter Wizard helps you quickly create Spring Boot projects by
selecting dependencies, project details, and generating a project structure that is ready
to use.
99.Q: How do you use the Spring Starter Wizard in IntelliJ IDEA?
A: In IntelliJ IDEA, the Spring Starter Wizard is available to generate Spring Boot
projects by selecting the required dependencies and project configurations, which then
creates the application structure for you.
104. Q: How do you set up and run your first Hibernate application?
A: To set up and run your first Hibernate application, you need to add Hibernate
dependencies (like Hibernate Core, Hibernate EntityManager) to your project, configure
Hibernate settings (either via XML or annotations), create a session factory, and perform
CRUD operations on your mapped objects.
112. Q: How do you use the mapping file generation tool in Hibernate?
A: The mapping file generation tool is used to create Hibernate XML mapping files from
Java classes. This is typically done using Hibernate tools in an IDE or by using the
Hibernate Ant tasks or Maven plugin.
131. Q: What are the benefits of using Spring Boot for REST services?
A: Spring Boot simplifies the development of REST APIs by:
145. Q: How do you configure CORS (Cross-Origin Resource Sharing) in Spring Boot?
A: CORS can be configured globally using WebMvcConfigurer or locally at the
controller level using the @CrossOrigin annotation. It allows you to specify which
domains are allowed to access your REST API.
A: HTML (Hypertext Markup Language) is the standard language used to create and design
webpages. It structures content on the web, using various tags to define elements like headings,
paragraphs, links, images, and more.
A: HTML heading tags define headings in a webpage. There are six levels of heading tags:
A: HTML attributes provide additional information about an element. They are placed within the
opening tag and define properties such as id, class, src, href, etc. For example, <a
href="https://example.com">Link</a>.
A: The <input> tag is used to create interactive controls in a form, allowing the user to input
data. It supports various types such as text, password, checkbox, radio, submit, etc.
A: HTML lists can be unordered (<ul>) or ordered (<ol>). Each item in the list is defined using
the <li> tag. For example:
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
A: Meta tags provide metadata about the HTML document, such as the character encoding
(<meta charset="UTF-8">), author information, description, and keywords for search
engines.
184. Q: What is the difference between block and inline elements in HTML?
A: Block elements take up the full width of their parent container (e.g., <div>, <p>) and start on
a new line. Inline elements take up only as much width as their content and do not start on a
new line (e.g., <span>, <a>).
A: CSS (Cascading Style Sheets) is used to control the presentation and layout of HTML
elements. It allows you to define styles such as colors, fonts, margins, padding, and more,
which are applied to the HTML structure.
A: CSS selectors target HTML elements to apply styles. Common selectors include:
A: CSS specificity determines which styles are applied when there are conflicting rules. It is
calculated based on the types of selectors used: inline styles, IDs, classes, attributes, and
element selectors. Inline styles have the highest specificity.
A: CSS Flexbox is a layout model that provides a way to arrange elements in a flexible
container. Items in a flex container can grow, shrink, and be aligned horizontally or vertically,
making responsive design easier.
A: CSS Grid is a two-dimensional layout system that allows elements to be arranged in rows
and columns. It is used for creating complex web layouts and gives greater control over
positioning and spacing.
A: CSS media queries are used to apply different styles based on device characteristics, such
as screen size, resolution, and orientation. They help create responsive designs that adjust to
various devices.
A: A variable in JavaScript is used to store data values. Variables can be declared using var,
let, or const and are used to hold values like numbers, strings, objects, etc.
● +: Addition
● -: Subtraction
● *: Multiplication
● /: Division
● %: Modulus (remainder)
● ==: Equal to
● !=: Not equal to
● >: Greater than
● <: Less than
● >=: Greater than or equal to
● <=: Less than or equal to
198. Q: What are comparison operators in JavaScript?
A: Comparison operators are used to compare two values and return a boolean result.
Examples include:
A: Conditional statements are used to perform different actions based on different conditions.
Common conditional statements include: