Pages

Online Tool for calculating MD5 HASH

Calculate MD5

Input


Result


SHA-1 In Java

SHA-1 produces a message digest based on principles similar to those used by Ronald L. Rivest of MIT in the design of the MD4 and MD5 message digest algorithms, but has a more conservative design.

The Secure Hash Algorithm takes a message of less than 264 bits in length and produces a 160-bit message digest which is designed so that it should be computationally expensive to find a text which matches a given hash. ie if you have a hash for document A, H(A), it is difficult to find a document B which has the same hash, and even more difficult to arrange that document B says what you want it to say.

You can use the SHA-1 algorithm for securing password and to check the  integrity of your file and data.

When storing user details in a repository, you should avoid storing user passwords in clear text, because that makes them vulnerable to hackers. Instead, you should always store encrypted passwords in your repository.

You can also use the  SHA-1 algorithm to check the Duplicate File. MD5 can also be used for checksum.


A checksum is a small-sized datum derived from a block of digital data for the purpose of detecting errors which may have been introduced during its transmission or storage. It is usually applied to an installation file after it is received from the download server. By themselves, checksums are often used to verify data integrity but are not relied upon to verify data authenticity.

Now I am going to show you, How to use SHA-1 in Java

Java has a class  "MessageDigest" inside java.security package, that contains the implementation of SHA-1

Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

package com.esc.validator;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class SHA1 {

 public static void main(String[] args) throws NoSuchAlgorithmException {

  String testString = "I am going to kanpur";
  MessageDigest md = MessageDigest.getInstance("SHA-1");
  byte[] digest = md.digest(testString.getBytes());

  StringBuilder sb = new StringBuilder();
  for (byte b : digest) {
   sb.append(String.format("%02x", b & 0xff));
  }
  System.out.println(sb.toString());

 }

}

Output 

48ebce1dcd35bc56c5b8223711d4c98375859e44 

MD5 in Java

References
https://en.wikipedia.org/wiki/SHA-1

अपने निजी डेटा को चित्र (image) के पीछे विंडोज़ (Windows) और लिनक्स (Linux) में छुपाएं

कभी-कभी हम अपने कंप्यूटर या लैपटॉप में किसी अन्य व्यक्ति से, सुरक्षा कारण या किसी अन्य कारण से हमारे डेटा (data) को छिपाना चाहते हैं, ताकि कोई भी इस डेटा को देख न सके। हम आम तौर पर Windows ऑपरेटिंग सिस्टम में फ़ाइलों को hidden property के द्वारा छुपा सकते है अौर यूनिक्स (Unix) या लिनक्स (Linux)ऑपरेटिंग सिस्टम में फ़ाइल या फ़ोल्डर के नाम के आगे .(dot) लगाकर  छिपा सकते हैं, लेकिन यह आपके डेटा को छिपाने का सबसे सुरक्षित तरीका नहीं है।






आज मैं आपको बताने जा रहा हूं, कि image के पीछे अपना डेटा कैसे छुपाते है इस चाल में हम एक छवि (image) के पीछे अपना डेटा छुपते हैं। इसलिए अगली बार जब अन्य उपयोगकर्ता आपके लैपटॉप का उपयोग करेगा, तो वह आपके डेटा तक नहीं पहुंच सकेगा, क्योंकि आप छवि(image) के पीछे अपना डेटा छुपा चुके है |


Steps :

1. winrar या किसी भी अन्य उपयोगिता का उपयोग कर .rar में अपने डेटा को संक्षिप्त (compress) करे।

2. दोनों को कॉपी(copy) करें, .rar file और चित्र  (जिस चित्र के पीछे आप अपना डेटा छिपाना चाहते हैं) डेस्कटॉप (desktop) पर (उदाहरण के लिए, आप कहीं भी रख सकते हैं)

3. कमांड प्रॉम्प्ट (command prompt) खोलें और नीचे दी गयी कमांड टाइप करें

"copy /b my.jpg + mydata.rar hidden.jpg"


जहाँ

my.jpg -> जिस चित्र के पीछे आप अपना डेटा छिपाना चाहते हैं

