Configuring Spring

Why would you need to configure Spring project?

Configuring enables a developer to achieve loose coupling in a project. You wouldn’t want a project to break when you need to make changes to it. For example, Honda gets its parts from different companies. Tires from Goodyear, stereo from Boss etc… But one day, Honda has a fight with Goodyear because their tires aren’t that good anymore. Now Honda needs a new company to provide tires. If the project was loosely coupled, all you have to change is the dependent(tires) and inject it into the program. So swap the tires in the configuration file with another company /*I don’t know any tire companies*/. That’s Dependency Injection!

Beans

bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container.

Configuring using Java Annotations

Java Annotations are a modern way of configuring Spring Application. They are, in short, meta-data about a class or Special labels added to Java classes. They are processed at compile time or runtime for special processing.

Examples of Java Annotations

@Override

Benefits of Java Annotations

XML configurations can be very verbose. In XML config file, every bean must be listed and if your project contains a large number of beans, it will be too much work

Spring beans can be configured using annotations

Annotations minimizes the XML configurations

Spring will scan your java classes and automatically register the bean into a spring container.

Configuring using Java code

Development Process

  1. Create a java Class and annotate as @Configuration
  2. Add component scanning support: @ComponentScan (Optional)
  3. Read Spring Java configuration class
    SpringAnnotationContext context = new SpringAnnotationContext(SpringAnnotationApplication.class)
  4. Retrieve bean from Spring container
    Use the getBean method

Defining a Bean with Java code

  1. Define the methods to expose the bean by @Bean
  2. Inject bean dependencies
  3. Read the Spring Java Configuration class
    SpringAnnotationContext context = new SpringAnnotationContext(SpringAnnotationApplication.class)
  4. Retrieve bean from Spring Container
    Use the getBean method

Auto-wiring

For dependency Injection, Spring can use spring auto wiring. The way auto-wiring works is that Spring will look for a class that matches the property.
Matchers by type: class or interface
Spring will inject the dependency automatically so you, the programmer, don’t have to worry about extra boilerplate code.

How does auto-wiring work?

  • Spring will scan for @Components. The @Component is placed above the class that you want to be injected.
  • Place the @Autowired above a constructor.

Spring MVC

Spring MVC is a framework for building web application in java. It is based on Model-View-Controller design pattern.

Image result for spring mvc
This is how Spring MVC will process a web request

Front Controller delegates the requests to the controller
Controller contains the business logic
1. Handle the request
2. Store/retrieve data
3. Place data in model
And finally, send it to the appropriate view template

Benefits of Spring MVC

  1. Reusable UI Components
  2. Flexible configuration
  3. processes form data
  4. Helps manage application state for web requests

REST (REpresentational State Transfer)

What is the data format used in REST?

Mostly JSON is used but XML can also be used.

Important Things to Remember about REST

REST calls can be made over HTTP
REST is language independent which means that projects developed in any language can use APIs.

REST over HTTP

HTTP MethodCRUD Operation
POSTCreates a new entitiy
GETRead a list of entities or a single entity
PUTUpdate an existing entity
DELETEDelete an existing entity

Where can you find REST APIs?

A good place to start is http://www.programmableweb.com. Some APIs are free while other are paid. It’s a good way to start learning.

JSON Basics

  • It stands for JavaScript Object Notation
  • Its a lightweight data format for storing and exchanging data
  • Language independent so it can be used with any programming language

How to write JSON?

  • Curly braces define objects in JSON
  • object members are name & value pairs
  • Name is always in double quotes

JSON values

  • Numbers: no quotes || Ex: “id”: 49
  • String: double quotes || Ex: “Name” : “name”
  • Boolean: true, false || Ex: “Yes”: true
  • Array || Ex: “List”: [1,2,3,4]
  • Nested JSON objects
  • Null

Java JSON Data Binding

  • Data binding is the process of converting /mapping /serializing /marshaling JSON data to a Java POJO and vice et versa.
  • Spring uses Jackson project for data binding behind the scenes.
  • By default, Jackson will call the appropriate getter/setter methods whenever they are called.

JSON to Java POJO

When JSON needs to be converted to Java POJO, the setter methods will be called on POJO.

Java POJO to JSON

When Java POJO needs to be converted to JSON, the getter methods will be called on POJO.

How to ignore unknown properties?

The way you ignore properties that you just added into the JSON but your program doesn’t know about is you add an annotation
@JsonIgnoreProperties(ignoreUnknown=true)

SOAP Web Services

SOAP Web Service Specification

  • SOAP
  • WSDL
  • UDDI
  • SEI

SOAP

How two applications will talk to each other over the internet. The transfer or exchange of information must occur in xml format.

  • Structure of the message
  • Envelope
    • Header – provides info about the message
    • Body – contains the actual request

WSDL

