Wednesday, 28 December 2016

How to change the alias name of JKS file!!!!

Hi All

How to change the alias name of JKS file once we generated?

Step1 : To view what alias is available present in JKS file, use the below command

Open the command prompt and got the location where the jks file is available and execute below command
keytool -list -v -keystore <jks file name>

Example:
keytool -list -v -keystore test.jks

Step2 : once you executed the above command it will ask you the jks password, enter the same then it will display all the details like what all are certificated available in jks, expiry of certificates, alias name..etc..

Step3 : Execute the below command to change the alias name

keytool -keyclone -alias "old alias name" -dest "new alias name" -keystore <jks file>

Example :
keytool -keyclone -alias "pavan" -dest "kumar" -keystore test.jks

once you have execute above command it will ask you the password of jks, enter the same.
Done..!!!!enjoy..


How to change the certificate password

Hi All, after a long time posting again

How to change the certificate password using keytool command

Step1: open to the command prompt and go to the location where the certificate exists.
Step2:  execute the below command

keytool -storepasswd -keystore <jks file name>

Example
keytool -storepasswd -keystore test.jks

Step3: it will ask you the current password enter the same.
Step4: it will ask you the new password enter the new password.
Step5: it will ask you the password again for confirmation enter the same password which is entered  
           in step5.
Step6: thats it!!! your jks file got changed with new password....enjoy!!!!

Tuesday, 2 February 2016

How to use equals( ) and equalsIgnoreCase( ) in Java ?

To compare two strings for equality, use equals( ). It has this general form:
boolean equals(Object str)
Here, str is the String object being compared with the invoking String object. It returns true if the strings contain the same characters in the same order, and false otherwise.
The comparison is case-sensitive. To perform a comparison that ignores case differences, call equalsIgnoreCase( ). When it compares two strings, it considers A-Z to be the same as a-z. It has this general form:
boolean equalsIgnoreCase(String str)

Here, str is the String object being compared with the invoking String object. It, too, returns true if the strings contain the same characters in the same order, and false otherwise. Here is an example that demonstrates equals( ) and equalsIgnoreCase( ):

In one word we can say equals() is case-sensitive, equalsIgnoreCase() is not a case-sensitive.

Below is the example
// Demonstrate equals() and equalsIgnoreCase().
class equalsDemo {
        public static void main(String args[]) {
               String s1 = "Hello";
               String s2 = "Hello";
               String s3 = "Good-bye";
               String s4 = "HELLO";
               System.out.println(s1 + " equals " + s2 + " -> " +
               s1.equals(s2));
               System.out.println(s1 + " equals " + s3 + " -> " +
               s1.equals(s3));
               System.out.println(s1 + " equals " + s4 + " -> " +
               s1.equals(s4));
               System.out.println(s1 + " equalsIgnoreCase " + s4 + " -> " +
               s1.equalsIgnoreCase(s4));
       }
}

The output from the program is shown here:
Hello equals Hello -> true
Hello equals Good-bye -> false
Hello equals HELLO -> false
Hello equalsIgnoreCase HELLO -> true

Saturday, 30 January 2016

What is GIT Hub and how to use ?

What Is Git?

Git is version control software, which means it manages changes to a project without overwriting any part of that project.

Why use something like Git? Say you and a coworker are both updating pages on the same website. You make your changes, save them, and upload them back to the website. So far, so good. The problem comes when your coworker is working on the same page as you at the same time. One of you is about to have your work overwritten and erased.

Command Line: 
                         The computer program we use to input Git commands. On a Mac, it’s called Terminal. On a PC, it’s a non-native program that you download when you download Git for the first time (we’ll do that in the next section). In both cases, you type text-based commands, known as prompts, into the screen, instead of using a mouse.

  
Repository: 
                  A directory or storage space where your projects can live. Sometimes GitHub users shorten this to “repo.” It can be local to a folder on your computer, or it can be a storage space on GitHub or another online host. You can keep code files, text files, image files, you name it, inside a repository.

Version Control: 
                          Basically, the purpose Git was designed to serve. When you have a Microsoft Word file, you either overwrite every saved file with a new save, or you save multiple versions. With Git, you don’t have to. It keeps “snapshots” of every point in time in the project’s history, so you can never lose or overwrite it.

Commit: 
              This is the command that gives Git its power. When you commit, you are taking a “snapshot” of your repository at that point in time, giving you a checkpoint to which you can reevaluate or restore your project to any previous state.

