Find if a string is a integer or not in Java

public static boolean isInteger(String s) {
    return isInteger(s,10);
}

public static boolean isInteger(String s, int radix) {
    if(s.isEmpty()) return false;
    for(int i = 0; i < s.length(); i++) {
        if(i == 0 && s.charAt(i) == '-') {
            if(s.length() == 1) return false;
            else continue;
        }
        if(Character.digit(s.charAt(i),radix) < 0) return false;
    }
    return true;
}

Changing Tomcat default web application

Add below line in server.xml in Host entry for localhost in server.xml.

<Context path="" docBase="whatsapp-direct" />


Result:


<Host name="localhost">

                <!-- SingleSignOn valve, share authentication between web applications 
                    Documentation at: /docs/config/valve.html -->
                <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" 
                    /> -->

                <!-- Access log processes all example. Documentation at: /docs/config/valve.html 
                    Note: The pattern used is equivalent to using pattern="common" -->
                <Valve className="org.apache.catalina.valves.AccessLogValve"
                    directory="logs" prefix="localhost_access_log." suffix=".txt"
                    pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />

                <Context path="" docBase="/usr/local/tomcat/mywebapps/myapplication">
                    <WatchedResource>WEB-INF/web.xml</WatchedResource>
                </Context>

            </Host>

How to kick start aws account

1. Sign up first
2. Create a key pair, download. Name it such that your email address is in it.
3. Create an EC2 instance (Ubuntu preferred)
4. Launch EC2
5. Buy a domain from Godaddy
6. Back to EC2 - Create an Elastic IP
7. Associate the Elastic IP created with the EC2 instance already launched
8. Update the A record from DNS management of Godaddy

Done

Making your EC2 instance ready.

1. scp -i myfile.pem ~/Desktop/apache-tomcat-7.0.72.zip ubuntu@ElasticIP:/home/ubuntu/

2. SSH -i <your-private-pem-file> ubuntu@ElasticIP

3. sudo apt-get install unzip

4. unzip apache-tomcat-7.0.72.zip

5. Install Java
    a) sudo add-apt-repository ppa:webupd8team/java
    b) sudo apt-get update
    c) sudo apt-get install oracle-java7-installer

6. chmod +x  apache-tomcat-7.0.72/bin/catalina.sh

7. sh apache-tomcat-7.0.72/bin/Startup.sh


Note: By default, tomcat runs in 8080, so to hit your public ip and see tomcat start page, you have to open the 8080 from custom protocal.


Now redirect 80 requests to a web service which is listening on 8080. For that

1. sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080







How to find ubuntu 32-bit or 64-bit version


>>file /lib/systemd/systemd

/lib/systemd/systemd: ELF 64-bit LSB shared object, x86-64, version ..........


Create Yooutube Video Links that set the default video quality to HD

https://www.youtube.com/embed/0KbavKOiS_k?rel=0&wmode=opaque&enablejsapi=1

Adding an existing or new project to GitHub using the command line

  1. Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.
  2. Open Terminal.
  3. Change the current working directory to your local project.
  4. Initialize the local directory as a Git repository.
    git init
    
  5. Add the files in your new local repository. This stages them for the first commit.
    git add .
    # Adds the files in the local repository and stages them for commit. To unstage a file, use 'git reset HEAD YOUR-FILE'.
    
  6. Commit the files that you've staged in your local repository.
    git commit -m "First commit"
    # Commits the tracked changes and prepares them to be pushed to a remote repository. To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
    
  7. Copy remote repository URL fieldAt the top of your GitHub repository's Quick Setup page, click  to copy the remote repository URL.
  8. In Terminal, add the URL for the remote repository where your local repository will be pushed.
    git remote add origin remote repository URL
    # Sets the new remote
    git remote -v
    # Verifies the new remote URL
    
  9. Push the changes in your local repository to GitHub.
    git push -u origin master
    # Pushes the changes in your local repository up to the remote repository you specified as the origin

Context path when the war deployed to tomcat

Most of the times, the name of the war file acts as the context path.

The Context path attribute is ignored unless the path is specified in a hard-coded Context in server.xml, which is strongly discouraged, and doesn't take multilevel paths.
The name of the war file, or the name of the Context xml file in tomcat/conf/Catalina/hostnamebecomes the path of the deployed application.
In your case the latter of the two above is the solution, just make sure you put the .war file outside of the designated appBase for the Host, or you'll deploy the app twice.
In: conf/Catalina/localhost/myapp#path.xml
<?xml version="1.0"?>
<Context docBase="/some/path/to/myapp.war">
</Context>