0% found this document useful (0 votes)
17 views21 pages

Unit 1-FSD

Full stack development

Uploaded by

rickyvanith7
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)
17 views21 pages

Unit 1-FSD

Full stack development

Uploaded by

rickyvanith7
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/ 21

Unit 1

Introduction to Full Stack Development

What is full stack development?

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.

What are the benefits of full-stack development?


Organizations adopting full-stack development strategies experience the following benefits.
Efficient resource utilization
Traditional setups require separate developers for frontend, backend, database management, and
sometimes even for server operations. Full-stack developers are adept at handling multiple aspects of
a project, from user interface design to server-side scripting and database management. This
significantly reduces the number of specialized roles that an organization needs to fill, making project
management simpler and more streamlined. A full-stack developer can communicate with both
frontend and backend web development teams to organize and manage client software development.
Fewer developers often translate to easier coordination among team members, simplified management
structures, and a unified project vision.
Flexibility and speed
Full-stack developers have the skills to create minimum viable products (MVPs) at a much faster rate,
given their ability to handle all layers of application development. This is particularly beneficial in
agile or lean development frameworks where rapid iteration is key. The ability to make frontend and
backend changes simultaneously reduces time to market, allowing organizations to adapt to market
needs and capitalize on business opportunities ahead of competitors.
Enhanced problem-solving
The ability to identify problems across a project is enhanced when you have full-stack developers on
board. Their comprehensive understanding of the system architecture and multiple coding languages
enables them to identify bottlenecks, conflicts, or inefficiencies that specialized developers might
miss. They can also switch easily between frontend and backend development.
What are the technologies used in full-stack development?

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.

The most common frontend languages are:


Hypertext Markup Language (HTML)
Cascading Style Sheets (CSS)
JavaScript
HTML allows you to structure web pages and the content on them. You use CSS to style the content,
creating more comprehensive layouts or structures. Finally, JavaScript lets you add interactive
features to a webpage, creating dynamic content for users.

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.

You can group backend technology into three sub-layers:


API layer
The API layer receives interactions from the frontend and then communicates these to the storage
layer. This layer acts as a bridge between the frontend and the backend.

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 )

 Why is Java 11 important ?


 Java 11 is the second LTS release after Java 8. Since Java 11, Oracle JDK would no
longer be free for commercial use.
 You can use it in developing stages but to use it commercially, you need to buy a
license. If you don’t, you can get an invoice bill from Oracle any day!
 Java 10 was the last free Oracle JDK that could be downloaded.
 Oracle stops Java 8 support from January 2019. You’ll need to pay for more support.
 You can continue using it, but won’t get any patches/security updates.

 We can run the Java program without compilation.


 From Java 11 we just run the program no need to compile separately. The Java
command itself will compile internally.
 Java Test.java

 String Enhancements:
 repeat(int): This methos can be called on string object, it returns the given string
object for the mentioned int number.

Out put is:

 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

What is the difference between strip() and trim();

 trim() removes only characters <= U+0020 (space); strip() removes all
Unicode whitespace characters (but not all control characters, such as \0)

 However, the strip() method uses Character.isWhitespace() method to check if the


character is a whitespace. This method uses Unicode code points whereas trim()
method identifies any character having codepoint value less than or equal to
‘U+0020’ as a whitespace character.
 The strip() method is the recommended way to remove whitespaces because it uses
the Unicode standard.
 Refer to link https://bugs.openjdk.org/browse/JDK-8200373
 String::trim has existed from early days of Java when Unicode had not fully evolved
to the standard we widely use today.
 The definition of space used by String::trim is any code point less than or equal to the
space code point (\u0020), commonly referred to as ASCII or ISO control characters.

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).

Lines example with \ r symbol


Lines example with \ n symbol

 Collection Enhancements in Java 11:


toArray(): In Java 11 new default method has been introduced in collection interface.

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.

 Here third parameter is


StandardOpenOption.Append -> This will append the text to the data that is
already present in the file. The append will happen at the end of the data in the file
Example: in the contact.txt -> the file contains Test as word then output of the
WriteString above method is shown below
If you open the file then below content is shown

>This StandardOpenOption.CREATE - method will override the content that is


present in the mentioned file.

Document after the operation:

The below is the other way of creating the file using createTempFile method
Path path = Files.writeString(Files.createTempFile(“test”, “.txt”), “Java 11 features”);

➢ Local Variable Declaration for Lamda:


 Java 11 adds the support for Local-Variable syntax for lambda expressions. Lambdas can
infer the type, but using the var keyword allows us to use annotations like @NotNull or
@Nullable with the parameters.
 (@NotNull var str) -> "$" + str
 In order to mention the local variable we can use var.
 In Java 10, Local-variable type-inference was introduced.
 It allows us to use var as data type of local variable instead of actual data type. (Example:
var x=10)
 Local variable are those variables, which are defined inside a particular block of code like
method, constructor and init blocks
 We cannot use this var for the method parameter, constructor parameter
 This var should be initialized where it is declared
 Java compiler infers the data type based on the value assigned to the variable. Example:
void m1(){
String x="ABC"
Int y=10;
} //Here in the above m1 method compiler knew that x is String type and y is int type

Same method we can like below from java 10.


void m1(){ var
x="ABC"
Var y=10; // here by looking at the 10 compiler understand sthat it takes int value but
late you can re initialize this y with another int value like below
y=25 but not you cannot change the type (y="A")
}//The difference here is that instead of specifying the data type, by assigned value
compiler will understand infer the data type.

 Here when we use local variable like var-> Initialization is mandatory.


 From Java 11 the new feature is we can declare this local variable var In lamda expression

(var s1, s2) - > s1 + s2 //no skipping allowed