Branch: 
            How do multiple people work on a project at the same time without Git getting them confused? Usually, they “branch off” of the main project with their own versions full of changes they themselves have made. After they’re done, it’s time to “merge” that branch back with the “master,” the main directory of the project.

Git-Specific Command
                        Since Git was designed with a big project like Linux in mind, there are a lot of Git commands. However, to use the basics of Git, you’ll only need to know a few terms. They all begin the same way, with the word “git.”

1. git config :-
                  Short for “configure,” this is most useful when you’re setting up Git for the first time.
2. git help :-
                   Forgot a command? Type this into the command line to bring up the 21 most common git commands. You can also be more specific and type “git help init” or another term to figure out how to use and configure a specific git command. 
3. git clone  <url>
                   Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.
                   After the clone, a plain git fetch without arguments will update all the remote-tracking branches, and a git pull without arguments will in addition merge the remote master branch into the current master branch, if any (this is untrue when "--single-branch" is given; see below).

4. git status :-
                   Check the status of your repository. See which files are inside it, which changes still need to be committed, and which branch of the repository you’re currently working on.
5. git add :-
               This does not add new files to your repository. Instead, it brings new files to Git’s attention. After you add files, they’re included in Git’s “snapshots” of the repository.
 i) git add <file name>
              This command is used to add a single file name into repository, that file will be available to commit, if you are not add file to repository you can't able to commit.
ii) git add -u
               This command is used to add all modified files to repository.
iii) git add .
               This command is used to add all modified and newly added files to repository.
5. git commit -m "commit message"
                        Git’s most important command. After you make any sort of change, you input this in order to take a “snapshot” of the repository. Usually it goes.
6. git push origin <branch name>
                        If you’re working on your local computer, and want your commits to be visible online on GitHub as well, you “push” the changes up to GitHub with this command.                      
7. git branch :-
                   Working with multiple collaborators and want to make changes on your own? This command will let you build a new branch, or timeline of commits, of changes and file additions that are completely your own. Your title goes after the command. If you wanted a new branch called “cats,” you’d type git branch cats.
8. git checkout <branch name> :-

                   Switch branches or restore working tree files.
     Ex: If you are current working directory master, if you want to switch from master to sandbox.
              git checkout sandbox
   If you want to restore of current modified files to previous stage use the below command

              git checkout <file name> 
   To revert all modified file to its previous stage use the below command

             git checkout .

9. git pull origin <branch name>
                If you’re working on your local computer and want the most up-to-date version of your repository to work with, you “pull” the changes down from GitHub with this command.
10. git merge <branch name>
               
When you’re done working on a branch, you can merge your changes back to the master branch, which is visible to all collaborators.
  Ex: you are currently working on feature branch i.e your branch xyz name.
would take all the changes you made to the “xyz” branch and add them to the master.
                 git merge xyz
11.  How to delete a branch from local repository ?
         git branch -D <branch name>
12. How to take particular commit from one branch to another branch ?

         git cherry-pick <commit-sha>
      commit-sha - take from original branch which commit you want.
    
  Below is the image where to take commit sha
       (
deff1f5b3a86bea8128e8eb18f689bc74ba0e213)
13. How to save your local changes temporarily in your local repository ?
      git stash
     
     When ever you want to pull out your changes we can use the below command
      git stash apply     
     Above command will pullout your last stashed files.
      git stash list     
      Above command will show all the local stashed commits.
      If you want to pullout specific local commit we can use below command
      git stash apply stash@{0}

      stash@{0}
- this is the latest local stashed commit.
      
{0} - here we can also pass specific stash number to pop out previous changes like                  below.       Ex :- git stash apply stash@{1} 

14. If you want to fix up your latest commit, you can undo the commit, and   
      unstage the files in it, by doing:
      git reset HEAD~1
      Below is the command we can use to reset N number of last commits.
      git reset HEAD~N
      If you want to get rid of your latest commit, and do not want to keep the code
      changes, you can do a "hard" reset.
      git reset --hard HEAD~1

15. To remove untracked files from git use below command
         git clean -fd

Tuesday, 8 December 2015

WebService Client Generation Error with JDK8

java.lang.AssertionError: org.xml.sax.SAXParseException:

