Contact Our Development Team
Free Code Tutorials & Open Source Code
Java Basics
Tutorials > Java > Basics
Java Basics
This tutorial has been design to provide the basics of Java Programming. There is a fair amount to learn, however if you can program in other languages, this should provide most of the syntax you will need to familiarize yourself with.
Java - If Statement
There are quite a few variables in Java, so here we are going to jump right in with the if statement!
public class IfTutorial{
	public static void main(String[] args){
		String test = "Hello World";
		if(test.equals("Hello World")){
			System.out.println("Yes, the string equals \"Hello World\"!");
		}
	}
}
Yes, the string equals "Hello World"!
The reason for the backslash '' before the quote '"' on the System.out.println(..) is that is provides an 'escape' so the String does not terminate. Like in most other languages, Java provides 'else' and 'else if' to handle other cases as shown below:
public class IfTutorial{
	public static void main(String[] args){
		String test = "Hello";
		if(test.equals("Hello World")){
			System.out.println("Yes, the string equals \"Hello World\"!");
		} else {
			System.out.println("No, this string does not equal \"Hello World\"!");
		}
	}
}
No, this string does not equal "Hello World"!
Page Responses
Currently there have been no responses to this page...
If you have anything to contribute to this tutorial, found a bug, or know a better way of achieving the same goal, please leave your response below.
     
Copyright ©2009, Wired IDS Ltd. | Licensed under Creative Commons Attribution Share-Alike | Load time: 0.3066 seconds