mydata.rar-> फ़ाइलों या फ़ोल्डर में परिवर्तित .rar, जिसे आप छुपाना चाहते हैं

hidden.jpg -> आउटपुट जो आपके डेटा को छुपाता है

यूनिक्स (Unix) उपयोगकर्ताओं  यह प्रयास करें

    cat my.jpg mydata.zip> hidden.jpg


छुपा डेटा तक पहुंचने के लिए

छिपे हुए डेटा का उपयोग करने के लिए बस अपनी फ़ाइल को unrar करना और आपको अपना मूल डेटा फ़ाइल मिलती है।

MD5 in Java

MD5 (Message Digest algorithm 5) is message-digest algorithm, which takes as input a message of arbitrary length and produces as output a 128-bit (32 hexadecimal character)  "message digest" of the input.

MD5 is one of various strategies for distinguishing, securing and checking information. Cryptographic hashing is a crucial part ever, and keeping things covered up.

You can use the MD5 algorithm for securing password and to check the  integrity of your file and data.

You can also use the  MD5 algorithm to check the Duplicate File. MD5 can also be used for checksum.

When storing user details in a repository, you should avoid storing user passwords in clear text, because that makes them vulnerable to hackers. Instead, you should always store encrypted passwords in your repository.

A checksum is a small-sized datum derived from a block of digital data for the purpose of detecting errors which may have been introduced during its transmission or storage. It is usually applied to an installation file after it is received from the download server. By themselves, checksums are often used to verify data integrity but are not relied upon to verify data authenticity.

Now I am going to show you, How to use MD5 in Java

Java has a class  "MessageDigest" inside java.security package, that contains the implementation of MD5

Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

We will use this class to get MD5 of a text data

package com.esc.validator;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5 {

    public static void main(String[] args) throws NoSuchAlgorithmException {

        String testString = "I am going to kanpur";
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(testString.getBytes());

        StringBuilder sb = new StringBuilder();
        for (byte b : digest) {
            sb.append(String.format("%02x", b & 0xff));
        }
        System.out.println(sb.toString());

    }

}


Output
 
7341e209948bef702bb6034c5d634098 
 

SHA-1 In Java

Online Demo of MD5 

References 

https://en.wikipedia.org/wiki/MD5 

Covariant return type in Java

Before Java 5.0, when you override a method, both parameters and return type must match exactly.

In Java 5.0, it introduces a new facility called covariant return type.
You can override a method with the same signature but returns a subclass of the object returned.

Case 1: If the return type is void or primitive then the data type of parent class method and overriding method must be same. e.g. if return type is int, float, double then it should be same

public class Fruit {

 int size;

 int description() {
  
  
  return size;

 }

}
public class Apple extends Fruit {

 float size ;

 
 @Override
 float description() {

  
  return size;

 }

}
 
Output
Error : The return type is incompatible with Fruit.description()
 
Case 2: If the return type of the parent class method is derived type then the return type of the overriding method is same derived data type or sub class to the derived data type.

e.g. Suppose you have a class Fruit, Apple is subclass to Fruit, 

public class Fruit {

 String name = "Fruit";

 Fruit description() {
  
  Fruit fruit = new Fruit();
  return fruit;

 }

}
public class Apple extends Fruit {

 String name = "Apple";

 // overiding Fruit class method using subclass type
 @Override
 Apple description() {

  Apple apple = new Apple();

  return apple;

 }

}

Constructor telescoping in Java

Use Case : When there are several parameters in which some is required/mandatory parameter to create an instance of class and some are optional, you can provide the value of optional parameter or not.

The default value for the optional parameter is provided by class.

What is telescoping constructor ?

telescoping constructor pattern, in which you provide a constructor with only the required parameters, another with a single optional parameter, a third with two optional parameters, and so on, culminating in a constructor with all the optional parameters.

Note: this pattern is helpful only when you have limited number of parameters. if parameter list is too long then this is not the best choice, you should use Builder pattern in this case.

Here I am providing you an example of how to implement this pattern -

public class ConsTelescoping {

