- PC - Software - Programmering
- Java >Applets >Applications
>Packages & Classes
v Data types, Operators, Keywords, Definition, Flow control, Functions, Comments
|
Download: Sun Java
Development Kit (JDK)
Java Decompiler: Jad
| 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
+ +op promotion of byte, short, char to int - -op negation
+ - * / op1 / op2 & op1 % op2 //modulus
++ op++ //op = op + 1 -- op-- //op = op - 1 += op1 += op2 //op1 = op1 + op2 -= *= /= %= &= |= ^= <<= >>= >>>=
| > | ||||
| >= | ||||
| < | ||||
| <= | ||||
| == | ||||
| != | ||||
| instanceof | op1 instanceof op2 | //true, if op1 and op2 are assignment compatible |
&& 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
<< 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
// constant variable final int pi = 3.1416; // may be set later - once final int max; --- max = 100;
int count = 0;
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);
public static void countChars( Reader in) throws IOException
definition : class, extends, import, public, static, void,
ex:
class HelloWorldApp
//this class is placed in the default package
{ //variables and methods
public static void main(String[] args)
{ . . .
)
}
indicates a subclass of a class ex: import java.applet.Applet; public class HelloWorld extends Applet ex: public class HelloWorld extends java.applet.Applet
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 : allows any class to call this method ex: public static void main() public class count()
static : a class method ex: public static void main()
void : the method returns no value ex: public static void main()
flow control, loops : do...while, for, if...else, switch...case, while
do
{ statements
} while( condition);
for( initialization; termination; increment) statement; for( int i=0; i<10; i++) ...
if( expression) statement; else statement;
switch( variable)
{ case val1: statement1; break;
case val2: statement2; break;
---
default: statement;
}
ex: int count = 0; while( in.read() != -1) count++;
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");
}
// 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