Wednesday, February 5, 2020

Kubernetes. What and How?

Introduction

In this part of the workshop you are going to get Minikube running on your local computer.
We are using Minikube because that is the easiest way to demonstrate how kubernetes works and what we can do with it. Minikube is a tool that runs a single-node Kubernetes cluster in a virtual machine on your personal computer.
To be able to run minikube you also need to install Docker and kubectl.



Tasks

1. Install Minikube

Read the instructions on how to install Minikube here, on macOS the short version is:
$ brew install minikube
$ minikube start

Verify Minikube installation

You can verify that Minikube is up and running on your computer by running the following command:
$ minikube status

2. Install kubectl

In order to manipulate the Kubernetes cluster you need to install the official CLI client called kubectl.
Details about the installation can be found here
$ brew install kubectl
$ kubectl version --client

3. Install Docker

Docker can be downloaded here Verify the installation running:
$ docker ps

4. Verify all up and running

Verify that all the following commands returns correctly
$ kubectl version
$ docker version
$ minikube version

Saturday, December 21, 2019

jQuery Selectors

With jQuery you select (query) HTML elements and perform "actions" on them.

jQuery Syntax

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)
Examples:
$(this).hide() - hides the current element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements with class="test".
$("#test").hide() - hides the element with id="test".



:input$(":input")All input elements
:text$(":text")All input elements with type="text"
:password$(":password")All input elements with type="password"
:radio$(":radio")All input elements with type="radio"
:checkbox$(":checkbox")All input elements with type="checkbox"
[attribute]$("[href]")All elements with a href attribute
[attribute=value]$("[href='default.htm']")All elements with a href attribute value equal to "default.htm"
[attribute!=value]$("[href!='default.htm']")All elements with a href attribute value not equal to "default.htm"
[attribute$=value]$("[href$='.jpg']")All elements with a href attribute value ending with ".jpg"


HTML manipulation
DOM manipulation
CSS manipulation
Event Handling
AJAX
Effects
Animation
Widgets


builtin objects
browser object
user defined objects
document objects





Spring Boot with React


Saturday, March 24, 2018

How to setup and start working on Postgres


These steps are for mac users. Though steps are common for other OS except installation process.


Install Postgres
--------------------
brew install postgres(Only for Mac OS)

Check Postgres Installed
--------------------------------
postgres -V

Initialise Postgres
-----------------------
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

To check status
---------------------
pg_ctl -D /usr/local/var/postgres status

To enter postgres command line
-----------------------------------------
psql postgres

Create User/Role
--------------------
There are 2 ways to do this:

1. Postgres has a shell command called createuser which will create a user for Postgres. Use it right from the OSX terminal command line like this:
createuser --pwprompt demouser; 
If you wish to create a user without a password just take the --pwprompt off the command.

2.  From postgres command line console:
CREATE ROLE demouser WITH LOGIN PASSWORD '12345'; 

Create Db and assign access to user
-------------------------------------------------
There are 2 ways to do:

1. createdb -Odemouser -Eutf8 myrecordDB;   
The -O indicates the user that will become the owner of the database.

2. create database demodb owner demoUser;

Access the Database 
-------------------------------
psql -U demouser -W bookstores;

The -U means to login using that username and the -W means to prompt for a password.

Create Table
-------------------
Now create table inside DB, Example:
CREATE TABLE demotable (did integer, name varchar(40), PRIMARY KEY(did));
CREATE TABLE demotable (did integer PRIMARY KEY, name varchar(40));

Other Useful commands
---------------------------------
To check roles/user present in postgres:
\du

To login 
psql -d mydb -U myuser


To connect to db
\connect <databasename>


To see database
\l  or \list 

To list tables in DB
\dt


To exit command line:
\q  

For Help
-------------
psql --Help

For further detail see documentation on Postgresql:

https://www.postgresql.org/docs/9.0/static/reference-client.html

Monday, January 1, 2018

Java 9 for Beginners

Modularity
Modularity is a general concept. In software, it applies to writing and implementing a program or computing system as a number of unique modules, rather than as a single, monolithic design.

The major change in Java 9 is the module System that has already been implemented in Java 9. The module system was introduced to make jdk scalable to smaller devices. The module system will provide application the capability to use only the jdk modules that are needed. The applications will no longer need the whole jdk framework. The module system will also encapsulate the public classes within a module. So a class defined public would not be available to the whole world until a module explicitly defines so. Because of this change the internal api e.g. com.sun.* of java will not be available anymore by default.