 private final int servingSize; //  required
 private final int servings; // required
 private final int calories; // optional
 private final int fat; //  optional
 private final int sodium; // optional
 private final int carbohydrate; // optional

 public ConsTelescoping(int servingSize, int servings) {
  this(servingSize, servings, 0);
 }

 public ConsTelescoping(int servingSize, int servings, int calories) {
  this(servingSize, servings, calories, 0);
 }

 public ConsTelescoping(int servingSize, int servings, int calories, int fat) {
  this(servingSize, servings, calories, fat, 0);
 }

 public ConsTelescoping(int servingSize, int servings, int calories, int fat,
   int sodium) {
  this(servingSize, servings, calories, fat, sodium, 0);
 }

 public ConsTelescoping(int servingSize, int servings, int calories, int fat,
   int sodium, int carbohydrate) {
  this.servingSize = servingSize;
  this.servings = servings;
  this.calories = calories;
  this.fat = fat;
  this.sodium = sodium;
  this.carbohydrate = carbohydrate;
 }
}
 

How to write an immutable Class in Java 


Static variable initialization in Java

There are two types of variable in Java classes

1. Class variable (static variable)
2. Instance variable

Class variable (static variable)

The variables defined with "static" keyword is known as class variable, because these are associated with class and created on class memory.

Syntax for static variable

 public static String staticVariable;  

Properties of static variable


1. These variables are share with all object of the class, and there is a single copy of static variable. if one object change the value of static variable then changes visible to all object.

2. Static variables are initialized only once , at the start of the execution .

3. A static variable can be accessed directly by the class name and doesn’t need any object.




Ex. StaticClass.staticVarible;

4. These variables will be initialized first, before the initialization of any instance variables

Instance variable

The variable define without static keyword is known as "instance" variable or object variable.


Properties of instance variable



1. These variable associated with object of class.
2. Each object have its own local copy for variable.
3. Require instance to access these variable.


How Initialize static variables ?

1. you can initialize it at the time of declaration
2. you can do by making static block
3. alternative to static blocks — you can write a private static method

Initialize the static variable at the time of declaration

Example 

public class StaticBlock {

 private static String staticVariable="I am static variable";
 private String instanceVariable;
 
 public static void main(String[] args) {

  System.out.println(staticVariable);

 }

}

Output

I am static variable
when the class loaded static variable initialized

Static Initialization Block

static variable can initialized using static block.
when class loader loads the class static block executed automatically.

syntax for static block

static {
    // whatever code is needed for initialization goes here
}


Here is an example of static initialization block

public class StaticBlock {

 private static String staticVariable;
 private String instanceVariable;

 static {
  staticVariable = "I am static variable";

 }

 public static void main(String[] args) {

  System.out.println(staticVariable);

 }

}

Output

I am static variable

Here we can see that as JVM loads the main class, the static block executed and initialize the variable. No object is created of the class.


Note :

A class can have any number of static initialization blocks, and they can appear anywhere in the class body. The runtime system guarantees that static initialization blocks are called in the order that they appear in the source code.


Example of multiple static block

public class StaticBlock {

 private static String staticVariable1;
 private static String staticVariable2;

 static {
  staticVariable1 = "I am static block 1";
  System.out.println(staticVariable1);

 }

 static {
  staticVariable2 = "I am static block 2";
  System.out.println(staticVariable2);

 }
 
 public static void main(String[] args) {
  
 }
 
 static {
  staticVariable2 = "I am static block 3";
  System.out.println(staticVariable2);

 }

}

Output

I am static block 1
I am static block 2
I am static block 3


Note :

1. Instance methods can access instance variables and instance methods directly.

2. Instance methods can access static variables and static methods directly.

3. static methods can access static variables and static methods directly.

4. static methods cannot access instance variables or instance methods directly—they must use an object reference. Also, static methods cannot use the this keyword as there is no instance for this to refer to.


How to write an immutable Class in Java

How to write an immutable Class in Java



Immutable Class ?


Immutable classes  are those classes whose instances  state doesn’t change after it has been initialized.

As we know that in Java String is an immutable class and once instantiated its value never changes.

Immutable object once created and initialized that can not be changed so these objects are the right candidate for the caching and it is also thread-safe , so you don't worry about thread safety.