Create a file named jaxp.properties (if it doesn't exist) under /path/to/jdk1.8.0/jre/lib and then write this line in it:

javax.xml.accessExternalSchema = all

That's all. Enjoy JDK 8.

Thursday, 20 August 2015

Just 3 Steps to Setting Up a Tomcat Server Log file in Eclipse ?

  • In the servers tab, double-click on the Tomcat Server. You will get a screen called Overview.
  • Click on "Open launch configuration". Click on the "Common" tab.
  • Towards the bottom of the screen you can check the "File" checkbox and then specify a file that can be used to log your console (catalina.out) output.
  • Finally, restart the Tomcat server.

Monday, 3 August 2015

How to add or remove or list certificates from keystore or trustStore in Java ?

                    How to add certificates on keystore in Java is primary questions when you start working on SSL connection and simple answer is keytool utility in Java is used to add or list Certificates into keystore. SSL is industry standard for secure communication between two parties e.g. client and server. SSL offers two benefits, it encrypts data transferred between client and server to make it hard for someone to access and understand in between and SSL also verify identity of two parties in communication and certificates are used for that purpose. SSL Setup in Java comes during various process e.g. Setting up SSL on tomcat, configuring messaging over SSL or JDBC over SSL are some examples of task where you need to deal with keyStore, certificates and trustStores. for those who are not aware of what is a keystore in Java and what is certificates, we will see brief introduction in next section.
Basics of SSL Certificates and Keystore in Java : -
                        When we access a secure site which uses SSL for providing identity and encryption, it provides a certificates which was verified by a trusted third party sites like verisign, godaddy or thwate. by using certificates browser or java clients knows that they talking to the correct site (who it claims to be) and not on redirected proxy site. this step is pretty transparent if you access websites using browser because if certificate is not on browser's trusted store it will ask you to add that certificate and it will be subsequently added, But when you access a secure site using Java program, this step of certificate hand shaking is not transparent to user and certificates are verified form JRE's trustStore. This trustStore is located on JDK Installation directory referred by JAVA_HOME  e.g. JAVA_HOME/jre/lib/security and commonly named as "cacerts".If certificate provided by secure site is present on JRE's trustStore SSL connection would be established but if certificate is not there than Java will throw exception and to solve that you need to add that certiificate into trustStore. keyStore and trustStore is often used interchangeably and same file can act as keystore as well as trustStore it just matter of pointing javax.net.ssl.keyStore and javax.net.ssl.trustStore properties to that file but there is slightly difference between keystore and trustStore. keyStore is used to store individual identity or certificate while trustStore is used to store other parties certificates signed by CA.
How to add ,remove and list certiifcates from Java keystore :-
  • In this article we will see how to add ,remove and list certiifcates from Java keystore using keytool utility.
  • keytool is binary located inside JAVA_HOME/jre/lib/security folder and used for adding, removing and listing certificates. 
 here is step by step example of adding certificates in Java:
Example of listing certificates form Java Keystore :-
                 Before adding new certificates in keystore or truststore its good to see, count and verify already installed certificates. run following keytool command in commonprompt to get a list of certififcates from keystore:
Step 1 :- Open the command prompt, go to the path where the java installed in your machine.
Step 2 :- Run the below command to get the list of certificates available in your cacerts file.
               keytool -list -keystore cacerts
               You see currently keystore "cacerts" holds 77 certificates.



Example of adding Certificate on Java KeyStore :-
Now let's see example of adding certificates into keytstore in Java:

1. Get Certificate: easier way is point your browser to that url and when certificate is presented save it on your local folder or directory say in C:/certificates/test.cer
2. Now go to Security folder of your JRE installation directory. id you have JDK installed than it would be something like C:/Program Files/Java//jdk1.6.0_20/jre/lib/security
3 Execute following keytool command to insert certificate into keystore


keytool -import -keystore cacerts -file test.cer

Now this will print details about certificate and ask you for confirmation of adding certificates:

Trust this certificate? [no]:  y
Certificate was added to keystore
if you approve it by typing "y" certificate will be added into keystore.
Trust this certificate? [no]:  n
Certificate was not added to keystore


password : changeit  - by default.

if you decline it by typing "n" certificate will not be added into keystore.


Important point about SSL, KeyStore and keyTool in Java :- 
1. Certificates are required to access secure sites using SSL protocol or making secure connection from client to server.
2. JRE stores certificates inside keystore named as "cacerts" in folder C:/Program Files/Java/jdk1.6.0_20/jre/lib/security.
3. Common password of keystore is "Changeit"
4. Keytool is used to access keystore in Java and by using keytool you can list, add certificates from keystore.
5. if you are implementing SSL connection on Server side say Tomcat you need both keyStore and trustStore, both can be same file though. keyStore will be used to store server certificate which server will present to client on SSL connection.

That’s all on how to add and list certificates from keyStore or trustStore in java. Keytool utility which comes with JDK installation will help you to create alias, list certificates etc.