Simply put, the modules are going to be described in a file called module-info.java located in the top of java code hierarchy:

module me.aboullaite.java9.modules.car
{
requires me.aboullaite.java9.modules.engines;
exports me.aboullaite.java9.modules.car.handling;
}

Collection Factory methods


Before Java 9, it was possible to create an immutable view of the collections but only with some utility methods e.g. Collections.unmodifiableCollection(Collection<? extends T> c). For example, Let us create an immutable view of Collection in Java 8, with a one liner. This is the easiest way to do so in Java 8. It looks bad! isn't ?
Map<String, String> immutableMap = 
Collections.unmodifiableMap(
           new HashMap<String, String>() {{
             put("key1", "Value1");
             put("key2", "Value2");
             put("key3", "Value3");
         }});

Java 9 brings Now, something useful with the factory methods for creating immutable collections. Lets us now create the immutable Map in Java 9.
Map<String, String> immutableMap = Map.of("key1", "Value1", "key2", "Value2", "key3", "Value3");

Here are the examples of the factory methods:
    // empty immutable collections
    List<String> emptyImmutableList = List.of();
    Set<String> emptyImmutableSet = Set.of();
    Map emptyImmutableMap = Map.of();

    // immutable collections
    List<String> immutableList = List.of("one", "two");
    Set<String> immutableSet = Set.of("value1", "value2");
    Map<String, String> immutableMap = Map.of("key1", "Value1", "key2", "Value2", "key3", "Value3");


Improved Javadoc
Currently, if you want to find some class documentation you have to search in google. In Java 9 there are several improvements to the Javadoc and one of them is the addition of a search box.




Process API Improvements

So far there has been a limited ability for controlling and managing operating system processes with Java. For example, in order to do something as simple as get your process PID today, you would need to either access native code or use some sort of a workaround. More than that, it would require a different implementation for each platform to guarantee you’re getting the right result.

In Java 9, expect the code for retrieving Linux PIDs, that now looks like this:
    public static void main(String[] args) throws Exception
    {
    Process proc = Runtime.getRuntime().exec(new String[]{ "/bin/sh", "-c", "echo $PPID" });

    if (proc.waitFor() == 0)
    {
    InputStream in = proc.getInputStream();
    int available = in.available();
    byte[] outputBytes = new byte[available];

    in.read(outputBytes);
    String pid = new String(outputBytes);

    System.out.println("Your pid is " + pid);
    }
    }



To turn into something like this (that also supports all operating systems):

System.out.println("Your pid is " + Process.getCurrentPid());

The update will extend Java’s ability to to interact with the operating system: New direct methods to handle PIDs, process names and states, and ability to enumerate JVMs and processes and more.


Money and Currency API

After the new Date and Time API introduced in Java 8, Java 9 brings with it a new and official API for representing, transporting, and performing comprehensive calculations with Money and Currency. To find out more about the project, you can visit JavaMoney on Github. Code and usage examples are already available right here . Here are a few highlights:


Money amt1 = Money.of(10.1234556123456789, "USD"); // Money is a BigDecimal
FastMoney amt2 = FastMoney.of(123456789, "USD"); // FastMoney is up to 5 decimal places
Money total = amt1.add(amt2);


The new money types: Money & FastMoney

MonetaryAmountFormat germanFormat = MonetaryFormats.getAmountFormat(Locale.GERMANY);
System.out.println(germanFormat.format(monetaryAmount)); // 1.202,12 USD
Formatting money according to different countries


Diamond Operator Scope Extension

Java 7 gave us diamond operator to make our lives bit easier.In the below example you can see that java 7 list is more readable and concise.

List<String> preJava7 = new ArrayList<String>();
List<String> java7 = new ArrayList<>();

But Java 7 diamond operator was not allowed on anonymous classes.

But Java 9 has enhanced the Diamond operator to work even on anonymous classes. The below example will only compile in Java 9

List<String> list = new ArrayList<>(){ };


Private Methods in Interfaces



Java 8 allowed you to write default methods in interfaces, and it was widely appreciated feature. So after this, interfaces only lack few things and only non-private methods was one of them. Java 9 onward, you are allowed to include private methods in interfaces.
These private methods will improve code re-usability inside interfaces. Foe example, if two default methods needed to share code, a private interface method would allow them to do so, but without exposing that private method to it’s implementing classes.
Using private methods in interfaces have four rules :
1. Private interface method cannot be abstract.
2. Private method can be used only inside interface.
3. Private static method can be used inside other static and non-static interface methods.
4. Private non-static methods cannot be used inside private static methods.

interface InterfaceWithPrivateMethods {
private static String staticPrivate() {
return "static private";
}

private String instancePrivate() {
return "instance private";
}

default void check() {
String result = staticPrivate();
InterfaceWithPrivateMethods pvt = new InterfaceWithPrivateMethods() { // anonymous class
};
result = pvt.instancePrivate();
}
}}



JShell Command Line Tool

JSJshell is read–eval–print loop – REPL for short.
Simply put, it’s an interactive tool to evaluate declarations, statements, and expressions of Java, together with an API. It is very convenient for testing small code snippets, which otherwise require creating a new class with the main method.

The jshell executable itself can be found in <JAVA_HOME>/bin folder:
jdk-9\bin>jshell.exe
| Welcome to JShell -- Version 9
| For an introduction type: /help intro
jshell>2 + 2

| Expression value is: 4


New Version String Format

Semantic versioning is the message here. In the new Java version, a new version scheme was defined as described below:

Major.Minor.Security.Patch, where:

• Major: $MAJOR version, when you make incompatible API changes.
• Minor: $MINOR version, when you add functionality in a backward-compatible manner.
• Security: $SECURITY version, when you add security-critical fixes, including those necessary to improve security functionality or make backward-compatible bug fixes.
• Patch: $PATCH version, when you make backward-compatible bug fixes.

With microservices projects, this feature could foster a new way to control the versioning and evolution of projects and solutions — with a clear view of what’s inside of it when this pattern is rigorously followed.



Reactive streams
Currently, the Reactive Programming is popular in developing applications to gain some great benefits. The likes of Scala, Play and Akka frameworks have joined the Reactive Streams.
Oracle is also announcing new Reactive Streams API in Java 9. These new Reactive Streams API is a Publish or Subscribe Framework to implement Asynchronous, Scalable and Parallel applications easily using Java language.

Reactive Streams

The Flow APIs in JDK 9 correspond to the Reactive Streams Specification, which is a defacto standard. JEP 266 contains a minimal set of interfaces that capture the heart of asynchronous publication and subscription. The hope is that in the future 3rd parties will implement them and thus convene on a shared set of types.

The class java.util.concurrent.Flow encloses the following 4 interfaces
Flow.Processor
Flow.Publisher
Flow.Subscriber
Flow.Subscription
These interfaces support the Reactive Streams publish-subscribe framework. Java 9 also provides a utility class SubmissionPublisher. A Publisher produces items that are consumed by a number of Subscribers. And a Subscriber is managed by a Subscription. Subscription links the Publisher and Subscriber.



