Unit 1-FSD
Unit 1-FSD
Full stack development is the process of developing both the frontend and backend of applications.
Any application has a frontend (user-facing) component and a backend (database and logic)
component. The frontend contains the user interface and code related to user interactions with the
application. The backend contains all the code required for the application to run, including
integrations with data systems, communicating with other applications, and processing data.
Software developers require slightly different skills, tools, and software knowledge for frontend and
backend development. However, full-stack development combines both disciplines—meaning teams
can build applications from start to finish in an integrated and cohesive manner.
A full-stack application is a software application that encompasses both frontend and backend in a
single code base.
The technologies that a full-stack developer uses will change depending on the focus area. Below are
the differences between frontend and backend technologies.
Frontend technology
Frontend technology (or client software) focuses on the client-facing side of development. You code
any parts of the graphical user interface (GUI) or the features that users interact with using frontend
technology.
Backend technology
Backend technology (or server software) coordinates the exchange of information between the
frontend and the server running a webpage. It allows an application to communicate with the main
server. The most common backend languages are Hypertext Preprocessor (PHP), Ruby, Java, and
Python. However, there are many more programming languages and technologies that can be used for
different requirements.
Storage layer
The storage layer manages and stores any application data. It will communicate with databases to
write and read data, while providing access to data. A notification layer will send notifications from
the frontend to the backend and vice versa. This allows an application to communicate and trigger
responses.
Business logic layer
The business logic layer is the main core of the backend. Backend developers configure
processing logic in this layer, changing the response a certain API request delivers.
Java 11 (//Back end development with Java 11 enhancements done )
String Enhancements:
repeat(int): This methos can be called on string object, it returns the given string
object for the mentioned int number.
To this repeat() method if we provides negative value then it gives illegal argument
exception
This method accepts the integer number, Since it accepts the integer, after creating
the new string the length should not cross the integer limit, if it crosses, it throws out
of memory error.
isBlank(): It returns true, if the given string is empty or having only the spaces.
strip(): this method is same as trim() which removes the leading and trailing spaces
from the string.
stripLeading(): This method is used to delete the leading spaces only
stripTrailing(): This method is used to delete the trailing spaces
trim() removes only characters <= U+0020 (space); strip() removes all
Unicode whitespace characters (but not all control characters, such as \0)
lines():
Returns a stream of lines extracted from this string, separated by line terminators
A line terminator is one of the following:
a line feed character {@code "\n"} (U+000A),
a carriage return character {@code "\r"} (U+000D), or a carriage return followed
immediately by a line feed {@code "\r\n"} (U+000D U+000A).
This toArray() takes the functional interface and converts into Array.
File API Changes:
Reading and writing text files has been continuously simplified since Java 6. In Java
6, we had to open a FileInputStream, wrap it with an InputStreamReader and a
BufferedReader, then load the text file line by line into a StringBuilder (alternatively,
omit the BufferedReader and read the data in char[] blocks) and close the readers and
the InputStream in the finally block.
Luckily, we had libraries like Apache Commons IO that did this work for us with the
FileUtils.readFileToString() and writeFileToString() methods.
The above is the general way of reading the data from the file.
Below is the Java 11 implementation.
readString(): This method reads all content from a file into a String. Using UTF-8
charset it decodes from bytes to characters. This function makes sure that the file is
closed when all content have been read or an I/O Error or other runtime exception, is
thrown.
writeString(): This method is used to write the data to the file. Syntax: static Path
writeString(Path path, CharSequence csq, OpenOption... options)
The first argument is path where the file is present.
The Second argument is Char Sequence which is nothing but the String that we want
to write to the file
The third parameter var args options ->options specifies how the file is opened.
The below is the other way of creating the file using createTempFile method
Path path = Files.writeString(Files.createTempFile(“test”, “.txt”), “Java 11 features”);
var s1 - > s1 //not allowed. Need parentheses if you use var in lambda.
Rules for Lamda local variables.
•
•
•
1. If there are multiple parameters then use var with all the parameters. No skipping allowed.
2. If one parameter use var then other parameters must use var rather than other types like
int, float, etc.
3. Must use parenthesis () while using the var with the parameters.
This not() static method is taking the predicate as input and returning the negate
[predicate as output. Internally it is calling the negate() method
Http Client:
• In Java 11, HTTP Client has introduced newly, through which we can send the request
and get the response.
• This HttpClient is present in java.net.http package.
• Making HTTP requests is a core feature of modern programming, and is often one of
the first things you want to do when learning a new programming language. For Java
programmers there are many ways to do it - core libraries in the JDK and third-party
libraries
• Using HttpURLConnection or ApacheHttpClient HTTP request and response can be
obtained.
• An enhanced HttpClient API was introduced in Java 9 as an experimental feature.
With Java 11, now HttpClient is a standard. It is recommended to use instead of other
HTTP Client APIs like Apache Http Client API. It is quite feature rich and now Java
based applications can make HTTP requests without using any external dependency.
Steps
Java 11 introduced a concept of nested class where we can declare a class within a class.
This nesting of classes allows to logically group the classes to be used in one place, making
them more readable and maintainable. Nested class can be of four types −
○ Static nested classes
○ Non-static nested classes
○ Local classes
○ Anonymous classes
Java 11 also provide the concept of nestmate to allow communication and verification of
nested classes.
Java 11 introduced nest-based access control that allows classes to access each other's
private members without the need for bridge methods created by the compiler. These
methods are called accessibility-broadening bridge methods and the compiler inserts
these into the code during the program execution.
Before Java 11, if we have private members in our code then the compiler creates
accessibility-broadening bridge methods that increase the size of the deployed applications
and may lead to confusion. That's why Java improved nest-based access control.
Java 11 allows classes and interfaces to be nested within each other. These nested type can
be private fields, methods, and constructors.
Web service
• Web Service is a web application that can communicate with other web-based applications
over a network. Web services implementation allows two web applications developed in
different languages to interact with each other using a standardized medium like XML, SOAP,
HTTP etc.
Features
• Web services are based on open standards like XML, HTTP. So these are operating
system independent.
• Likewise, web services are programming language independent. A Java application can
consume a PHP web service.
• Web services can be published over the internet to be consumed by other web applications.
• The consumer or the client of the web-service is loosely coupled with the web service. So
the web services can update or change its underlying logic without affecting the consumer.
SOAP Web Service:
• SOAP stands for Simple Object Access Protocol. It is a standardized protocol for message
exchange between web applications. The message format supported by SOAP is XML. A web
service that is based on SOAP protocol is called SOAP web service.
• REST stands for Representational State Transfer. It is an architectural style that describes
some constraints for web service development. The web services satisfying these constraints
are RESTful web services. The six REST architecture constraints are-
1. Client-Server – Client and server are separated by a uniform interface. These are not
concerned with each other’s internal logic.
2. Stateless – Each client request is independent and contains all the necessary information
required to get executed. No client data is saved at the server.
3. Cacheable – The client should have the ability to cache the responses.
4. Layered System – A layered system having multiple layers wherein each layer communicates
with the adjacent layer only.
5. Uniform Interface – A uniform interface design requires each component within the service
to share a single and uniform architecture.
6. Code on Demand – This constraint is optional. It extends client-side execution of code
transfer of executable scripts like javascript from the server.
REST ARCHITECTURE
5 Testing
• Unit Testing: Write unit tests for your endpoints to ensure they work as expected.
• Integration Testing: Test the integration between different parts of your API.
• Manual Testing: Use tools like Postman or curl to manually test your API endpoints.
6.Deployment
• Choose a Hosting Service: Deploy your API to a hosting provider such as AWS, Heroku,
or DigitalOcean.
• Environment Variables: Manage environment-specific configurations using environment
variables.
• CI/CD Pipeline: Set up Continuous Integration and Continuous Deployment (CI/CD) to
automate testing and deployment.
7. Monitoring and Maintenance
Monitor Performance: Use monitoring tools to keep track of your API’s performance and
health.
Update and Maintain: Regularly update your API to fix bugs, add features, and address
security vulnerabilities.
Effective communication between the front-end and back-end of a web application is crucial for a
smooth and functional user experience. Here’s a high-level overview of how this communication
typically works and some key considerations:
1. HTTP Requests and Responses
Front-End to Back-End: The front-end (client-side) sends HTTP requests to the back-end
(server-side) using methods like GET, POST, PUT, DELETE, etc. These requests are often
triggered by user interactions or application events.
Back-End to Front-End: The back-end processes these requests and sends back HTTP
responses, which may include status codes (e.g., 200 OK, 404 Not Found) and data in formats
like JSON or XML.
2. Data Formats
JSON (JavaScript Object Notation): The most common data format for communication. It
is lightweight and easy to parse, making it a preferred choice for APIs.
XML (eXtensible Markup Language): Less common today but still used in some
applications. It is more verbose compared to JSON.
Other Formats: Depending on the application, you might encounter formats like YAML,
Protocol Buffers, or even custom formats.
3. API Endpoints
RESTful APIs: Representational State Transfer (REST) is a common architectural style for
designing networked applications. It uses standard HTTP methods and provides a stateless
way to interact with resources.
GraphQL: An alternative to REST, GraphQL allows clients to request exactly the data they
need, which can reduce the amount of data transferred and simplify interactions.
WebSockets: For real-time communication, WebSockets provide a persistent connection
between the front-end and back-end, allowing for bi-directional data exchange.
4. Authentication and Authorization
Authentication: Ensuring that the user is who they claim to be. This is typically handled via
tokens (e.g., JWT - JSON Web Tokens) or session cookies.
Authorization: Ensuring that the authenticated user has permission to perform certain actions
or access specific resources. This often involves checking user roles or permissions on the
back-end.
5. Error Handling
Front-End Handling: The front-end should handle various error scenarios gracefully,
providing informative feedback to the user and possibly retrying requests or handling
different status codes.
Back-End Handling: The back-end should validate requests, handle errors internally, and
send appropriate status codes and messages in the response.
6. Performance Considerations
Caching: Implementing caching strategies (e.g., browser caching, server-side caching) to
improve performance and reduce unnecessary requests.
Rate Limiting: Preventing abuse by limiting the number of requests a user can make in a
given timeframe.
Compression: Reducing the size of responses (e.g., using gzip or Brotli) to speed up data
transfer.
7. Security
HTTPS: Ensuring all communication between front-end and back-end is encrypted.
Input Validation: Both front-end and back-end should validate input to prevent attacks such
as SQL injection or cross-site scripting (XSS).
CSRF Tokens: Protecting against Cross-Site Request Forgery attacks by including tokens in
requests.
8. Testing
Unit Tests: Testing individual components or functions.
Integration Tests: Testing interactions between front-end and back-end components.
End-to-End Tests: Simulating real user scenarios to ensure the entire system works as
expected.
What is ORM?
JPA allows developers to map Java objects to database tables and vice versa using annotations or
XML configuration files. This abstracts the complexities in converting data between its object-
oriented form in the application and its relational form in the database.
JPA is not an implementation but a specification. Various ORM tools, such as Hibernate,
EclipseLink, and Apache OpenJPA, provide implementations of the JPA specification. This allows
developers to switch between these implementations if needed without changing the application
code that uses JPA.
Hibernate is the most popular JPA implementation and one of the most popular Java ORM
frameworks. Hibernate is an additional layer on top of JDBC and enables you to implement a
database-independent persistence layer. It provides an object-relational mapping implementation
that maps your database records to Java objects and generates the required SQL statements to
replicate all operations to the database.
Example: The diagram below shows an Object-Relational Mapping between the Student Java
class and the student's table in the database.
Figure 1. This illustrates one way to conceptualize the MVC application architectural design pattern
model.
The controller handles all user interaction, such as when the user clicks a button or selects a value
from a list. The controller also feeds data to the view component in response to user requests. In
addition, the controller interfaces with the model component, which sends updated data to the view
element. The view component is concerned only with rendering the data provided by the controller,
model or both.
In this linear approach, users interact solely with the view element through a browser, the view
interacts solely with the controller and the controller interacts solely with the model.
Each development team may have its own interpretation of how MVC should be implemented. If
it's using an MVC framework, it might also need to work around how the framework structures an
application. The important point is that the team adheres to the SoC principle when designing and
building its applications, with each component responsible for a discrete set of tasks.