(var s1, String y) - > s1 + y //no mixing allowed

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.

 Predicate Interface Changes:


 The not() Method
A static not() method has been added to the Predicate interface in Java 11. As the name
suggests, this method is used to negate a Predicate. The not() method can also be used with
method references.
 Predicate.not() is a static method which is introduced in Java 11 to negate the supplied
Predicate
 Syntax of not method of predicate interface

This not() static method is taking the predicate as input and returning the negate
[predicate as output. Internally it is calling the negate() method

Before Java 11 : Negating The Predicate


This is the implementation before Java 11

Using the same example with the Predicate.not() 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

• Following are the steps to use an HttpClient.


• Create HttpClient instance using HttpClient.newBuilder() instance
• Create HttpRequest instance using HttpRequest.newBuilder() instance
• Make a request using httpClient.send() and get a response object
 Nested Based Access

 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.

RESTful Web services or REST API:

• 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.

RESTful APIs implements the following types of HTTP methods-

• GET – HTTP GET method retrieves some information.


• POST – HTTP POST method submits and creates new resources.
• PUT – HTTP PUT updates an already existing resource.
• DELETE – HTTP DELETE deletes a resource.

REST ARCHITECTURE

Steps in creating REST API

1. Planning and Designing


Define Objectives: Understand the purpose of your API. What problem does it solve?
Who is the target audience?
Identify Resources: Determine the resources (data entities) that your API will handle. For
example, if you're creating an API for a library, resources might include books, authors,
and patrons.

2. Setting Up the Development Environment

• Choose a Programming Language: Select a language you’re comfortable with or one


that is well-suited for building APIs. Common choices include JavaScript (Node.js), Python,
Ruby, Java, and PHP.
• Select a Framework: Use a framework that simplifies API development. For example:
• Node.js: Express.js
• Python: Flask or Django REST Framework
• Ruby: Rails
• Java: Spring Boot
• Install Dependencies: Install necessary libraries or packages for your chosen language and
framework.

3. Building the API


. Initialize the Project
• Create Project Directory: Set up your project directory and initialize it.
• For instance, with Node.js, you might run npm init to create a package.json file.
b. Create Endpoints
• Set Up Routing: Define routes for your endpoints.
For example, with Express.js

const express = require('express');


const app = express();
app.use(express.json());
app.get('/books', (req, res) => {
// Code to handle GET request
});
app.post('/books', (req, res) => {
// Code to handle POST request
});
app.get('/books/:id', (req, res) => {
// Code to handle GET request for a specific book
});
app.put('/books/:id', (req, res) => {
// Code to handle PUT request
});
app.delete('/books/:id', (req, res) => {
// Code to handle DELETE request
});
app.listen(3000, () => {
console.log('Server is running on port 3000');});
4. Implement Logic
• Data Handling: Implement logic for CRUD operations (Create, Read, Update, Delete) for
each endpoint.
• Database Integration: Connect your API to a database (e.g., MongoDB, MySQL,
PostgreSQL) to store and retrieve data.
• Validation: Validate incoming data to ensure it meets the expected format and constraints.
• d. Error Handling and Logging
• Handle Errors: Implement error handling for invalid requests and server errors.
• Logging: Set up logging to track requests, errors, and other important events.

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.

Communication Between Front-End and Back-End

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?

ORM (Object-relational mapping) is a programming technique for mapping application domain


model objects to relational database tables. Hibernate is a Java-based ORM tool that provides a
framework for mapping application domain objects to relational database tables and vice versa.

What is the Java Persistence API (JPA)?


he Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data
between Java objects/classes and a relational database. JPA acts as a bridge between object-
oriented domain models and relational database systems, making it easier for developers to work
with data in their applications.

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.

What is the Hibernate Framework? (More about this in Unit -IV)


Hibernate is a Java-based ORM tool that provides a framework for mapping application domain
objects to relational database tables and vice versa.

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.

What is model-view-controller (MVC)?


In programming, model-view-controller (MVC) is an architectural design pattern that organizes an
application's logic into distinct layers, each of which carries out a specific set of tasks. The layers also
interact with each other to ensure that the application's functionality is delivered in a coordinated and
consistent manner. The MVC methodology incorporates the entire application, from the user interface
(UI) to the underlying data model.
The MVC system, which originated in the 1970s in connection with building graphical UIs, is widely
used in program development, especially for today's web applications and object-oriented
programming (OOP). Developers use a range of programming languages,
including Java, Python, JavaScript, C#, Swift, Perl and PHP, to build applications based on MVC.
Most of these languages also have MVC frameworks available to them to help streamline the
development process. Popular MVC frameworks include Django, Ruby on Rails, Symfony, Catalyst
and CherryPy, among many others.
MVC offers development teams important benefits. Programmers can
build components simultaneously without stepping over each other's work, and they can reuse
components. They can also deploy and maintain the components independently from others. MVC
makes it easier to build large, complex applications, leading to faster, more efficient development
efforts. In addition, MVC supports test-driven development, while making it possible to test and
troubleshoot components individually.

MVC design layers


The MVC methodology separates an application's logic into three distinct layers:
1. Model. The model layer is responsible for the application's data logic and storing and
retrieving data from back-end data stores. The model layer might also include mechanisms for
validating data and carrying out other data-related tasks. This layer is responsible for
maintaining all aspects of the data and ensuring its integrity and accessibility.
2. View. The view layer provides the UI necessary to interact with the application. It includes
components needed to display the data and enables users to interact with that data. For
example, the view layer might include buttons, links, tables, drop-down lists or text boxes.
3. Controller. The controller layer contains the application logic necessary to facilitate
communications across the application, acting as an interface between the view and model
layers. The controller is sometimes viewed as the brains of the application, keeping
everything moving and in sync.

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.

You might also like