Введение в программирование
Синтаксис Java
| Имя | float | double |
|---|---|---|
| Биты | 32 | 64 |
| Мантисса | 23 | 52 |
| Экспонента | 8 | 11 |
| Экспонента | -126..127 | -1022..1023 |
| Обертка | Float | Double |
int[][][]
Integer[][]
new Integer[3][]
new int[]{10, 20, 30}Integer[][] a = {{0, 1}, {2}}Object o = new int[3];
String[] strings = new String[10]; Object[] objects = strings; objects[0] = new Object(); String string = strings[0];
int a = …; new Integer(a)
Integer a = …; a.intValue()
(Integer) 10
(int) new Integer(10)
(Object) 10
Integer i1 = 1; Integer i2 = 2; Integer i3 = i1 + i2;
Integer i1 = Integer.valueOf(1);
Integer i2 = Integer.valueOf(2);
Integer i3 = Integer.valueOf(i1.intValue() +
i2.intValue());
final int a;
final int b;
if (условие) {
a = 1;
b = 10;
} else {
a = 3;
b = -2;
}
switch (input) {
case 'y': case 'Y':
return true;
case 'n': case 'N':
return false;
default:
// Error?
break;
}
try { … }
catch (…) { … }
catch (…) { … }
finally { … }
[доступ] [abstract] [strictfp] interface Name
[extends Interface1, Interface2] {
// Поля и методы
}
[public] [abstract] тип имя(аргументы);
[public] default тип имя(аргументы) { … }
[public] [static] [final] тип ИМЯ [= выражение];
static { … } [доступ] [abstract|final] [static] [strictfp]
class Name [extends Parent]
[implements Interface1, Interface2] {
// Поля
// Инициализаторы
// Конструкторы
// Методы
// Вложенные классы
}
[доступ] [static] [final] тип имя [= выражение];
{ … } [доступ] [strictfp]
имя([final] Тип₁ арг₁, [final] Тип₂ арг₂, …) {
[super(…)|this(…)]
…
}
[доступ] [static] [final] [strictfp] [native]
Тип имя(аргументы)
{ … }
[доступ] [abstract] Тип имя(аргументы);
class Внешний {
class Внутренний {
// Доступ Внешний.this
}
}
внешний.new Внутренний(…)
class Внешний {
static class Вложенный {
// Нет доступа к Внешний.this
}
}
void method() {
class Local { … }
}
Shape shape = new AbstractShape() { … }