Here I am providing a way to create immutable class via an example for better understanding.

To create a class immutable, you need to follow following steps:
  1. Declare the class as final so it can’t be extended. so overriding of method is not possible.
  2. all fields must private and final, so that direct access is not allowed and once the value of field initialized they can't be changed.
  3. Don’t provide setter methods for variables
  4. Make all mutable fields final so that it’s value can be assigned only once.
  5. Initialize all the fields via a constructor performing deep copy.
  6. Perform cloning of objects in the getter methods to return a copy rather than returning the actual object reference.



public final class ImmutableStudent {

 // field once intialized can not be changed 
 final String name;
 final int regNo;

 public ImmutableStudent(String name, int regNo) {
  this.name = name;
  this.regNo = regNo;
 }

 public String getName() {
  return name;
 }

 public int getRegNo() {
  return regNo;
 }
 
 // No setter method 
 
}
The static factory method implementation for immutable class--
public class ImmutableStudentFactory {

 final private String name;
 final private int age;

 // private constructor so no class extend this
 private ImmutableStudentFactory(final int age, final String name) {
  this.age = age;
  this.name = name;
 }

 // static factory method
 public static ImmutableStudentFactory getInstnace(final int age,
   final String name) {
  return new ImmutableStudentFactory(age, name);
 }

 public int getAge() {
  return age;
 }

 public String getName() {
  return name;
 }

Loading property File using Singleton pattern in Java

Singleton pattern : Singleton pattern insure only a single instance of a class can exist at given time per JVM.

There are different  ways to implement Singleton pattern.

In this example I will provide you to load properties files using Singleton pattern. This implementation is not thread safe. So if you are not dealing with multi-thread you can use this implementation.


public final class PropReader {

 private static PropReader instance = null;
 static Properties prop = null;
 static InputStream in = null;
 public static String tmLocation = null;

 // private constructor so no other class can instanciate this
 private PropReader() {

  try {
   in = this.getClass().getResourceAsStream("/app.properties");
   prop = new Properties();
   prop.load(in);
   tmLocation = prop.getProperty("TM_BASE_DIRECTORY");
  }

  catch (Exception e) {

   System.out.println(e);
  }
 } 
 
// provide instance if no other instance exist 
 public static PropReader getInstance() throws IOException {

  if (instance == null) {
   instance = new PropReader();
  }

  return instance;
 }

}


How to write an immutable Class in Java

Counting the occurences of each character in a given string in java

In this example I will show you how to count the occurrences of each character in a given string.

For this we use HashMap. key for HashMap is the character and value is the number of occurrences.
public static void main(String[] args) {
  char[] ch = name.toLowerCase().toCharArray();
  HashMap<Character, Integer> map = new HashMap<>();

  for (int i = 0; i < ch.length; i++) {
   if (map.containsKey(ch[i])) {
    map.put(ch[i], map.get(ch[i]) + 1);
   }

   else {
    map.put(ch[i], 1);
   }
  }

  System.out.println(map);
 }
Output of the program 

{v=1,  =1, t=1, r=1, a=2, n=1, o=2, m=1, j=1, i=1}


How to write an immutable Class in Java

Java Package class

public class Package (java.lang)

Package objects contain version information about the implementation and specification of a Java package. The version information is retrieved and made available by the ClassLoader instance that loaded the class(es).

Typically, it is stored in the manifest that is distributed with the classes.

Example of Package Class

package com.self.practise;

public class PackageClass {

 public static void main(String[] args) {
  
  
  Package pac = Package.getPackage("java.lang");
 
                System.out.println(pac.getImplementationVersion());
  System.out.println(pac.getSpecificationVendor());
  System.out.println(pac.getImplementationTitle());
  System.out.println(pac.isSealed());
  System.out.println(pac.getSpecificationTitle());
  

 }

}

Output of the program
1.7.0_75
Oracle Corporation
Java Runtime Environment
false
Java Platform API Specification

How to write an immutable Class in Java

Java ClassLoader

Java ClassLoader is a class found inside the package java.lang. The class loader is responsible for dynamically loading the class for make it available to JVM.

The java.lang.ClassLoader is an abstract class that can be sub classed by applications that need to extend the manner in which the JVM dynamically loads classes.

Every class is loaded by some class loader. The class loader loads the classes from classpath, jre/lib and jre/lib/ext.

Each instance of ClassLoader has an associated parent class loader. The bootstrap class loader does not itself have a parent but may serve as the parent of a ClassLoader instance.


