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 179<br />

import statement<br />

The import statement loads a specific class or classes from a referenced package. It must be placed at the top of a<br />

code file after the package declaration.<br />

import java.io.InputStream; /*Now it is allowed to use InputStream<br />

class without referencing its full name including the package*/<br />

import java.util.*; /*This is a star import which loads all<br />

classes contained in java.util package*/<br />

Since J2SE 5.0 it is allowed to do static imports, which allows to access members (fields and methods) defined in the<br />

imported class as public static without specifying the class name:<br />

import static java.lang.System.out;<br />

public class HelloWorld {<br />

}<br />

public static void main(String[] args) {<br />

}<br />

Operators<br />

out.println("Hello World!"); /*Without the static import it would<br />

be required to write "System.out" instead of just "out".*/<br />

Operators in Java are mostly similar to those in C++. There's no delete operator due to garbage collection<br />

mechanisms in Java and no operations on pointers since Java does not support them, another difference is that Java<br />

has unsigned right shift operator (>>>). Operators in Java cannot be overloaded.<br />

Precedence Operator Description Associativity<br />

1 () Method invocation Left-to-right<br />

[] Array access<br />

. Class member selection<br />

2 ++ -- Postfix increment and decrement<br />

3 ++ -- Prefix increment and decrement Right-to-left<br />

+ - Unary plus and minus<br />

! ~ Logical NOT and bitwise NOT<br />

(type) Type cast<br />

new Class instance or array creation

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

Saved successfully!

Ooh no, something went wrong!