Thursday, March 22, 2018

Maven and Spring Boot Basics

Hello Everyone,

By this post I will talk about what maven is and it's uses along with depth knowledge about Spring Boot.

Let's first talk what maven is.........

Maven automates downloads dependencies, putting additional jars on a class path, compiling source code into binary code, running tests, packaging compiled code , minimizing the risk of humans making errors while building the software manually and separating the work of compiling and packaging our code from that of code construction.

Inorder to check whether your computer has installed with maven check below command,



What is a POM?

A Project Object Model or POM is the fundamental unit of work in Maven.It is XML format which contain all the dependencies and configuration details project need to process and get build.



Few commands that maven uses
  • mvn clean       - previously generated artifacts will be removed
  • mvn compile   - compile source code
  • mvn package   - bundle is created
  • mvn install      - package is copied to local repo
  • mvn deploy     - final package is copied to remote repo
  • mvn test          - testcases are executed


Before talking about Spring Boot let's talk about spring framework......

Spring is a lightweight framework which act as a framework of frameworks. It provides support to various frameworks such as Struts, Hibernate, Tapestry, EJB, JSF etc. The framework is used to find solution to the various technical problems.

The Spring framework comprises several modules 


  • IOC
  • AOP
  • DAO
  • Context
  • ORM
  • WEB MVC 

What is a Dependency Injection (DI)?

By the name it gives you the maening. Dependencied are injected to classes rather than allowing them to have links to other classes.
This reduces coupling between each classes. DI is a specific type of Inversion Of control(IOC)


 Figure 1

 Figure 2


In figure 1 there is a tight coupling between address and student.If the address class get changed, the student class also need to be changed.But in figure 2 Address Object is passed to the constructor to set the value which reduces the coupling between the address and student.

DI can be achieve through using 3 methods.

● Setter Based
@Autowired
public void setName(StudentService sv){
this.name=sv;
}


● Constructor Based
@Autowired
public Student(StudentService sv){
this.student=sv;
}


● Fields
@Autowired
private CacheMonitor cache;


Now let's talk about what Spring Boot do...

Why to use Spring Boot?

Though Spring is a good framework, It is hard to configure and manage the code while it takes some time to bootstrap the project. But by using Spring Boot we can minimize those drawbacks.Integration of the 3rd party libraries are highly supported by Spring Boot. Presence of integrated server to run the application also provides Spring Boot more special.

Starters can be downloaded from the Spring Boot website easily.Below are some starters used by spring boot..


  • spring-boot-starter-security 
  • spring-boot-starter-web-services
  • spring-boot-starter-integration
  • spring-boot-starter-validation
  • spring-boot-starter-actuator

First Spring Boot Code

Bootstrapping the application.



By using run method, Spring Boot server gets started.By annotation @SpringBootApplication we tells to the application that we want to run the application using spring boot.

Let's see how Rest controller can be used with spring boot..



Using the browser we can navigate to the localhost and relevant port number we can get the output as hello world.This is the base of building large web services.

Let's meet again with another exiting post.Happy coding :)

©Copyright Viraj Wickramasinghe.

Monday, March 12, 2018

NodeJS Basics I

Hello Everyone,
By this post you will be able to understand the basic stuff about NodeJS.
Firstly I will introduce what NodeJS is,

Node.js is a very powerful JavaScript-based framework.Platform was built on Google Chrome's JavaScript V8 Engine. Node.js is a server side scripting language which is mostly used for back end of the application.

In order to see whether node.js is successfully installed in your machine, use the following commands.




Basic Hello World Program


Using the require directive I have used the http module and returned an instance of it.Instance of server is created from createServer method and in the body 'Hello World' is printed.By using listen keyword, we define that server runs on that port number and output will be available in that port number.After connection is successfully established, console log statement will be executed in the console.

In order to run the node.js file, first open a terminal in the directory where your js file exists.




Output to the console

Reading a File

Now Let's look at some of the capabilities node.js has. It has the ability to read files in either synchronous way or asynchronous way.When both forms are present, node.js tends to read in the synchronous way first.



To read files node file system module is required.It is represented as fs in node.js. In here read.txt is an external file which contains some content which is read by node application. Below is the read.txt file.



Asynchronous reading takes callback function with 2 parameters err and data.First parameter is used to represent any errors that can occur while reading and data parameter is used to state the completion of the function.
In synchronous reading readFileSync keyword is used where no callback functions is used.In general Asynchronous reading is more approprite than synchronous reading where no blocks can occur in the reading process.


Output to the console




Writing a File

In here we over write the existing file using writeFile method.First parameter is said to be the file name where we want to write the content and second parameter is the content that we want to write to the file and at third we use call function with err as the parameter to display any errors that can occur during writing.




Output to the console







Let's meet again with another exiting post.Happy coding :)

