Search This Blog

Thursday 15 December 2016

Difference between PATH and CLASSPATH in Java

Here are some of the common difference between PATH vs CLASSPATH in Java :



1) PATH is an environment variable which is used to locate JDK binaries like "java" or "javac" command used to run java program and compile java source file. CLASSPATH, an environment variable is used by Java to locate and load compile Java bytecodes stored in the .class file.

2) In order to set PATH in Java, you need to include JDK_HOME/bin directory in PATH environment variable while in order to set CLASSPATH in Java you need to include all those directories where you have put either your .class file or JAR file which is required by your Java application.

3) Another significant difference between PATH and CLASSPATH is that PATH can not be overridden by any Java settings but CLASSPATH can be overridden by providing command line option -classpath or -cp to both "java" and "javac" commands.



4) PATH environment variable is used by operating system to find any binary or command typed in the shell, this is true for both Windows and Linux environment while CLASSPATH is only used by Java ClassLoaders to load class files.


These are some notable difference between PATH vs CLASSPATH in Java.
How to set PATH and CLASSPATH in Windows and Unix
Use command prompt in Windows or shell in Linux to set PATH and CLASSPATH . Both PATH and CLASSPATH are environment variable and can be set using 
set keyword in DOS and Windows and export command in Linux

Command to set PATH in Windows

set PATH=%PATH%;C:\Program Files\Java\JDK1.6.20\bin

Command to set PATH in UNIX/Linux

export PATH = ${PATH}:/opt/Java/JDK1.6.18/bin

In Linux use a colon(:) as a 
separator and in Windows use semi-colon(;) as a separator.

Command to set CLASSPATH in windows

set CLASSPATH=%CLASSPATH%;C:\Program Files\Java\JDK1.6.20\lib

Command to set CLASSPATH in Unix/Linux

export CLASSPATH= ${CLASSPATH}:/opt/Java/JDK1.6.18/lib





Saturday 10 December 2016

What Are RESTful Web Services

Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as performance, scalability and modifiability that enable services to work best on the Web.
In the REST architectural style, data and functionality are considered resources and are accessed using Uniform Resource Identifiers (URIs), typically links on the Web.
It revolves around resource where every component is a resource and a resource is accessed by a common interface using HTTP standard methods. In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.
In REST architecture, a REST Server simply provides access to resources and REST client accesses and presents the resources. Each resource is identified by URIs/ global IDs. REST uses various representations to represent a resource like text, JSON and XML.  JSON is the most popular format being used in web services.
The following principles encourage RESTful applications to be simple, lightweight, and fast:
·         Resource identification through URI: A RESTful web service exposes a set of resources that identify the targets of the interaction with its clients. Resources are identified by URIs, which provide a global addressing space for resource and service discovery.
·         Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE. PUT creates a new resource, DELETE is used to remove a resource. GET retrieves the current state of a resource. POST is used to update an existing resource.
·         Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others.

·         Stateful interactions: Every interaction with a resource is stateless. It is responsibility of the client to pass its context to server and then server can store this context to process client's further request.  Stateful interactions are based on the concept of explicit state transfer. Several techniques exist to exchange state, such as URI rewriting, cookies, and hidden form fields. State can be embedded in response messages to point to valid future states of the interaction. 

Wednesday 7 December 2016

Dependency Injection

Dependency Injection

Dependency Injection is a software design pattern that implements inversion of control for resolving dependencies. A dependency is an object that can be used. An injection is the passing of a dependency to a dependent object that would use it. The service is made part of the client's state. Passing the service to the client, rather than allowing a client to build or find the service, is the fundamental requirement of the pattern.
Dependency injection allows a program design to follow the dependency inversion principle. The client delegates the responsibility of providing its dependencies to external code. The client is not allowed to call the injector code. It is the injecting code that constructs the services and calls the client to inject them. This means the client code does not need to know about the injecting code. The client does not need to know how to construct the services. The client does not need to know which actual services it is using. The client only needs to know about the intrinsic interfaces of the services because these define how the client may use the services. This separates the responsibilities of use and construction.
There are three common means for a client to accept a dependency injection: setter-, interface- and constructor-based injection.
·         Constructor Injection: the dependencies are provided through a class constructor.
·         Setter Injection: the client exposes a setter method that the injector uses to inject the dependency.
·      Interface Injection: the dependency provides an injector method that will inject the dependency into any client passed to it. Clients must implement an interface that exposes a setter method that accepts the dependency.

 


