MLHA - PC - Software - Programmering - Java >Applets >Applications
>Packages & Classes

v Data types, Operators, Keywords, Definition, Flow control, Functions, Comments

java.sun.com
The Java Tutorial
Java Standard Edition Platform Documentation
Products
JDK 1.0
JDK 1.1
JDK 1.2
JavaWorld
Java Boutique
grunge.cs.tu-berlin.de/~tolk/vmlanguages.html : Programming Languages for the Java Virtual Machine
www.andromeda.com/people/ddyer/java/Reviews.html : Reviews of JAVA tools
www.webdeveloper.com/java/java_ides.html : Java IDEs
JavaCats
www.javacats.com/US/search/dir005.html : Programming in Java
www.javacats.com/US/search/dir153.html : Java Development Tools

Program development

Download: Sun Java Development Kit (JDK)
Java Decompiler: Jad

Data types

integer
   byte : 8-bit signed
short : 16-bit signed
int : 32-bit signed : int count;
int count = 0;
int[] intArray;
int[] intArray = new int[10];
long : 64-bit signed
real
float : 32-bit IEEE 754
double : 64-bit IEEE 754
char
char : 16-bit unicode : char data[] = {'a', 'b', 'c'};
boolean
boolean : true, false

Operators
v unary, binary, assignment, boolean, bit-logical

unary
+	+op	promotion of byte, short, char to int
-	-op	negation
binary
+
-
*
/	op1 / op2
&	op1 % op2    //modulus
assignment
++ 	op++         //op = op + 1
-- 	op--         //op = op - 1
+= 	op1 += op2   //op1 = op1 + op2
-=
*=
/=
%=
&=
|=
^=
<<=
>>=
>>>=
boolean
relational
>      
>=
<
<=
==
!=
instanceof op1 instanceof op2 //true, if op1 and op2 are assignment compatible
 
conditional
&&	op1 && op2   //and - conditionally evaluates op2
||	op1 || op2   // or - conditionally evaluates op2
!	!op          //not
&	op1 & op2    //and - always evaluates op2
|	op1 | op2    // or - always evaluates op2
?	expression ? op1 : op2
 
bitwise, logical
<<   op1 << op2  //shift op1 left op2 bits
>>   op1 >> op2  //shift op1 right op2 bits unsigned
>>>  op1 >>> op2 //shift op1 right op2 bits signed
&    op1 & op2   //bitwise and
|    op1 | op2   //bitwise or
^    op1 ^ op2   //bitwise xor
~    ~ op        //bitwise complement

Keywords (reserved)
abstract, boolean, break, byte, case, catch, char, class, const, double, else, extends, final, finally, float, for, goto, if, int, interface, long, native, new, null, package, private, protected, static, super, switch, synchronized, this, throw, throws, transient, try

abstract
boolean
byte
char
const
default
double
final
// constant variable
final int pi = 3.1416;

// may be set later - once
final int max;
---
max = 100;
float
goto
implements
instanceof
int
int count = 0;
interface
long
native
new
int[] arrayOfInts; //no space allocated

// allocate space for 10 ints:
int[] arrayOfInts = new int[10];

string[] arrayOfStrings = new String[10];
// space for 10 string-pointers is now allocated
// but no space for the strings!
// so, allocate some space for the strings:
for( int i=0; i<arrayOfStrings.length; i++)
  arrayOfStrings[i] = new String("String #" + i);
null
package
private
protected
short
super
synchronized
this
throws
public static void countChars( Reader in) throws IOException
transient
volatile

definition : class, extends, import, public, static, void,

class
ex:
class HelloWorldApp
//this class is placed in the default package
{ //variables and methods
  public static void main(String[] args)
  { . . .
  )
}
extends
indicates a subclass of a class
ex:
import java.applet.Applet;
public class HelloWorld extends Applet
ex:
public class HelloWorld extends java.applet.Applet
import
By importing classes or packages (groups of classes), a class can refer to other classes.
NB: the lang package is automatically imported.
class import Ex:
import java.applet.Applet;
import java.awt.Graphics;
package import Ex:
import java.applet.*;
import java.io.*;
public
public : allows any class to call this method
ex:
public static void main()
public class count()
static
static : a class method
ex:
public static void main()
void
void : the method returns no value
ex:
public static void main()
 

flow control, loops : do...while, for, if...else, switch...case, while

break
continue
do ... while
do
{ statements
} while( condition);
for
for( initialization; termination; increment)
  statement;
for( int i=0; i<10; i++) ...
if ... else
if( expression) statement;
else statement;
try ... catch ... finally
return
switch ... case
switch( variable)
{ case val1: statement1; break;
  case val2: statement2; break;
  ---
  default: statement;
}
throw
while
ex:
int count = 0;
while( in.read() != -1)
count++;

Functions

Ex:
public static void main( String[] args) throws IOException
{ if ( args.length >= 1)
    countChars( new FileReader( args[0]));
  else
    System.err.println("Usage: Count filename");
}

Comments

// text
text is ignored by the compiler javac
/* text */
text is ignored by the compiler javac
/** documentation */
documentation is ignored by the compiler javac
but used by javadoc for automatically generated documentation