OPI_LR2011_ch3
.pdf91
? , + . ? ,
+ .
3)Patient: id, ' i, 0' , ' , 5, ; +, :
, E. > 'f. ?:) f, i @ ;
) f, f
.
> g
+.
4)Abiturient: id, ' i, 0' , ' , 5, ; +,
.. > 'f. ?:
) f, i @ ;
) f, i ;
) n f, i @ i
( ( f, i @
).
> .
5)Book: id, :, 5( ), ?, = , C
, D, .. > 'f. ?:) ;
) , i ;) , i .
g . '
@ ( .
6)House: id, : , ' i, ', C , ?, ; , > . >
'f. ?:
) , i @ ;
) , i @
g , i f (;
) , i @ i, i g f . > . .
.
92
7)Phone: id, ' i, 0' , ' , 5, :
, E, C, / ( . > 'f. ?:
) ,
i f ;
) , (' ;
) @.
, + @ .
8)Car: id, , , = , C, D, = f . > 'f. ?:
) ;) , @
g n ;
) , g
.
? ( ( . >
'f (.
9)Product: id, :, ?, D, > , C. > 'f. ?:
) ;) ,
g f ;
) , g . > ( , ) I(1..n) U(1..n) n-
R. ( R
g .
10)Train: ' , : , / , /
( , , , @).> 'f. ?:
) , i ;
) , i
@ ;
93
) , i @
.
(
:
g @ ,
@ g . . ,
g .
11)Bus: ' i , : , : g,
, = , '.> 'f. ?:
) g;
) , @ g 10 ;
) , g 100000 . :
@ ( 'f, ’f
, - .
: @ ( 'f,
, - .
12)Airlines: ' , : , ; , /
, E (. > 'f. ?:) ;) (;
) (,
g .
, i f '(', ')', '[', ']', '{', '}'. ' i (. ? .
7.3.4.+ .
7.3.5? .
7.4 !, #",
7.4.1; .
7.4.2.
7.4.3C .
7.4.4; .
7.4.5= .
94
7.4.6 ?, i
(5 g. ), ( ( @
.
7.5 7] , # 4 )
7.5.1. Vector Java?
7.5.2G , Vector ?
f?
7.5.3. Stack Java?
7.5.4G , Stack ?
f?
7.5.5. Hashtable Java?
7.5.6G , Hashtable
? f?
7.5.7. Properties Java?
7.5.8G , Properties
? f?
7.5.9. + Collection Java?
7.5.10G , +
Collection ? f?
95
8 ? 8 8 8 ? 8
->
8.1( 4
: @ - Java.
8.2 " , ( ( 4-, ",9 ! ,
8.2.1 8 # ! 4" !4
8 # ! 4" !4
Arrays java.util
.
? @
'f . ? @
static void sort(type[] a)
type ( byte, short, int, long, char, float, double Object.
? ( @
from @ to @:
static void sort(type[] a, int from, int to)
E @
object , 'f c, i f
+ Comparator:
static void sort(Object[] a, Comparator c)
static void sort(Object[] a, int from, int to, Comparator c)
' ( g
' g. ? @
static int binarySearch(type[] a, type element)
type - ( . E' g f
static int binarySearch(Object[] a,Object element,Comparator c)
? g f element ,
, 'f .
96
g @
. G i , f ’f , i f .
? @@
value:
static void fill(type[], type value)
static void fill(type[], int from, int to, type value)
type - object. E' @@ :
static boolean equals(type[] a1, type[] a2)
type - Object.
( @ , i @
( ,
f true.
' 8.1 - . ' 8.1. Arrays:
import java.utii.*; class ArraysTest{
public static void main(String[] args){
int[] a = {34, -45, 12, 67, -24, 45, 36, -56}; Arrays.sort(a) ;
for(int i = 0; i < a.length; i++) System.out.print(a[i]. + " "); System.out.println();
Arrays.fill(a, Arrays.binarySearch(a, 12), a.length, 0); for(int i = 6; i < a.length; i++)
System.out.print(a[i] + " "); System.out.println();
} }
8.2.2 1 7] , "14
> + - " ", f
'f Locale java.util. E 'f
language country. 0
- variant, i f ,
, "WIN", "MAC", "POSIX".
@ @
@ @ .
user.language = ua |
// h2@= - 429857/7 |
user.region = UA |
// h89_O@89:; - 12985 |
file.encoding = Cpl251 |
// •=>:2@O P26N@=775 - CP1251 |
? @
. e,
97
g, f , ( '
Locale.getDefault.
? Locale f :
Locale(String language, String country)
Locale(String language, String country, String variant)
' language - ,
ISO639, , "ua", "fr", "en". ' country -
, ISO3166,
, "UA", "US", "EN". ' variant f
, , "Traditional".
e @ "ru_RU", "en_EN", "en_US", "en_CA " . .
' ( @
:
Locale.setDefault(Locale newLocale);
E Locale @ (
:
–string get>ountry() – ;
–string getDisplayCountry() – f ;
–String getDisplayCountry(Locale locale) – (
.
; ( f .
( ,
JVM, :
Locale[] getAvailableLocales() String!] getISOCountries() String[] getISOLanguages()
f
+.
8.2.3 8 # 9 !4 -!
: Calendar Date java.util.
.'f Date f , i g 1
1970 . 00:00:00 ’.
C Date (
.
. ( , (
System.currentTimeMillis()
98
Date . C Date()
@ 'f g, f
, , Date(long millisec) - .
. ( , i f 'f, (
long getTime(), - setTime(long newTime).
; @@ :
–boolean after(long when) – f true, i when g
;
–boolean before(long when) – f true, i when
g ;
–boolean after(Object when) – f true, i when - 'f
ca Date @.
‘ , @@ , @ ’f
int, i g when; , i
@; , i g when:
–int compareTo(Date when);
–int compareTo(object when) – i when
'f Date, f .
' , i @ 'f
Date, calendar.
7 Calendar
C Calendar – ,
: @, , .
. calendar – ,
@@ /
:
Calendar getlnstance()
Calendar getlnstance(Locale loc) Calendar getlnstance(TimeZone tz)
Calendar getlnstance(TimeZone tz, Locale loc)
E
JANUARY DECEMBER, -
MONDAY SUNDAY.
' g ( ( int getFirstDayOfWeek(), a – setFirstDayOfWeek(int day), :
setFirstDayOfWeek(Calendar.MONDAY)
99
0 g @
.
3,917 GregorianCalendar
@ : BC(before Christ) AD(Anno Domini).
> @ ,
/ :
GregorianCalendar()
GregorianCalendar(int year, int month, int date) GregorianCalendar(int year, int month, int date, int hour, int minute)
GregorianCalendar(int year, int month, int date, int hour, int minute, int
second)
GregorianCalendar(Locale loc) GregorianCalendar(TimeZone tz) GregorianCalendar(TimeZone tz, Locale loc)
' 'f
@
setGregorianChange(Date date). 15 ( 1582 .:
GregorianCalendar greg = new GregorianCalendar(); greg.setGregorianChange(new GregorianCalendar(200+, Calendar.FEBRUARY, 14).getTime()) ;
E, f , ( isLeapYear().
get(int field) f ,
field. E Calendar
:
ERA |
WEEK_OF_YEAR |
YEAR |
WEEK_OF_MONTH |
MONTH |
DAY_OF_YEAR |
DATE |
DAY_OF_MONTH |
DAY_OF_WEEK |
SECOND |
DAY_OF_WEEK_IN_MONTH |
MILLISECOND |
HOUR_OF_DAY |
ZONE_OFFSET |
MINUTE |
DST_OFFSET |
C set(), i @ ,
@@ .
3 9 ) 9 4 -
= (
, DateFormat
SimpleDateFormat Java.text.
C DateFormat f :
–SHORT f
: 27.04.01 17:32;
–MEDIUM f + f
: 27.04.2001 17:32:45;
–LONG f f
: 27 2001 . 17:32:45 GMT+02.00;
100
– FULL (, LONG; @
>•5 – f i (.
6 i DEFAULT, i f MEDIUM. ? g + g, : SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy
hh.mm"); System.out.println(sdf.format(new Date()));
. ( : 27-04-2001 17.32.
: ( 'f
SimpleDateFormat. @
getInstance() DateFormat, i @ 'f
DateFormat.
' 'f format() DateFormat
f @ , @. G
f 'f Date. ::
System.out.println("LONG: " + DateFormat.getDateTimelnstance(DateFormat.LONG, DateFormat.LONG).format(new Date()));
System.out.println("FULL: " + DateFormat.getDateTimelnstance( DateFormat.FULL, DateFormat.FULL, Locale.US).format(new Date()));
8.2.4 9( o ) "4 91 "4D -4 (7
. ( `f , g ,
double ( random()
java.lang.Math.
' g @f
, i f (
.
m g (
@ Random java.util.
:
Random (long seed) – @f
, f seed; Random() -
f .
> g , ( (
nextBoolean(), nextDouble(), nextFloat()(, nextGaussian(), nextInt(), nextLong(), nextInt(int max)