Advantages

·         Dependency injection allows a client the flexibility of being configurable.
·         Dependency injection can be used to externalize a system's configuration details into configuration files allowing the system to be reconfigured without recompilation. Separate configurations can be written for different situations that require different implementations of components. This includes, but is not limited to, testing.
·         Because dependency injection doesn't require any change in code behavior it can be applied to legacy code as a refactoring.
·         This ease of testing is often the first benefit noticed when using dependency injection.
·         Dependency injection allows a client to remove all knowledge of a concrete implementation that it needs to use. This helps isolate the client from the impact of design changes and defects. It promotes reusability, testability and maintainability.
·         Reduction of boilerplate code in the application objects, since all work to initialize or set up dependencies is handled by a provider component.
·         Dependency injection allows concurrent or independent development. Two developers can independently develop classes that use each other, while only needing to know the interface the classes will communicate through. 
·         Dependency Injection decreases coupling between a class and its dependency.

 

Disadvantages

·         Dependency injection can make code difficult to trace (read) because it separates behavior from construction. This means developers must refer to more files to follow how a system performs.
·         Dependency injection forces complexity to move out of classes and into the linkages between classes which might not always be desirable or easily managed.
·         Ironically, dependency injection can encourage dependence on a dependency injection framework.


Monday 5 December 2016

What is MVC architecture in J2EE

MVC stands for Model-View-Controller architecture. It promotes loose coupling between components by separating the functionality of displaying and maintaining of the data. It is often used by applications that need the ability to maintain multiple views like HTML, WML, Swing, XML based Web service etc. Multiple views and controllers can interface with the same model. Even new types of views and controllers can interface with a model without forcing a change in the model design.

To summarize the MVC does the following
  • Separation of Model from View components makes it possible to implement several user interfaces that reuse the common core business logic.
  • Duplication of low-level Model code is eliminated across multiple UI implementations.
  • Decoupling of Model and View code results in an improved ability to write unit tests for the core business logic code.
  • Modularity of components allows core logic developers and UI developers to work simultaneously without affecting the other.

  
A model represents the core business logic and state. A model commonly also maps to data the database and will also contain core business logic.
  • Manages the app data and state
  • Not concerned with UI or presentation
  • Often persists somewhere
  • Same model should be reusable, unchanged in different interfaces

  
A view renders the contents of a model. A view accesses the data from the model and adds display logic to present the data. 
  • Present the Model to the user in an appropriate interface
  • Allows user to manipulate data
  • Does not store any data.
  • Easily reusable & configurable to display different data


A controller acts as the glue between a model and a view. A controller translates interactions with the view into actions to be performed by the model. User interactions in a Web application appear as GET and POST HTTP  requests. The actions performed by a model include activating business processes or changing the state of the model. Based on the user interactions and the outcome of the model actions, the controller responds by selecting an appropriate view.
  • Intermediary between Model & View
  • Updates the view when the model changes
  • Updates the model when the user manipulates the view
MVC pattern decouples how data is manipulated from how data is displayed or stored. MVC is a way of developing apps by keeping the data (model) used in the program, and the visual (view) component separate from one another, each interacting only with a controller containing the logic. The view and the model interact only with the controller NEVER with each other.
MVC
MVC

Saturday 3 December 2016

How to enter Current Dates and Times in Excel?

To enter the current date and time , select a cell and in the cell enter =NOW()
To enter the current Date in excel, select a cell and in the cellr =TODAY()

The dates and/or times will be automatically updated when the sheet is updated or reopened.

To insert a fixed date, select a cell, and Press [Ctrl] + [;]
To add a fixed time, Press [Ctrl] + [Shift] +[;]


For above 2 the dates and/or times will NOT be automatically updated when the sheet is updated or reopened.


Excel Dates Tips
Excel Dates