14.07.2013 Views

Contents - Cultural View

Contents - Cultural View

Contents - Cultural View

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Java syntax 177<br />

Double quote \"<br />

Tab \t<br />

Backspace \b<br />

Integer literals are of int type by default unless long type is specified by appending L or l suffix to the literal, e.g.<br />

367L.<br />

Variables<br />

Variables are identifiers associated with values. They are declared by writing the variable's type and name, and are<br />

optionally initialized in the same statement by assigning a value.<br />

int myInt; /* Declaring an uninitialized variable called 'myInt',<br />

of type 'int' */<br />

myInt = 35; // Initializing the variable<br />

int myInt = 35; // Declaring and initializing the variable at the same time<br />

Multiple variables of the same type can be declared and initialized in one statement using comma as a delimiter.<br />

int a, b; // Declaring multiple variable of the same type<br />

int a = 2, b = 3; // Declaring and initializing multiple variables of the same type<br />

Code blocks<br />

The operators { ... } are used to signify a code block and a new scope. Class members and the body of a method are<br />

examples of what can live inside these braces in various contexts.<br />

Inside of method bodies you can use the braces to create new scopes like so:<br />

void doSomething() {<br />

}<br />

int a;<br />

{<br />

}<br />

a = 2;<br />

int b;<br />

a = 1;<br />

b = 3; // Will fail because the variable is declared in an inner scope.<br />

Comments<br />

Java has three kinds of comments: traditional comments, end-of-line comments and documentation comments.<br />

Traditional comments start with /* and end with */, they may span across multiple lines. This type of comments was<br />

derived from C and C++.<br />

/* This is a multi-line comment.<br />

It may occupy more than one line. */<br />

End-of-line comments start with // and extend to the end of the current line. This comment type is also present in<br />

C++ and in modern C.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!