0% found this document useful (0 votes)
5 views9 pages

adv java ese

Uploaded by

rajambekar2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

adv java ese

Uploaded by

rajambekar2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Q1. How many layers are there in OSI model? Explain. Q2. Explain socket programming in details.

Socket Programming is a method of communication between two


The OSI (Open Systems Interconnection) model is a devices over a network. It involves creating a socket at both ends of
conceptual framework used to understand network interactions the communication to send and receive data.
in seven layers: 1. Socket: A socket is a combination of an IP address and a port number
1. Physical Layer: Deals with the physical connection that uniquely identi ies a communication endpoint. A socket can be
between devices. Protocols: Ethernet, USB, DSL. used to send data to a remote machine, and it can listen for incoming
2. Data Link Layer: Provides node-to-node data transfer. data.
Protocols: PPP (Point-to-Point Protocol), Frame Relay, 2. Types of Sockets: Stream Socket (TCP): Provides reliable, connection-
oriented communication. Uses the Transmission Control Protocol
Ethernet.
(TCP).
3. Network Layer: Handles routing of data packets.
o Datagram Socket (UDP): Provides connectionless
Protocols: IP (Internet Protocol), ICMP (Internet Control
communication with no guarantee of reliability or order. Uses
Message Protocol).
User Datagram Protocol (UDP).
4. Transport Layer: Ensures complete data transfer. 3. Server Side: The server listens for incoming client requests on a
Protocols: TCP (Transmission Control Protocol), UDP speci ic port using a ServerSocket.
(User Datagram Protocol). o Once a request is received, a connection is established, and data
5. Session Layer: Manages sessions between applications. can be exchanged.
Protocols: NetBIOS, RPC (Remote Procedure Call). o Example: In Java, ServerSocket.accept() is used to accept
6. Presentation Layer: Translates data for the application incoming connections.
layer. Protocols: SSL (Secure Sockets Layer), TLS 4. Client Side: The client connects to the server by specifying the
(Transport Layer Security). server’s IP address and the port to connect to.
7. Application Layer: Closest to the end user, supports o Once connected, data can be sent and received.
application and end-user processes. Protocols: HTTP, o Example: In Java, Socket.connect() is used to establish a
FTP, SMTP, DNS. connection to the server.
Applica on Layer 5. Steps in Socket Communication: Create a Socket: The client and
Presenta on Layer server each create a socket object.
Session Layer o Establish Connection: The client connects to the server via the
Transport Layer server’s IP and port number.
Network Layer o Send/Receive Data: Once connected, data can be exchanged
Data Link Layer between the server and client using input/output streams.
Physical Layer o Close the Connection: After communication is inished, both
sides close the socket to free up resources.
// Server Code: ServerSocket serverSocket = new ServerSocket(8080);
Socket socket = serverSocket.accept(); // Wait for client connection //
Client Code: Socket socket = new Socket("localhost", 8080); // Connect to
server
Q3. Explain Multicasting socket along with 4 methods. Q4. Explain SSI in details.
Multicasting allows data to be sent to multiple receivers at Server Side Includes (SSI) is a simple server-side scripting
once, which is more efficient than broadcasting (sending to all technology that allows web servers to dynamically generate
devices in the network). It uses MulticastSockets. content by including one file inside another. This technology is
Multicasting is the transmission of a message or information to a used to enhance static web pages by inserting dynamic content
group of destination computers simultaneously in a single into HTML without the need to recompile code or perform
transmission. Multicast sockets are used for sending data to complex programming.
multiple clients over a network efficiently. Java provides Key Features of SSI:
Multicast Socket class for multicasting operations.
Key Concepts: 1. Server-side Execution: SSI scripts are processed by the
 Multicast Group: A group of hosts that can send or receive server, not by the browser. The server looks for special