©Copyright Viraj Wickramasinghe.

Saturday, March 3, 2018

JavaScript Basics II

Hello Everyone,

This is the continuation of my 1st JS Basics post, In this post I will talk about Inheritance hierarchy with Prototyping objects and What Closure is?

Let's first talk about how inheritance is implemented using JS... 



In here Car extends from Vehicle class.Drive is a prototype object of class Vehicle.For the car to use that object, Car creates a object from Vehicle prototype and access the drive method of Vehicle using car.drive().

In here if we set this.model = model inside Car function as Vehicle('car'), property will be set to car in DOM(Document Object Model) but it gives an undefine case in the console.


Also when we use Vehicle.call(this, 'car') console will give the output as Car but DOM gives a no type scenario.

As prototypes doesn't inherit properties of parent class Vehicle, console.log(car.type) is undefined.

Output to the console




What is a Closure?

Closure is refers to as function which invokes/returns another function.Simply function inside another function.Let's simplifies this by using an example.





In here printAmount is the main function and I have written another function inside of that function print() which prints percentage calculation.That function is equals to a variable which returns from main function.

Then printAmount function is called from outside which execute both the functions and prints the console.log part in the sub function.

Output to the console





Let's meet again with some indepth about Node.js in the next post.


©Copyright Viraj Wickramasinghe.

Saturday, February 24, 2018

JavaScript Basics I

Hello Everyone,

I am writting this post to express the knowledge that got through learning Javascript in my AF module in the university.
Firstly I will introduce what Javascript(JS) is,
  • JS is a programming language which is used add some client side validations to static HTML pages.
  • It is an interpreted language
  • It uses nIO(non blocking IO) to avoid concurrency issues
  • Nowadys there several JS frameworks namely AngularJS, ExpressJS, NodeJS, ReactJS are some.

Simplest of JS code For a beginning


In HTML code we define <script> tag where all the JS codes are written in between those tags

Lets Learn more basic stuff about JS



In here we defines a object from function using new keyword and initialize with parameter. If we use var.marks instead of this.marks we cannot access marks outside of the function as var has local scope.


Output to the console



Next we'll talk about an another interesting feature JS process i.e. Prototyping. Prototyping is refers to as referring different object inside of  a function.
Let's simplifies this using an example.




In this code when the function is already defined we cannot add more behaviours. So in order to add more behaviors we use prototype objects.If we try add behavior using Student.id it will be an undefined case.So to avoid these prototype object can be used.Also prototype objects can be used to add new methods objects constructors.
               

Output to the console



I hope you guys learnt something from this.Hope to see you in the 2nd part of this which talks about inheritance and prototyping together.See you in that.


©Copyright Viraj Wickramasinghe.

Saturday, February 17, 2018

First Post in the Blog

Hello Everyone,
I am writting this blog to express the technicle stuff to the readers of this blog and as well as an assignment in my university.
In here I will talk about varieties of different technologies that I am going to learn with the practical explations.As a start I will give an overview of the 2nd Year final group project which was done as an asssignment.

Supermarket Management System for Madusha Supermarket
The proposed project was to implement a Supermarket Management System for Madusha Supermarket. It enables to automate 8 main functions practiced in the supermarket namely,
  • ·         Sales Management
  • ·         Inventory Management
  • ·         Delivery Management
  • ·         Employee Management
  • ·         Vendor Management
  • ·         Service and Repair Management
  • ·         Installment and Treasury Management
  • ·         Loyalty and Promotion Management





Key Benefits
  1. Increase Efficiency and performance
It will directly affect to the every function of the system in a favorable manner. Most of the manual processes can be automated through the proposed system that leads to saves valuable time and cost.
  1. High Security
Due to having different access levels for different levels of employee, more security will be achieved by the important data. In case of corruptions in the system or hardware, no data losses will occur due to maintaining regular backups in the database. 
  1. Improve Productivity 
Through the efficiency employees can enhance their productivity and perform their relative works with more accurately and with less time more load of work could be completed with much ease.
  1. Higher Availability 
The data will be always available when it is needed. The Manager can be sure that he has the relevant data which is requested. And the manager can search the reports and refer them without wasting time in searching the reports which include in huge books. Ability of gaining a range of reports which analyses the business functions.
  1. Data Integrity 
Data is accurate and precise rather than doing all of the works manually. The probability of doing mistakes will be low. Employees can be sure about the information that he has.
  1. High Scalability
Ability of handling a range of various tasks with optimum functionalities. Including the main functionalities, the system will prompt the users with essential notifications which will help the business to take important decisions and to maintain a good level in the business.

Technologies used: C#, MySQL,Bunifu framework, Adobe Photoshop, WAMP, XAMPP. 


©Copyright Viraj Wickramasinghe.