 ClassLoader in Java works on three principle:
  1. Delegation
  2. Visibility
  3. Uniqueness

The Delegation principle forward request of class loading to parent class loader and only loads the class, if parent is not able to find or load class.

Visibility principle allows child class loader to see all the classes loaded by parent ClassLoader, but parent class loader cannot see classes loaded by child.

Uniqueness principle allows to load a class exactly once, which is basically achieved by delegation and ensures that child ClassLoader doesn't reload the class already loaded by parent.

How Class Loader works ?


The loadClass() method of the ClassLoader performs the following tasks, in order, when called to load a class:

If a class has already been loaded, it returns it. Otherwise, it delegates the search for the new class to the parent class loader. If the parent class loader doesn't find the class, loadClass() calls the method findClass() to find and load the class. The findClass() method searches for the class in the current class loader if the class wasn't found by the parent class loader.
Types of class loader
There are three type of class loader used inside JVM
  1. Bootstrap class loader
  2. Extensions class loader
  3. System class loader

Bootstrap class loader


The bootstrap class loader loads the core Java libraries located in the /jre/lib directory. This class loader, which is part of the core JVM, is written in native code.

Extensions class loader


The extensions class loader loads the code in the extensions directories (/jre/lib/ext or any other directory specified by the java.ext.dirs system property.

System class loader


The system class loader loads code found on java.class.path, which maps to the CLASSPATH environment variable.

Important HTTP codes for Rest web services

As all of us know that when we send a request to HTTP server, server returns the response of the request and also send a  status code. these status codes have special meaning for the client so a as software engineer  we must have knowledge about these codes. HTTP code have three digits like 200.

As we know that web services like consumes by program not directly by user, so web services should return HTTP status code very carefully, because based on these case consumer of web service will take action.

When a resource is created, the response code should be 201 (“Created”) and the Location header should point the way to the resource’s location.

When a resource is modified, the response code should be 200 (“OK”). If the resource state changes in a way that changes the URI to the resource (for instance, a user account is renamed), the response code is 301 (“Moved Permanently”) and the Location header should provide the new URI.

When an object is deleted, the response code should be 200 (“OK”).

We can use the 401 response code (“Unau-thorized”) any time the client tries to do something (edit a user’s account) without providing the proper Authorization header.

a client might try to rename a user account to a name that already exists. The 409 (“Conflict”) response code is appropriate here.

we will use 400 when a user tries to create or modify a resource, but doesn’t provide a valid representation.


Here I am listing some of the Important status code that everyone should know.
I took this article from www.w3.org. This site explain all the available status code very nicely.

There are 5 categories of HTTP code.

Category 1 : Start with digit "1"
1xx: Informational - Request received, continuing process

Category 2 : Start with digit "2"
2xx: Success - The action was successfully received, understood, and accepted

Category 3 : Start with digit "3"
3xx: Redirection - Further action must be taken in order to complete the request

Category 4 : Start with digit "4"
4xx: Client Error - The request contains bad syntax or cannot be fulfilled

Category 5 : Start with digit "5"
5xx: Server Error - The server failed to fulfill an apparently valid request





Here we are listing some important status code --

200     OK - client's request was successfully received, understood, and accepted.

201     Created - The request has been fulfilled and resulted in a new resource being created

202     Accepted- The request has been accepted for processing, but the processing has not been completed



301     Moved Permanently - The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs

302     Found - The requested resource resides temporarily under a different URI.

307     Temporary Redirect - The requested resource resides temporarily under a different URI

400     Bad Request - could not be understood by the server due to malformed syntax

401     Unauthorized

404     Not Found - The server has not found anything matching the Request-URI

405     Method Not Allowed -  The method specified in the Request-Line is not allowed for the resource identified by the Request-URI

406     Not Acceptable

500     Internal Server Error- The server encountered an unexpected condition which prevented it from fulfilling the request


503     Service Unavailable - The server is currently unable to handle the request due to a temporary overloading or maintenance


REST Architecture

Bar Chart Customization in JasperReport

Jasper Report is used to build a Report. Report may contains charts, to represent the behavior of data in pictorial form.

In this tutorial I will tell you, How to customize charts properties through Java code instead of hard-coding property to "jrxml" file.

As we know that every chart has a property called "Customizer Class" that can take the reference of Java classes. we use this property to format the chart.

To set  the chart property through Java code we require following steps - 

1. First we have to create a "Java class" and put the formatting code inside this class

2. compile and package this class to "jar" file.

3. add  "jar" file to 'class path' of invoking program that will run the jasper.

Here I am providing a small sample code for setting the property of Bar Chart through Java code, that you can used to format the charts.


public class BarChart implements JRChartCustomizer {
 @SuppressWarnings("deprecation")
 public void customize(JFreeChart chart, JRChart jasperChart) {
  CategoryPlot plot = chart.getCategoryPlot();
                BarRenderer render = (BarRenderer) plot.getRenderer();
                Font titleFont = new Font("Helvetica", Font.BOLD, 7);
  Font font = new Font("Helvetica", Font.PLAIN, 6);
  Font subFont = new Font("Helvetica", Font.ITALIC, 7);

  plot.setNoDataMessage("No Data Available");
  plot.setNoDataMessageFont(font);
  plot.setDomainGridlinesVisible(false);
  plot.setRangeGridlinesVisible(false);
  
  int a = plot.getDataset().getRowCount();
   
                if(a==1){
   render.setSeriesPaint(0, Color.BLACK);
  }
    
  chart.setBorderVisible(false);
  chart.setBorderPaint(Color.WHITE);
    
}



Now compile this code and pack to "jar" file and add to the "classpath" and use this class in "Customizer Class" property of chart.

If you have any query feel free to ask.

Integrate Jenkins with GIT SCM

TO configure Git in Jenkins, first log in to your Jenkins server and in your Dashboard left side there is an option "Manage Jenkins", click on it


Now click on "Manage Plugins" on the next screen.



In the next screen click on "Available" tab.


You get a list of Plugins, in this list there so many Plugin, in 'Filter' box we put 'Git Plugin'.


Now we select the 'Git Plugin' check-box  and press the "Install without restart"


you get the following screen



Once all installations are complete, restart the Jenkins server by selecting ""  at the bottom of the page.

Now login again to Jenkins dashboard.


After Jenkins is restarted, Git will be available as an option whilst configuring jobs. To verify, click on New Item in the menu options for Jenkins. Then enter a name for a job, in the following case, the name entered is ‘JenkisDemo’. Select ‘Freestyle project’ as the item type. Click the Ok button.

In the next screen when you click on "Source Code Management" tab you get GIT as an option


Jenkins continous Integration tool

What is Continuous Integration ?

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. This article is a quick overview of Continuous Integration summarizing the technique and its current usage. 

The main aim of CI is to prevent integration problems, referred to as "integration hell"

A continuous integration server acts as a monitor to the repository. Every time a commit against the repository finishes the server automatically checks out the sources onto the integration machine, initiates a build, and notifies the committer of the result of the build. The committer isn't done until she gets the notification - usually an email.


What is Jenkins ? 

Jenkins is a popular open source tool to perform continuous integration and build automation. The basic functionality of Jenkins is to execute a predefined list of steps, e.g. to compile Java source code and build a JAR from the resulting classes. The trigger for this execution can be time or event based. For example, every 20 minutes or after a new commit in a Git repository.

Environment Set up for Jenkins ?

Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with the Java Runtime Environment installed.

1. In this tutorial we use standalone distribution. TO download the Jenkis click on the given Jenkins link.

2. Go to the directory where you download the Jenkins war file and run the following command-

$ java -jar jenkins.war

After the command is run, various tasks will run, one of which is the extraction of the war file which is done by an embedded webserver called winstone.

Running from: /home/expert/Downloads/jenkins.war
webroot: $user.home/.jenkins
Jul 24, 2017 10:18:48 PM Main deleteWinstoneTempContents

WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
Jul 24, 2017 10:18:48 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Logging initialized @454ms
Jul 24, 2017 10:18:48 PM winstone.Logger logInternal
INFO: Beginning extraction from war file

3. Go to browser and type http://localhost:8080/
an authentication window is opened and it will ask you to enter the user and password.

type user as admin and password for this you get on server machine in the location ${user.home}/.jenkins/secrets/initialAdminPassword


after succesfull authentication you will get the Jenkins dashboard

References
https://jenkins.io/doc/
https://martinfowler.com/articles/continuousIntegration.html 

Convention for Versioning of your project build

As we know that when we use any software tool or dependency or OS, they all come up with vesrion number like 2.1.1.

As a Software Engineer, developer and programmer we must understood what these version numbers.

So In this tutorial I will explain you about these version number.

The common convention for version numbers is major.minor.build.

major. is incremented when something major is changed in your project.  For example, suppose you have removed a functionality, or changes the  signature of a function. so if client uses new version of project, changes can break the project of Clients using your library, so your client  need to take care when using a library with a different major version.

minor is incremented when something new added to your project but all the old functionality is same, For example, a method is added. In this case your client doe not worry about using the new version.Clients do not need to worry about about using the new version, as all the functions they are used to seeing will still be there and act the same.

build is incremented when the implementation of a function changes, but no signatures are added or removed. For example, you found a bug and fixed it. Clients should probably update to the new version, but if it doesn't work because they depended on the broken behavior, they can easily downgrade.






What Browser do when you type a address in your Browser Addres bar

As a end user, we do not have to know about what the browser do,  when we type an address in Browser.

But as a Programmer or Software Engineer some time we involve in web programming. As we know that web programming include HTTP, HTML, CSS, web server and so on.

Mostly novice programmer have an abstract idea about, what is happening behind the scene. In this tutorial I will try to take all of you into a deeper picture of behind the scene.

Suppose we are going to read a tutorial on techie-knowledge

1. We type the interested address(URL) in the Browser address bar.

 

2.  As we know the address which we have type is known as domain-name. Internet works on IP address.
     so it is clear that domain name converted to IP  address.

    a. So after typing the URL in browser, browser first extract the domain name from the URL.
    b. then browser queries to your pre-configure DNS server to find the IP address of the domain.Some               time it may be happen that DNS server have not the IP for domain, In this case DNS server will                    forward the query along to  DNS server it is configured to defer to.



     c. After getting IP address browser sends a HTTP request  original site
   



       d. After getting the response browser render the page to browser.



MAVEN archetype

MAVEN archetype is predefined template for specific project type like web project, spring project,  provided by Maven. In Maven a template is called an archetype.

As we know that when we create a project in eclipse it ask us to select the type of project like simple java project, dynamic web project ... when we select the type of project a structure of the project is created by eclipse.

similarly maven provides different archetype to create project.

Using an Archetype :

To create a new project based on an Archetype, you need to call mvn archetype:generate goal, like the following:

$ mvn archetype:generate
when you run this command maven download the diffrent archetype provided by maven, and ask you to select the archetype for your project.

sample output of the command

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------ [INFO]
[INFO] maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO] [INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype:
1: remote -> am.ik.archetype:maven-reactjs-blank-archetype (Blank Project for React.js)
2: remote -> am.ik.archetype:msgpack-rpc-jersey-blank-archetype (Blank Project for Spring Boot + Jersey)
3: remote -> am.ik.archetype:mvc-1.0-blank-archetype (MVC 1.0 Blank Project)
4: remote -> am.ik.archetype:spring-boot-blank-archetype (Blank Project for Spring Boot)
5: remote -> am.ik.archetype:spring-boot-docker-blank-archetype (Docker Blank Project for Spring Boot)
6: remote -> am.ik.archetype:spring-boot-gae-blank-archetype (GAE Blank Project for Spring Boot)
7: remote -> am.ik.archetype:spring-boot-jersey-blank-archetype (Blank Project for Spring Boot + Jersey)
8: remote -> at.chrl.archetypes:chrl-spring-sample (Archetype for Spring Vaadin Webapps)
9: remote -> br.com.address.archetypes:struts2-archetype (an archetype web 3.0 + struts2 (bootstrap + jquery) + JPA 2.1 with struts2 login system)
10: remote -> br.com.address.archetypes:struts2-base-archetype (An Archetype with JPA 2.1; Struts2 core 2.3.28.1; Jquery struts plugin; Struts BootStrap plugin; json Struts plugin; Login System using Session and Interceptor)
11: remote -> br.com.anteros:Anteros-Archetype (Anteros Archetype for Java Web projects.)
12: remote -> br.com.codecode:vlocadora-json (Modelos com Anotações Gson)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 1007:
Press Enter to choose to default option or chosse the number of archetype. Enter project detail as asked.Press Enter if default value is provided. You can override them by entering your own value.
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
Choose a number: 6:
Define value for property 'groupId': com.xyz
Define value for property 'artifactId': mvntest
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' com.xyz: : com.xyz.mvntest

Maven will ask for project detail confirmation. Press enter or press Y
Confirm properties configuration:
groupId: com.xyz
artifactId: mvntest
version: 1.0-SNAPSHOT
package: com.esc.mvntest
Y: :
Now Maven will start creating project structure and will display the following:
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1
[INFO] ---------------------------------------------------------------------------- [INFO] Parameter: basedir, Value: /home/expert
[INFO] Parameter: package, Value: com.esc.mvntest
[INFO] Parameter: groupId, Value: com.xyz
[INFO] Parameter: artifactId, Value: mvntest
[INFO] Parameter: packageName, Value: com.xyz.mvntest [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /home/expert/mvntest
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:26 min
[INFO] Finished at: 2017-07-19T18:10:36+05:30
[INFO] Final Memory: 18M/199M
[INFO] ------------------------------------------------------------------------
You'll see a java application project created named mvntest which was given as artifactId at the time of project creation. Maven will create a standard directory layout for the project as shown below:
mvntest
├── pom.xml
└── src
        ├── main
        │        └── java
        │              └── com
        │                       └── xyz
        │                               └── mvntest
        │                                              └── App.java
        └── test
               └── java
                      └── com
                             └── xyz
                                     └── mvntest
                                             └── AppTest.java
Maven generates a POM.xml file for the project as listed below:
<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.xyz</groupId>
  <artifactId>mvntest</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mvntest</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project> 
 
App.java file which was created by maven 



package com.esc.mvntest;

/**
 * Hello world!
 *
 */
public class App
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
} 
  
Compiling code

To compile the code we use the following command
$ mvn compile
The sample output of the above commmand
[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------
[INFO] Building mvntest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/expert/mvntest/src/main/resources
[INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ mvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.150 s
[INFO] Finished at: 2017-07-22T11:04:23+05:30
[INFO] Final Memory: 7M/121M
[INFO] ------------------------ ------------------------------------------------


Packaging the code

As we know that this project is just a simple java program so we can create the jar file of this project. To create the jar file of the project we use the following command

The default naming convention of Maven artifacts is: {artifact-name}-{artifact-version}

$ mvn package

Sample output of the following command

[INFO] Scanning for projects...
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Building mvntest 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/expert/mvntest/src/main/resources
[INFO] [INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ mvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mvntest ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/expert/mvntest/src/test/resources
[INFO] [INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ mvntest ---
[INFO] Nothing to compile - all classes are up to date
[INFO] [INFO] --- maven-surefire-plugin:2.17:test (default-test) @ mvntest ---
[INFO] Surefire report directory: /home/expert/mvntest/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.esc.mvntest.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec - in com.esc.mvntest.AppTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mvntest ---
[INFO] Building jar: /home/expert/mvntest/target/mvntest-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.885 s
[INFO] Finished at: 2017-07-22T11:28:38+05:30
[INFO] Final Memory: 16M/158M
[INFO] ------------------------------------------------------------------------