Pages

Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Convert String to Int


Convert string to int variable that may do arithmetic operaton.
Here is the code to convert
{
     String month="25";
     int count=0;
     count=count+Integer.parseInt(month);
     System.out.println("Count is " + count);
}

Output :
Count is 25

Using indexOf()

indexOf function is used to find the character in a String. It will return '-1' on failure i.e. no character found in a String else it will return the position of the character.

Example
public class example
{
    public static void main(String[] args)
    {
          String email="example@gmail.com";
          int pos=email.indexOf('@');
          if(pos!=-1)
          {
                  System.out.println("@ Special Character Found in a postion "+pos);
           }
          else
          {
                  System.out.println("@ Special Character Not Found");
          }
     }
}
Output
@ Special Character Found in a postion 7

Remove Special Characters in a String - Java

To remove special characters in a string, replaceAll is used.Example of replaceAll follows below











public class example
{
     public static void main(String[] args)
     {
          String price="$5.00";
          String newPrice=price.replaceAll("\\$","");
          System.out.println("New Price "+newPrice);
     }
}

Output:
New Price 5.00

Difference between Java and Javaw exe

There will be a bit confusion between java and javaw exes in JDK bin folder, the path is (where the jdk is placed directory)


c:/Program Files/Java/JDK/bin/java.exe
c:/Program Files/Java/JDK/bin/javaw.exe



Both will do the similar work and will run in same environment (Windows). But have one key difference in common.

java.exe is the console app, if want to work in console executing any java code without any IDE(Eclipse,Netbeans) java.exe will execute and run.

c:/Program Files/Java/JDK/bin/Java FirstApp.java

javaw.exe is windows app (console-less). You can't have Console with javaw.exe. If  working in IDE like Eclipse,javaw.exe will run in the system.