HTTP/2 Client
HTTP/1.1 client was released on 1997. A lot has changed since. So for Java 9 a new API been introduced that is cleaner and clearer to use and which also adds support for HTTP/2. New API uses 3 major classes i.e. HttpClientHttpRequest and HttpResponse.
To make a request, it is as simple as getting your client, building a request and sending it as shown below.
HttpClient httpClient = HttpClient.newHttpClient();
HttpRequest httpRequest = HttpRequest.newBuilder().uri(newURI("//:javafungus.blogspot.com")).GET().build();
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandler.asString());
System.out.println( httpResponse.body() );
Above code looks much cleaner and readable.
New API also support Async HTTP requests using httpClient.sendAsync() method. It returns CompletableFuture object which can be used to determine whether the request has been completed or not. It also provide you access to the HttpResponse once request is completed. Best part is that if you desire you can even cancel the request before it completes. e.g.
if(httpResponse.isDone()) {
    System.out.println(httpResponse.get().statusCode());
    System.out.println(httpResponse.get().body());
else {
    httpResponse.cancel(true);
}


Saturday, December 16, 2017

Maven For Beginners

Maven is a powerful build tool for Java software projects. Actually, you can build software projects using other languages too, but Maven is developed in Java, and is thus historically used more for Java projects.

What is a Build Tool?

A build tool is a tool that automates everything related to building the software project. Building a software project typically includes one or more of these activities:
  • Generating source code (if auto-generated code is used in the project).
  • Generating documentation from the source code.
  • Compiling source code.
  • Packaging compiled code into JAR files or ZIP files.
  • Installing the packaged code on a server, in a repository or somewhere else.

Installing Maven

To install Maven on your own system (computer), go to the Maven download page and follow the instructions there. In summary, what you need to do is:
  1. Set the JAVA_HOME environment variable to point to a valid Java SDK (e.g. Java 8).
  2. Download and unzip Maven.
  3. Set the M2_HOME environment variable to point to the directory you unzipped Maven to.
  4. Set the M2 environment variable to point to M2_HOME/bin (%M2_HOME%\bin on Windows, $M2_HOME/bin on unix).
  5. Add M2 to the PATH environment variable (%M2% on Windows, $M2 on unix).
  6. Open a command prompt and type 'mvn -version' (without quotes) and press enter.
After typing in the mvn -version command you should be able to see Maven execute, and the version number of Maven written out to the command prompt.

Maven Overview - Core Concepts

Maven is centered around the concept of POM files (Project Object Model). A POM file is an XML representation of project resources like source code, test code, dependencies (external JARs used) etc. The POM contains references to all of these resources. The POM file should be located in the root directory of the project it belongs to.
Here is a diagram illustrating how Maven uses the POM file, and what the POM file primarily contains:
Overview of Maven core concepts.
Overview of Maven core concepts.

These concepts are explained briefly below to give you an overview, and then in more detail in their own sections later in this tutorial.




POM Files
When you execute a Maven command you give Maven a POM file to execute the commands on. Maven will then execute the command on the resources described in the POM.

Build Life Cycles, Phases and Goals
The build process in Maven is split up into build life cycles, phases and goals. A build life cycle consists of a sequence of build phases, and each build phase consists of a sequence of goals. When you run Maven you pass a command to Maven. This command is the name of a build life cycle, phase or goal. If a life cycle is requested executed, all build phases in that life cycle are executed. If a build phase is requested executed, all build phases before it in the pre-defined sequence of build phases are executed too.

Dependencies and Repositories
One of the first goals Maven executes is to check the dependencies needed by your project. Dependencies are external JAR files (Java libraries) that your project uses. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository. The local repository is just a directory on your computer's hard disk. You can specify where the local repository should be located if you want to (I do). You can also specify which remote repository to use for downloading dependencies. All this will be explained in more detail later in this tutorial.

Build Plugins
Build plugins are used to insert extra goals into a build phase. If you need to perform a set of actions for your project which are not covered by the standard Maven build phases and goals, you can add a plugin to the POM file. Maven has some standard plugins you can use, and you can also implement your own in Java if you need to.

Build Profiles
Build profiles are used if you need to build your project in different ways. For instance, you may need to build your project for your local computer, for development and test. And you may need to build it for deployment on your production environment. These two builds may be different. To enable different builds you can add different build profiles to your POM files. When executing Maven you can tell which build profile to use.

Maven POM Files

A Maven POM file (Project Object Model) is an XML file that describe the resources of the project. This includes the directories where the source code, test source etc. is located in, what external dependencies (JAR files) your projects has etc.
Here is a minimal POM file:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.jenkov</groupId>
    <artifactId>java-web-crawler</artifactId>
    <version>1.0.0</version>
</project>

The above groupIdartifactId and version elements would result in a JAR file being built and put into the local Maven repository at the following path (directory and file name):
MAVEN_REPO/com/jenkov/java-web-crawler/1.0.0/java-web-crawler-1.0.0.jar

Effective POM

With all this POM inheritance it may be hard to know what the total POM file looks like when Maven executes. The total POM file (result of all inheritance) is called the effective POM. You can get Maven to show you the effective POM using this command:
mvn help:effective-pom

Maven Settings File

Maven has two settings files. In the settings files you can configure settings for Maven across all Maven POM files. For instance, you can configure:
  • Location of local repository
  • Active build profile
  • Etc.
The settings files are called settings.xml. The two settings files are located at:
  • The Maven installation directory: $M2_HOME/conf/settings.xml
  • The user's home directory: ${user.home}/.m2/settings.xml
Both files are optional. If both files are present, the values in the user home settings file overrides the values in the Maven installation settings file.

Running Maven

When you have installed Maven and have created a POM file and put the POM file in the root directory of your project, you can run Maven on your project.
Running Maven is done by executing the mvn command from a command prompt. When executing the mvn command you pass the name of a build life cycle, phase or goal to it, which Maven then executes. Here is an example:
mvn install
This command executes the build phase called install (part of the default build life cycle), which builds the project and copies the packaged JAR file into the local Maven repository. Actually, this command executes all build phases before install in the build phase sequence, before executing the install build phase.
You can execute multiple build life cycles or phases by passing more than one argument to the mvncommand. Here is an example:
 mvn clean install
This command first executes the clean build life cycle, which removes compiled classes from the Maven output directory, and then it executes the install build phase.
You can also execute a Maven goal (a subpart of a build phase) by passing the build phase and goal name concatenated with a : in between, as parameter to the Maven command. Here is an example:
mvn dependency:copy-dependencies
This command executes the copy-dependencies goal of the dependency build phase.

Maven Directory Structure

Maven has a standard directory structure. If you follow that directory structure for your project, you do not need to specify the directories of your source code, test code etc. in your POM file.
Here are the most important directories:
- src
  - main
    - java
    - resources
    - webapp
  - test
    - java
    - resources

- target

Project Dependencies

You specify your project dependencies inside the dependencies element in the POM file. Here is an example:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
   http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.jenkov.crawler</groupId>
    <artifactId>java-web-crawler</artifactId>
    <version>1.0.0</version>
    
      <dependencies>

        <dependency>
          <groupId>org.jsoup</groupId>
          <artifactId>jsoup</artifactId>
          <version>1.7.1</version>
        </dependency>

        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.1</version>
          <scope>test</scope>
        </dependency>

      </dependencies>
    

    <build>
    </build>

</project>

Snapshot Dependencies

Snapshot dependencies are dependencies (JAR files) which are under development. Instead of constantly updating the version numbers to get the latest version, you can depend on a snapshot version of the project. Snapshot versions are always downloaded into your local repository for every build, even if a matching snapshot version is already located in your local repository. Always downloading the snapshot dependencies assures that you always have the latest version in your local repository, for every build.
You can tell Maven that your project is a snapshot version simply by appending -SNAPSHOT to the version number in the beginning of the POM (where you also set the groupId and artifactId). Here is a versionelement example:
<version>1.0-SNAPSHOT</version>

Maven Repositories

Maven repositories are directories of packaged JAR files with extra meta data. The meta data are POM files describing the projects each packaged JAR file belongs to, including what external dependencies each packaged JAR has. It is this meta data that enables Maven to download dependencies of your dependencies recursively, until the whole tree of dependencies is download and put into your local repository.
Maven repositories are covered in more detail in the Maven Introduction to Repositories, but here is a quick overview.
Maven has three types of repository:
  • Local repository
  • Central repository
  • Remote repository
Maven searches these repositories for dependencies in the above sequence. First in the local repository, then in the central repository, and third in remote repositories if specified in the POM.
Here is a diagram illustrating the three repository types and their location:
Maven Repository Types and Location.
Maven Repository Types and Location.

Maven Build Life Cycles, Phases and Goals

When Maven builds a software project it follows a build life cycle. The build life cycle is divided into build phases, and the build phases are divided into build goals. Maven build life cycles, build phases and goals are described in more detail in the Maven Introduction to Build Phases, but here I will give you a quick overview.

Build Life Cycles
Maven has 3 built-in build life cycles. These are:
  1. default
  2. clean
  3. site
Build Phases
Each build life cycle is divided into a sequence of build phases, and the build phases are again subdivided into goals. Thus, the total build process is a sequence of build life cycle(s), build phases and goals.
Build PhaseDescription
validateValidates that the project is correct and all necessary information is available. This also makes sure the dependencies are downloaded.
compileCompiles the source code of the project.
testRuns the tests against the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
packagePacks the compiled code in its distributable format, such as a JAR.
installInstall the package into the local repository, for use as a dependency in other projects locally.
deployCopies the final package to the remote repository for sharing with other developers and projects.

Build Goals
Build goals are the finest steps in the Maven build process. A goal can be bound to one or more build phases, or to none at all. If a goal is not bound to any build phase, you can only execute it by passing the goals name to the mvn command. If a goal is bound to multiple build phases, that goal will get executed during each of the build phases it is bound to.

Maven Build Profiles

Maven build profiles enable you to build your project using different configurations. Instead of creating two separate POM files, you can just specify a profile with the different build configuration, and build your project with this build profile when needed.
You can read the full story about build profiles in the Maven POM reference under Profiles. Here I will give you a quick overview though.
Maven build profiles are specified inside the POM file, inside the profiles element. Each build profile is nested inside a profile element. Here is an example:
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
   http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.jenkov.crawler</groupId>
  <artifactId>java-web-crawler</artifactId>
  <version>1.0.0</version>

  <profiles>
      <profile>
          <id>test</id>
          <activation>...</activation>
          <build>...</build>
          <modules>...</modules>
          <repositories>...</repositories>
          <pluginRepositories>...</pluginRepositories>
          <dependencies>...</dependencies>
          <reporting>...</reporting>
          <dependencyManagement>...</dependencyManagement>
          <distributionManagement>...</distributionManagement>
      </profile>
  </profiles>

</project>

A build profile describes what changes should be made to the POM file when executing under that build profile. This could be changing the applications configuration file to use etc. The elements inside the profile element will override the values of the elements with the same name further up in the POM.
Inside the profile element you can see a activation element. This element describes the condition that triggers this build profile to be used. One way to choose what profile is being executed is in the settings.xml file. There you can set the active profile. Another way is to add -P profile-name to the Maven command line.

Maven Plugins

Maven plugins enable you to add your own actions to the build process. You do so by creating a simple Java class that extends a special Maven class, and then create a POM for the project. The plugin should be located in its own project.

Maven" is really just a core framework for a collection of Maven Plugins. In other words, plugins are where much of the real action is performed, plugins are used to: create jar files, create war files, compile code, unit test code, create project documentation, and on and on. Almost any action that you can think of performing on a project is implemented as a Maven plugin.
Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing an "action" (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM). Plugin behavior can be customized through a set of unique parameters which are exposed by a description of each plugin goal (or Mojo).
One of the simplest plugins in Maven is the Clean Plugin. The Maven Clean plugin (maven-clean-plugin) is responsible for removing the target directory of a Maven project. When you run "mvn clean", Maven executes the "clean" goal as defined in the Clean plug-in, and the target directory is removed. The Clean plugin defines a parameter which can be used to customize plugin behavior, this parameter is called outputDirectory and it defaults to ${project.build.directory}.

What is a Mojo ?

A Mojo is really just a goal in Maven, and plug-ins consist of any number of goals (Mojos). Mojos can be defined as annotated Java classes or Beanshell script. A Mojo specifies metadata about a goal: a goal name, which phase of the lifecycle it fits into, and the parameters it is expecting.
Mojo term was introduced in Maven 2 as a complete rework on how to write plugins (see below for more details on Maven 1.x plugins comparison).
MOJO is a play on POJO (Plain-old-Java-object), substituting "Maven" for "Plain".

Custom Plugin can be created with the help of MOJO.


Saturday, October 28, 2017

what's use of "$" in Javascript

I found this interesting story about "$". Hence sharing this information as separate blog.
There is nothing inherently special about '$'. It is a variable name just like any other. In earlier days, people used to write code using document.getElementById. Because JavaScript is case-sensitive, it was normal to make mistake while writing document.getElementById. Should I capital 'b' of 'by'? Should I capital 'i' of Id? You get the drift. Because functions are first class citizens in JavaScript, you can always do this
var $ = document.getElementById; //freedom from document.getElementById!
[EDIT: Looks like in Firefox 3 and Google Chrome, you can't make alias so easily. In IE6 and Firefox2, above technique still works.]
When Prototype library arrived, they named their function, which gets the DOM elements, as '$' to save on typing/readability [When writing JS code, most of the time you start with selecting some DOM elements]. Almost all the JavaScript libraries copied this idea. Prototype also introduced $$ function to select elements using CSS selector.
jQuery not only adapted the '$ function', but expanded to make it accept all kind of 'selectors' to get the elements you want. Now, if you are already using Prototype in your project and wanted to include jQuery, you will be in problem as '$' could either refer to Prototype's implementation OR jQuery's implementation. That's why jQuery has the option of noConflict so that you can include jQuery in your project which uses Prototype and slowly migrate your code. I think this was a brilliant move on John's part! :)

Web application Security and underlying concepts

Let's break down how to learn about web application certificates and the underlying security concepts. Here's a suggested order and ...