Thursday, October 12, 2017

Write Your First Java Program

This is very basic startup for your learning java programming language. Before writing and executing this you should make sure that you have installed the expecting JDK. This JDK is mandatory, apart from this JDK you need some IDE (i.e. Eclipse,Netbean, Jboss developer studio etc). These IDE are not mandatory ,but now-a-days these are very common to make your development easy. 

You can run the below java program on command line also  by using any text editor (i.e. notepad,text pad etc). I have used here Eclipse IDE (Oxygen) for development.

Below is the example :-

package com.techbyteslearn;
/**
 *
 * @author techbyteslearn
 *
 */
public class FristJavaProgram {
public static void main(String[] args) {
System.out.println("Welcome To Java");
}
}


OutPut :-
First Java Project

Reverse a String in Java Using Java API

Reverse a string using java existing API is really very easy. Below example will show you how to reverse the string using StringBuilder class.
package com.techbyteslearn.www;

public class ReverseString {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String inputString = "javadevelopersguide";

        System.out.println("Before Reverse:: " + inputString);

        // You can do this using StringBuffer also, based on your requirement.
        // If you are concerned about thread safety, use StringBuffer.
        StringBuilder builder = new StringBuilder(inputString).reverse();

        // After reverse using StringBuilder
        inputString = builder.toString();

        System.out.println("After Reverse:: " + inputString);
    }
}
Output :-

Before Reverse::javadevelopersguide
After Reverse:: ediugsrepolevedavaj