Skip to content

Instantly share code, notes, and snippets.

@kellydunn
Created December 10, 2010 19:06
Show Gist options
  • Save kellydunn/736627 to your computer and use it in GitHub Desktop.
Save kellydunn/736627 to your computer and use it in GitHub Desktop.
Rassul's Java Lessons 1 : Variables
public static void letsLearnJava() {
int x = 2;
int y = 2;
int z = x + y;
// The println function is smart enough to wrap the int value into a String variable :)
System.out.println(z); // prints "4".
}
// Less redundant. You don't need the z variable.
public static void letsLearnJava() {
int x = 2;
int y = 2;
System.out.println(x + y); // prints "4"
}
// SCOPE ERROR
// You don't have access to variables outside of the methods you declare them in
public static void badScope() {
System.out.println(x); // Exception thrown. Java is sad :(
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment