11 October, 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. notpad,textpad etc). I have used here Eclipse IDE (Oxygen) for development.

Below is the example :-

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


OutPut :-
First Java Project



Reverse a String in Java - 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.javadevelopersguide.www;
/**
 * This example will help you to reverse a string using StringBuilder.
 *
 * @author manojkumar.bardhan
 *
 */
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 really worried about thread saftey
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


Hope it will help you.