multicast messages. SSI directives in HTML files (e.g., <!--#include-->) and
 Multicast IP Address: A specific range of IP addresses processes them to insert dynamic content before sending
(224.0.0.0 to 239.255.255.255) used for multicasting. the response to the client.
 Multicast Socket: A type of Datagram socket that supports
sending and receiving messages from multicast groups. 2. Common Use Cases:
o Including Static Content: It’s often used to include
Four Key Methods for Multicasting: static pieces of content like headers, footers, or
1. joinGroup(InetAddress group): Allows the socket to join navigation bars across multiple pages.
a multicast group, so it can receive messages sent to the
group’s multicast IP address. o Displaying Server Information: SSI can output
information about the server, such as the current
2. leaveGroup(InetAddress group): Used when the socket time, server variables, etc.
no longer wants to receive messages from a multicast o Displaying Dynamic Content: SSI can be used to
group.
fetch dynamic content from databases, display logs,
3. send(DatagramPacket p, byte ttl): Used to send data to or show system variables (like the current date/time).
the multicast group. The ttl (time-to-live) controls the scope 3.How it Works:
of the multicast, limiting the number of hops (i.e., network
layers) it can go through.  The server processes the SSI directives in the HTML file
before sending the final output to the client’s browser. For
4. setTimeToLive(int ttl): Sets the TTL for multicast packets example, a request for a page with the SSI directive <!--
sent from the socket. The TTL controls how many network #include file="header.html" --> will cause the server to
segments (hops) the packet is allowed to traverse. include the contents of header.html in place of the
directive, and the result is sent to the browser.
Q5. JSP tags: Scriplet, Directive, Expression, Declaration. Q6. What is Servlet Channing? How it can be achieved?
In JavaServer Pages (JSP), JSP tags are used to embed Java Servlet Chaining refers to the process of forwarding a request
code into HTML pages. There are four main types of tags in from one servlet to another servlet within the same web
JSP that allow embedding Java code within HTML: application, allowing multiple servlets to collaborate in
Scriplet (<% %>): processing a single request. This is typically used to separate
concerns, such as performing multiple steps in the request
o A scriplet allows embedding Java code directly inside handling process (e.g., validation, authentication, etc.).
the JSP page.
How Servlet Chaining Works:
o Java code written inside a scriplet is executed when
the page is requested, and any result can be 1. A client sends a request to a servlet.
included in the response. 2. The first servlet processes the request and forwards it to
Directive (<%@ %>): another servlet using the RequestDispatcher.

 A directive provides meta-information about the page, 3. The second servlet performs its part of the processing and
can either send a response to the client or forward the
such as settings for the page language, content type,
imports, etc. request to another servlet.

 Directives affect the overall structure of the JSP and do Achieving Servlet Chaining: You can achieve servlet chaining
not output content directly. using the RequestDispatcher object. It allows you to either
forward or include content in the response from one servlet to
Expression (<%= %>): another.
 An expression allows embedding Java code that will  Forwarding a Request: The forward() method of
produce output directly into the HTML response. RequestDispatcher is used to pass the request to another
 The Java expression inside the tag is evaluated, and the servlet without sending the response back to the client.
result is inserted directly into the page.  Including Content: The include() method includes the
Declaration (<%! %>): content from another servlet or resource, appending the
result to the response.
 A declaration allows defining variables or methods at the
class level in the JSP page. These are available Benefits of Servlet Chaining:
throughout the JSP page.  Separation of concerns: Different servlets can handle
 Declarations define methods and fields that can be used different parts of the request.
by the page.  Code Reusability: Common functionality can be placed in
separate servlets.
Q7. What is MVC? Explain MVC architecture. 2. Model: The Model interacts with the database or business
MVC (Model-View-Controller) is a software architectural pattern logic and processes the data.
commonly used in designing web applications. It separates an 3. Update View: The Controller then updates the View
application into three main components, each responsible for a based on the changes in the Model. The view is re-
different aspect of the application's behavior: rendered with the updated data.
1. Model: Represents the data and business logic of the
application.
o It interacts with the database and processes data,
keeping it separate from the user interface.
o The model is responsible for updating the view when
the data changes and sending notifications to the
controller about any updates.
2. View: The view is responsible for displaying the data
provided by the model in a user-friendly format.
o It renders the HTML or other UI elements that the
user interacts with.
Servlet JSP
o The view listens for changes in the model and Servlet is a java code. JSP is a HTML-based
updates the UI accordingly. compilation code.
Writing code for servlet is JSP is easy to code as it is
3. Controller: The controller acts as an intermediary harder than JSP as it is HTML java in HTML.
between the model and the view. in java.
o It handles user inputs (such as button clicks, form Servlet plays a controller role JSP is the view in the MVC
submissions) and determines which part of the model in the ,MVC approach. approach for showing output.
to interact with based on the request. Servlet is faster than JSP. JSP is slower than Servlet
Servlet can accept all protocol JSP only accepts HTTP
o After processing, the controller updates the view requests. requests.
accordingly, either by redirecting to another view or In Servlet, we can override In JSP, we cannot override its
returning new data. the service() method. service() method.
Flow of MVC Architecture: User Action: The user interacts In JSP, we cannot override its In JSP there are inbuilt
service() method. implicit objects.
with the View (e.g., clicking a button or submitting a form).
1. Controller: The Controller processes the user input,
interacts with the Model to retrieve or update data.
Q8. Explain architecture of hibernate. Core concept of Hibernate. 5. Transaction: Hibernate provides transaction management
Hibernate is an Object-Relational Mapping (ORM) framework for ensuring that database operations are completed
for Java. It simplifies the interaction between Java applications successfully or rolled back in case of errors.
and relational databases by mapping Java objects to database 6. Querying: Hibernate supports several methods of
tables. Hibernate abstracts the complexities of database querying the database, including HQL (Hibernate Query
interaction, allowing developers to work with Java objects Language), Criteria API, and native SQL.
instead of writing SQL queries directly.
Architecture of Hibernate:
Core Concepts of Hibernate:
1. Application Layer: The Java application interacts with
1. Session: The Session is the interface between the Java Hibernate APIs to save, retrieve, and manage entities
application and the database. It is used to create, read, (objects).
update, and delete objects in the database. A session
2. Hibernate Core: Handles the interaction between Java
represents a single unit of work.
objects and relational database. This layer contains the
o SessionFactory is used to create sessions. core components like SessionFactory, Session,
2. SessionFactory: SessionFactory is a thread-safe object Transaction, and Query.
that creates Session objects. It is a heavy-weight object, 3. Database Layer: The relational database stores the data,
usually created once for the entire application. which is accessed through SQL queries generated by
o It is configured with Hibernate configuration Hibernate.
(hibernate.cfg.xml) that contains information like the
database URL, username, password, and other
Hibernate settings.
3. Configuration: Hibernate uses a configuration file
(hibernate.cfg.xml) or annotations to specify the database
connection, mapping, and other configurations.
4. Mapping: Hibernate uses mapping files (.hbm.xml) or
annotations to map Java objects (entities) to database
tables. These mappings define how Java objects are
saved, retrieved, and updated in the database.
o In the mapping, the properties of Java classes are
mapped to columns of the database tables.
Q9. Explain Maven & it’s architecture in details.  default: Handles the build, testing, packaging,
and deployment.
Maven is a powerful build automation tool used primarily for
Java projects. It is a project management tool that helps  clean: Cleans the project (removes compiled
developers manage the build, reporting, and documentation artifacts).
tasks. It provides a consistent framework for managing project
 site: Builds the project’s documentation.
dependencies, building the project, and generating
documentation. 4. Maven Plugins: Maven uses plugins to perform tasks like
compiling code, running tests, packaging the project, etc. Each
Maven Architecture Overview:
plugin is responsible for a specific task in the build process.
1. POM (Project Object Model): The central configuration file
5. Goals: A goal is a specific task that Maven performs within a
for a Maven project is the pom.xml. This file contains
plugin. Goals are bound to lifecycle phases (e.g., compile, test,
information about the project, such as its dependencies,
package).
build settings, and plugins.
Maven Workflow: Dependency Management: Maven manages
o Elements in pom.xml: <groupId>: Defines the group
external libraries by downloading them from remote repositories into
or organization.
the local repository. Dependencies are specified in the pom.xml file.
 <artifactId>: The name of the artifact (e.g., my-
 Build Management: Maven builds the project by using the
app).
pom.xml file to define the build process, including compiling
 <version>: The version of the artifact. code, running tests, and packaging the project.
 <dependencies>: The dependencies required  Multi-Module Project: Maven supports complex, multi-
by the project. module projects where a parent project can manage several
sub-projects.
2. Maven Repositories: Local Repository: A directory on the
developer’s machine that stores dependencies
downloaded from remote repositories.
o Remote Repository: A central location (e.g., Maven
Central) that stores libraries for reuse by other
projects.
o Central Repository: A publicly available repository
(e.g., Maven Central Repository) for open-source
Java libraries.
3. Maven Lifecycle: Maven defines a standard build lifecycle,
which is a sequence of steps that occur when building a
project. The three primary lifecycles are:
Q10. List down popular MVC frameworks.
MVC (Model-View-Controller) is a widely-used design pattern Q11. Short note HQL with Example.
for building web applications by separating the application logic HQL (Hibernate Query Language) is an object-oriented
into three interconnected components. Many frameworks have query language, similar to SQL but designed specifically
been developed to support the MVC pattern, offering features
for Hibernate to query the Java objects (entities) rather
like routing, data binding, and template rendering. than database tables. HQL is independent of the
Here are some popular MVC frameworks: database, meaning that it is database-agnostic. It allows
1. Spring MVC: Part of the larger Spring Framework, Spring developers to perform database operations like SELECT,
UPDATE, DELETE, and INSERT but using object-
MVC is one of the most widely used Java-based
frameworks. It provides a comprehensive infrastructure for oriented entities.
building web applications by using the DispatcherServlet Example: String hql = "FROM Employee WHERE salary >
to manage the flow between the model, view, and :salary";
controller.
Query query = session.createQuery(hql);
2. Struts: Apache Struts is an open-source web application query.setParameter("salary", 50000);
framework that uses the MVC pattern. It simplifies the
development of Java web applications by using tags for List<Employee> employees = query.list();
creating the user interface and supports features like Q12. Explain Maven life cycle in details.
validation, form handling, and internationalization.
1. Maven Lifecycle: Maven defines a standard build
3. JSF (JavaServer Faces):JSF is a Java web application lifecycle, which is a sequence of steps that occur
framework that provides a component-based approach to when building a project. The three primary lifecycles
building user interfaces. are:
4. Grails: Grails is a Groovy-based web application  default: Handles the build, testing,
framework built on top of Spring MVC. It leverages the packaging, and deployment.
Groovy programming language to provide dynamic web
development with a convention-over-configuration  clean: Cleans the project (removes compiled
approach. artifacts).

5. Play Framework: Play is a reactive web framework for  site: Builds the project’s documentation.
Java and Scala. It focuses on simplicity, scalability, and
developer productivity. Play is an MVC-based framework
that provides asynchronous processing and real-time
capabilities.
Q13. What is Maven Repository? Hibernate JDBC
Hibernate maps the object In JDBC, one needs to write
A Maven Repository is a central location where all project model’s data to the schema of code to map the object model’s
dependencies (JARs, libraries, plugins, etc.) are stored. There the database itself with the help data representation to the
are three types of Maven repositories: of annotations. schema of the relational model.
Hibernate maps the object JDBC enables developers to
1. Local Repository: The local repository is a directory on model’s data to the schema of create queries and update data
your machine where Maven stores all the project the database itself with the help to a relational database using
dependencies it downloads. It is located in the of annotations. the Structured Query Language
(SQL).
~/.m2/repository directory by default (on Unix/Linux-based It is a Java framework. It is a database connectivity
systems). tool.
Lazy Loading is supported. Lazy Loading is not supported.
o When you run a Maven build, Maven will first check It has high performance. It has low performance than
the local repository for the required dependencies Hibernate.
before downloading them from remote repositories. It itself manages its own One needs to maintain explicitly
transactions. database connections and
o If the dependency isn't available locally, Maven will transactions.
attempt to fetch it from remote repositories. Waiting time is more for any It has a dedicated customer
answer to an issue. support service system.
2. Central Repository:
o The Maven Central Repository is a large, publicly IPv4 IPv6
available repository that hosts a vast collection of 32 bits (4 bytes) long, 128 bits (16 bytes) long, allowing
libraries and dependencies. It is managed by the resulting in approximately 4.3 for 340 undecillion addresses
Maven community and is the default repository from billion unique addresses (2^128), which solves the
which Maven downloads dependencies. (2^32). address exhaustion problem of
IPv4.
o By default, Maven will fetch dependencies from this
Written in decimal as four Written in hexadecimal,
central repository if they are not found in the local
octets separated by dots separated by colons (e.g.,
repository. (e.g., 192.168.1.1). 2001:0db8:85a3:0000:0000:8a2
3. Remote Repository: A remote repository is any e:0370:7334).
repository other than the Maven Central Repository, Unicast, broadcast, multicast. Unicast, multicast, anycast
typically hosted by a third party or an organization. For The header is complex, with The header is simplified with 8
example, a private corporate repository can host internal 12 fields, requiring more fields, improving processing
libraries that are not available on Maven Central. processing time. efficiency and speed.
Security is optional and IPsec is mandatory, providing
o You can define a remote repository in the pom.xml typically implemented built-in security features.
file using the <repositories> tag. through additional protocols
like IPsec.
Q16. Differen ate between RMI and RPC.
RPC RMI
RPC is a library and OS RMI is a java platform.
dependent platform.
RPC supports procedural RMI supports object-oriented
programming. programming.
RPC is less ef icient in RMI is more ef icient than RPC.
comparison of RMI.
RPC creates more overhead. RMI creates less overhead than
RPC.
RPC is the older version of RMI. RMI is the successor version of
RPC.
RPC does not provide any RMI provides client level
security. security.
Can be complex due to low- Generally simpler to use and
level implementation implement
Q18. Difference between Servlet and CGI

Servlets CGI
It is thread based i.e. for every
It is process-based i.e. for
new request new thread isevery new request new
created. process is created.
The codes are written in JAVA
The codes are written any
programming language. programming language.
It can use any of the web-
It can use the web-server that
server. supports it.
Data sharing is possible.Data sharing is not possible.
It links directly to the server.
It does not link the web server
directly to the server.
It can read and set HTTP It can neither read nor set
servers. HTTP servers.
It is portable. It is not portable.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy