Upload
killer111985
View
228
Download
0
Embed Size (px)
Citation preview
8/10/2019 Lecture 1 IE
1/55
1
Advanced ProgrammingMethodsLecture 1
8/10/2019 Lecture 1 IE
2/55
2
GradingLaboratory:--50%
- Assignments at each lab about 10 lab assigments! -- "5%- #irst Practical $est &am at LA'5 1 hour( o)en boo*!: -- 5%
- +econd Practical $est &am at LA'11 or LA'12 or LA'1" 2hours( o)en boo*!: --10%
#inal e&am: -- 50%
- ,ritten &am about 1 hour( closed boo*s!: --20%
- Practical &am about hours( one )roblem in .ava( one)roblem in / ( o)en boo*s!: --"0%
+eminar:
- your contribution ill be ta*en into account or the rounding othe inal mar*
8/10/2019 Lecture 1 IE
3/55
"
3ules - you have to )resent each assignment at its deadline
- each ee* o the assignment delay means -1)oints rom thatassigment mar*
- i you delay an assignment more than ee*s you ill get thegrade 1 or it
- i you ill not come to a lab )ractical e&am you ill get 1 or thate&am
- in order to get into the inal e&am your average grade or the labactivities assigments 4 2 lab )ractical tests! must be at least 5
- in order to )ass the inal e&am you must have at least 5 at theinal ritten e&am and at least 5 at the inal )ractical e&am such
that the inal grade must be at least 5
- you can )ass either both the inal ritten e&am and the inal)ractical e&am or nothing
8/10/2019 Lecture 1 IE
4/55
3ules or the second e&amrestanta6!
- in order to )ass the inal second e&am you must have at least 5
at the inal ritten e&am and at least 5 at the inal )ractical e&am
- you can )ass either both the second inal ritten e&am and the
second inal )ractical e&am or nothing - at the second e&am restanta6 you can )resent or re-)resent
ma&imum 5 lab assigments in order to im)rove your labactivities mar*
8/10/2019 Lecture 1 IE
5/55
5
/ourse in ormation
htt):77 8cs8ubbclu98ro7 craciun 7MetodeAvansate;ePr ogramare7
8/10/2019 Lecture 1 IE
6/55
=
Lectures >vervie>b9ect-oriented languages:
- .ava
- /
Lecture 1 and Lecture 2 Lab 1( Lab2( and +em1!:.ava basics
Lecture " and Lecture Lab "( Lab ( and +em2!:/ basics
A ter lectures and labs! :
- )ractical e&am at the lab( you ill be able torite sim)le >> )rograms in .ava and /
8/10/2019 Lecture 1 IE
7/55
8/10/2019 Lecture 1 IE
8/55
.ava $echnology
8/10/2019 Lecture 1 IE
9/55
.ava language
@ariables;eclaration:
type name_var1[=expr1][, name_var2[=expr2]];
Primitive ;ata $y)es
$y)e r8 byte @alues ;e ault value
boolean - true( alse alse
byte 1 -12B C 412? byte!0
short 2 -2 15 C2 15-1 short!0
int -2 "1 C2 "1 -1 0
long B -2 =" C2 =" -1 0L
loat < ?5 080
double B < ?5 080d
char 2 Dnicode 0( Dnicode 2 1=-1 EFu0000 null!
8/10/2019 Lecture 1 IE
10/55
.ava Language
&am)les: boolean gasit=true;
int numar=34, suma;float eroare=0 4!;"#ar litera=$"%;litera=$f%;litera=litera&1;
8/10/2019 Lecture 1 IE
11/55
.ava /omments 18 '' entire line
28 '( multiple lines ('"8 '(( use) by )o"umentation *ava)o" tool
multiplelines('
>bs: /omments canot be nested into strings8
'( '((' (' + - ./
'( '' ''
(' .//
8/10/2019 Lecture 1 IE
12/55
.ava /onstants
final type name [=value];
&am)les:a! final int =100;
b! final int ;
=100;C
=1!0; ''error
8/10/2019 Lecture 1 IE
13/55
Array Array ith one dimension
type[] name; type name[];
Array allocation:array_name=ne type[)im]; ''memory allo"ation
''in)ex 0 )im 1 Accessing an array element: arrayHname [in)ex]
&am)les:
float[] ve";
ve"=ne float[10];
int[] sir=ne int[3];float tmp[];tmp=ve"; ''ve" an) tmp refer to t#e same array
8/10/2019 Lecture 1 IE
14/55
>ne dimension Array
Built-in length : returns the array dimension8int[] sir=ne int[!];
int lung_sir=sir lengt#; ''lung=!;sir[0]=sir lengt#;sir lengt#=2; ''error
int[] y;int lung_y= y lengt#; ''error, y as not "reate)
)ouble[] t=ne )ouble[0];int lung_t=t lengt#; ''lung_t=0;t[0]=2 3 ''error5 in)ex out of boun)s
t#e s#ort"ut syntax to "reate an) initiali6e an array5int[] )x=7 1,0, 18;
8/10/2019 Lecture 1 IE
15/55
3ectangular multidimensional array
;eclaration:type name[][][][];
type[][][][] name;
/reation:
name=ne type[)im 1][)im 2][)im n]; Accessing an element:
name[in)ex 1][in)ex 2][in)ex n];
&am)les:
int[][] a;a=ne int[!][!];a[0][0]=2;int x=a[2][2]; ''x=9
8/10/2019 Lecture 1 IE
16/55
on-3ectangular Multidimensional Array
&am)les:int[][] a=ne int[3][];for:int i=0;i 3;i&&ab"?;s=s&?123?; ''"on"atenating stringsAtring t=s; ''t=>ab"123?t&=>12?; ''t=9, s=9
+tring content can not be changed: t[0]=$ %; "#ar "=t "#ar t:0
8/10/2019 Lecture 1 IE
18/55
>)eratorsarihtmetic: &, , (, ', F
relational: E, E=, , =, /=, ==increment7decrement: &&,
prefix5 int a=2;int b=&&a; ''a=2, b=2
postfix5 int a=2;
int b=a&&; ''a=3, b=2assignment: =, &=, =, (=, '=conditional: GG, HH, /
bit ise 5 shi t EE, , EEE,- conditional G, H, I :not
8/10/2019 Lecture 1 IE
19/55
>)erator )recedence>)erators Precedence higher )recedence on to)( the same )recedence on the same line!
18 Post i& expr&& expr
28 Dnari &&expr expr &expr expr I /
"8 ( ' F
8 &
58 EE EEE =8 E = E= instan"eof
?8 == /=
B8 G
K8 J
108 H
118 GG
128 HH
1"8 9 5
1 8 = &= = (= '= F= G= J= H= = EE= EEE=
8/10/2019 Lecture 1 IE
20/55
+tatements+eJuential /om)osition:
7 instr1;
instr2; 8
/onditional:
if :logi"a_expr
8/10/2019 Lecture 1 IE
21/55
Loo) +tatements,hile statement:
#ile:logi"al_expr3 statement:
for:initiali6ation;termination; stepbs: none o the initiali6ation, termination, step are mandatory
int suma=0for:int i=1;i 10;i&&< suma&=i;
for:int i=0,suma=0;i 10;i&&)erator ne 5
Xun"t p=ne Xun"t:
8/10/2019 Lecture 1 IE
41/55
;e ining methods[ ] "lass Dlass+ame7 [a""ess_mo)ifier] Cesult_-ype met#o)+ame:[list_formal_param]
8/10/2019 Lecture 1 IE
42/55
8/10/2019 Lecture 1 IE
43/55
>verloading methods A class may contain multi)le methods ith the same name but ith di erent signature8
A signature O return ty)e and the list o the ormal )arameters
publi" "lass Domplex7 private )ouble real, imag; '' "onstru"tors publi" voi) a)una :)ouble real
8/10/2019 Lecture 1 IE
44/55
.ava does not allo the o)erators overloading8/lass +tring has overloaded o)erators & and &=8Atring s=Uab"U;
Atring t=UMZ U; Atring r=s&t; s&=23; s&=\ \; s&=4 !;
''s=>ab"23 4 !?;''r=>ab"MZ ?
;estructor:
8/10/2019 Lecture 1 IE
45/55
>b9ects as Parameters>b9ects can be ormal )arameters or the methods
A method can return an ob9ect or an array o ob9ects8 publi" "lass Cational7 private int numarator, numitor;
''Donstru"tors
publi" voi) a)una:Cational r
8/10/2019 Lecture 1 IE
46/55
Passing argumentsPrimitive ty)e arguments boolean( int( byte( long( double! are )assed by value8 $heir
values are co)ied on the stac*8 Arguments o re erence ty)e are )assed by value8 A re erence to them is co)ied on thestac*( but their content ields or ob9ects( locations or array! can be modi ied i themethod has the rights to accces them8
18 $here is not any ay to change the )assing mode li*e Q in /44!8
"lass Xarametrii7 stati" voi) inters"#imba:int x, int y
8/10/2019 Lecture 1 IE
47/55
Passing arguments"lass S7
int val; publi" S:int x
8/10/2019 Lecture 1 IE
48/55
Passing arguments"lass S7
int val; publi" S:int x
8/10/2019 Lecture 1 IE
49/55
Array o ob9ectsach array element must be allocated and intialiIed8
publi" "lass -ablouri bie"te 7 stati" voi) generea6a:int nrMlem, Domplex[] t
8/10/2019 Lecture 1 IE
50/55
Array o ob9ects stati" Domplex suma:Domplex[] t
8/10/2019 Lecture 1 IE
51/55
$he methods to+tring and eJuals
publi" "lass Domplex7 private )ouble real, imag; publi" Domplex:)ouble re, )ouble im
8/10/2019 Lecture 1 IE
52/55
+tatic methods
8/10/2019 Lecture 1 IE
53/55
+tatic methods$hey are called using the class name :
Domplex a,b;'' initiali6ation a an) b
Domplex "=Domplex a)una:a, b
8/10/2019 Lecture 1 IE
54/55
+tatic ields
publi" "lass +atural7 private long val;
publi" stati" long =232 ''2JN3 1 ''8
publi" "lass Xro)us 7 private stati" long "ounter; private final long i)="ounter&&;
publi" Atring toAtring:
8/10/2019 Lecture 1 IE
55/55
+tatic ields