Java.txt

(4 KB) Pobierz
Typy
====

byte - 8b
short - 16b
int - 32b
long - 64b
float - 32b
double - 64b
char - 16b, Unicode
boolean - true, false

Klasy: Character, Boolean, Integer, Float itp. z java.lang
static int MAXVALUE
static int MINVALUE
konstruktor Integer(int i)
konstruktor Integer(String s)
int intValue()
byte byteValue() itd...
String toString()
static int parseInt(String s)
static Integer valueOf(int i)

String, StringBuffer

123.4 - typu double
123.4f, 123.4F - typu float
123.4d, 123.4D - typu double
123l, 123L - typu long
'A' - typu char
false - typu boolean

Tablice, klasy i interfejsy s? referencjami.

final float PI = 3.14f;
  sta?a

Warto?? null.

char[] helloArray = { 'h', 'e', 'l', 'l', 'o' };

String:
(java.lang.String)
int length()
char charAt(int Index)
String substring(int Begin, int End)

StringBuffer:
void append(char Ch)
void insert(int Index, String s)
String toString()

Konwersja co? > ?a?cuch:
int i = 123; String s = String.valueOf(i);
Konwersja ?a?cuch > co?:
String s = "123"; int i = Integer.valueOf(s);

System.out.println(String s)


Operatory
=========

+ - * / % ++ --
> >= < <= == !=
! ^ ~
&& || - ewaluacja jednego lub obydwu argument?w
& | - ewaluacja zawsze obydwu argument?w
>> << >>>
+= itd...
is as instanceof


Instrukcje
==========

if (warunek)
	instrukcja1;
[ else
	instrukcja2; ]

switch (wyra?enie)
{
	case Sta?a1: Instrukcja1;
	case Sta?a2: Instrukcja2;
	...
	[ default: InstrukcjaX; ]
}

while (wyra?enie)
	instrukcja;

do
	instrukcja
while (wyra?enie);

for (wyra?enie1; wyra?enie2; wyra?enie3)
	instrukcja;

{
	instrukcja1;
	instrukcja2;
	...
}

break;

continue;


Klasy
=====

private, public, protected, package

Klasa:
abstract - cannot be instantiated
final - cannot be inherited

Pola:
static
final - nie mo?e by? zmieniane

Metody:
static
abstract
final - cannot be overriden
native - impemented in other language
synchronized


public class Klasa1 extends KlasaBazowa implements InterfejsA
{
	int Pole1 = 123;

	Klasa1()
	{
		// Konstruktor...
	}
	
	Klasa1(int X)
	{
		// Konstruktor z parametrem...
	}
}

Mo?na przeci??a? metody.

this - m?j obiekt
super - odwo?anie do klasy bazowej

Klasa bazowa: java.lang.Object
Object clone()
	interfejs Cloneable
bool equals(?)
? hashCode(?)
? finalize(?)
? toString(?)
? getClass(?)
notify, notifyAll, wait

Nested Classes
Inner Classes


Wyj?tki
=======

Klasa Throwable, Exception

try
{
	...
}
catch (ExceptionClass1 ExceptionObject)
{
	...
}
catch
	...
[ finally
{
	...
} ]

void Metoda1()
	throws Wyjatek1, Wyjatek2, ...
{
	// Tre??...
}

throw new Wyjatek1(...);


W?tki
=====

Spos?b 1
--------

public class MojWatek1 extends Thread
{
	public MojWatek1()
	{
		...
	}
	
	public void run()
	{
		// kod osobnego w?tku
	}
}

MojWatek1 watek1 = new MojWatek1();
watek1.start();
watek1.join();

Spos?b 2
--------

public class MojWatek2 implements Runnable
{
	private Thread myThread = null;

	public void start()
	{
		if (myThread == null)
		{
			myThread = new Thread(this, "Nazwa w?tku");
			myThread.start();
		}
	}
	
	public void run()
	{
		...
	}
}

void Thread.sleep(int Miliseconds)
isAlive


try
{
	sleep((int)(Math.random() * 100));
} catch (InterruptedException e) { }

Synchronizacja
--------------

- Metody synchronized
- instrukcja synchronized (Obiekt1) { ... }
- wait(), notify(), notifyAll()
	wait()
	wait(long timeout)
	wait(long timeout, int nanos)

Grupowanie
----------

ThreadGroup Grupa1 = new ThreadGroup("NazwaGrupy1");

Konstruktory Thread:
public Thread(ThreadGroup group, Runnable runnable)
public Thread(ThreadGroup group, String name)
public Thread(ThreadGroup group, Runnable runnable, String name)

Thread:
getThreadGroup()
getName()
resume, stop, suspend

ThreadGroup:
int activeCount()
activeGroupCount()
Thread[] list()
getMaxPriority, setMaxPriority
getDaemon, setDaemon
getName
getParent, parentOf
toString
resume, stop, suspend


Random
======

java.util.Random
konstruktor Random()
konstruktor Random(long Seed)
boolean nextBoolean()
double nextDouble() - 0 .. 1
float nextFloat()
int nextInt()
int nextInt(int n) - 0 .. n-1


ArrayList (1.4.2)
=========

java.util.ArrayList
konstruktor ArrayList()
konstruktor ArrayList(int InitialCapacity)
void add(int i, object o)
boolean add(Object o)
void clear()
boolean contains(Object o)
Object get(int i)
int indexOf(Object e)
boolean isEmpty()
Object remove(int i)
int size()
Object set(int i, Object o)
Zgłoś jeśli naruszono regulamin