Web Service Description Language – Service provider publishes an interface for his web services that describes all attributes of the web services. It has an XML interface. It is an interface for web service and the service provider creates the WSDL and the service consumer uses the web services.

UDDI

Universal Description, Discovery and Integration – An online registry/ directory where all the web service providers publish their services and consumer can access that WSDL.

SEI –

References

Application Layer of the Internet

Today we will be talking about the application layer. Below are a few of the services provided by the Application layer.

  • The application layer provides services for an application program to ensure that effective with communication another application program on a network is possible
  • The application layer is a component within an application that controls the communication method to other devices
  • It’s an abstraction layer service that masks the rest of the application from the transmission process.
  • The application layer relies on all the layers below it to complete its process. At this stage, the data, or the application, is presented in a visual form the user can understand.

A few protocols used in the Application layer

TELNET

Telnet stands for the TELecomunications NETwork. It helps in terminal emulation. It allows Telnet client to access the resources of the Telnet server. It is used for managing the files on the internet

FTP

FTP stands for file transfer protocol. It is the protocol that actually lets us transfer files. It can facilitate this between any two machines using it. But FTP is not just a protocol but it is also a program. FTP promotes sharing of files via remote computers with reliable and efficient data transfer

DHCP

It stands for Domain Name Service. Every time you use a domain name, therefore, a DNS service must translate the name into the corresponding IP address

DNS

It stands for Domain Name Service. Every time you use a domain name, therefore, a DNS service must translate the name into the corresponding IP address

HTTP

HTTP means HyperText Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web and this protocol defines how messages are formatted and transmitted, and what actions Web servers and browsers should take in response to various commands.

What Happens when you type a URL into the Web Browser?

When you type a URL into a web browser, this is what happens:

  1. If the URL contains a domain name, the browser first connects to a domain name server and retrieves the corresponding IP address for the web server.
  2. The web browser connects to the web server and sends an HTTP request (via the protocol stack) for the desired web page.
  3. The web server receives the request and checks for the desired page. If the page exists, the web server sends it. If the server cannot find the requested page, it will send an HTTP 404 error message. (404 means ‘Page Not Found’ as anyone who has surfed the web probably knows.)
  4. The web browser receives the page back and the connection is closed.
  5. The browser then parses through the page and looks for other page elements it needs to complete the web page. These usually include images, applets, etc.
  6. For each element needed, the browser makes additional connections and HTTP requests to the server for each element.
  7. When the browser has finished loading all images, applets, etc. the page will be completely loaded in the browser window.

References

https://www.informit.com/articles/article.aspx?p=169578

http://www.theshulers.com/whitepapers/internet_whitepaper/index.html

BootStrap Classes

list-unstyled
list-inline-item

blockquote
blockquote-footer – for names

text-danger
bg-danger

img-fluid
img-thumbnail

float-left/right
figure-caption

container
container-fluid – the container is responsive to the viewport
row
column – splits the content into columns

section
div
/div
section

order – orders the way the colums are arraged

align-items-start ———row
align-self-start ————column
justify-content-start——row——-horizontal Alignment

position

d-flex
d-flex flex

align
align-self

Margin and Padding

Visibility

  • invisible
  • visible

Sizing (size-amt)

  • w , h , mw , mh , vw , vh , min-vw , min-vh
  • 25 , 50 , 75 , 100 , auto

Borders (side-col) & Rounded (side-shape-size)

  • top , right , bottom , left
  • colors
  • top , right , bottom , left
  • circle , pill
  • 0 , sm , lg

Buttons

  • btn-color
  • btn-outline-color

JavaScript Variables and Types

Numbers

All the numbers like ints, floats, double are under the data type number in java script.
Math functions are function that can be performed by java script
For example: Math.round(number) or Math.random

Strings – Methods

Strings are an array of character, basically a word or a sentence. Many methods can be performed with Strings. Here are a few:
– myString.toUpperCase
– myString.toLowerCase

Booleans

  • True
  • False
  • Can be used to compare Strings and Numbers

References

JavaScript Syntax

Keywords

var is used to declare variables

//………. or /*………/* is used for comments

All JavaScript identifiers are case sensitive

lower case Camel case is widely used by JavaScript programmers

Operators

+Addition
Subtraction
*Multiplication
**Exponentiation
/Division
%Modulus (Division Remainder)
++Increment
Decrement

JavaScript Function syntax

A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().
Example:
function name (parameters){
Code…………………..}

Objects

var person = {
  firstName: “John”,
  lastName: “Doe”,
  age: 50,
  eyeColor: “blue”
};
Every objects has a nam

Accessing Objects in JS

objectName.propertyName or objectName[“propertyName”]
can be used to call the

References

https://www.w3schools.com/js/default.asp

Design a site like this with WordPress.com
Get started