29.04.2013 Views

J. Introducere in limbajul Java - Discipline

J. Introducere in limbajul Java - Discipline

J. Introducere in limbajul Java - Discipline

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Curs SwRTc (draft) 2004-2005 23/34 10/22/2006 2006_Intro_<strong>Java</strong>_v01.htm<br />

J.4. Tipuri refer<strong>in</strong>ta<br />

J.4.1. <strong>Introducere</strong> <strong>in</strong> tipuri refer<strong>in</strong>ta <strong>Java</strong><br />

Tipurile refer<strong>in</strong>ta <strong>Java</strong> sunt:<br />

• tipul tablou,<br />

• tipul clasa si<br />

• tipul <strong>in</strong>terfata.<br />

Variabilele de tip refer<strong>in</strong>ta sunt:<br />

• variabile tablou, al caror tip este un tablou,<br />

• variabile obiect, al caror tip este o clasa sau o <strong>in</strong>terfata.<br />

Variabilele de tip refer<strong>in</strong>ta cont<strong>in</strong>:<br />

• refer<strong>in</strong>ta catre tablou sau obiect (creata <strong>in</strong> momentul declararii),<br />

• tabloul sau obiectul propriu-zis (creat <strong>in</strong> mod d<strong>in</strong>amic, cu operatorul new).<br />

Notatie generala:<br />

numeVariabilaTipRefer<strong>in</strong>ta<br />

refer<strong>in</strong>ta la<br />

tablou sau obiect tabloul sau obiectul<br />

propriu-zis<br />

Programatorul nu are acces la cont<strong>in</strong>utul refer<strong>in</strong>telor (ca <strong>in</strong> alte limbaje, cum ar fi C si C++,<br />

unde po<strong>in</strong>terii si refer<strong>in</strong>tele pot fi accesate si tratate ca orice alta variabila), ci la cont<strong>in</strong>utul<br />

tablourilor sau al obiectelor referite.<br />

Pe de alta parte, programatorul nu poate avea acces la cont<strong>in</strong>utul tablourilor sau al obiectelor<br />

decat pr<strong>in</strong> <strong>in</strong>termediul refer<strong>in</strong>telor catre ele.<br />

O valoare pe care o pot lua refer<strong>in</strong>tele este null, semnificand refer<strong>in</strong>ta “catre nimic”. Simpla<br />

declarare a variabilelor refer<strong>in</strong>ta conduce la <strong>in</strong>itializarea implicita a refer<strong>in</strong>telor cu valoarea<br />

null.<br />

numeVariabilaTipRefer<strong>in</strong>ta<br />

null<br />

refer<strong>in</strong>ta catre nimic<br />

J.4.2. Tablouri cu elemente de tip primitiv<br />

J.4.2.1. Componentele <strong>in</strong>terne ale unui tablou <strong>Java</strong><br />

Un tablou <strong>Java</strong> este o structura care cont<strong>in</strong>e mai multe valori de acelasi tip, numite elemente.<br />

Lungimea unui tablou este stabilita <strong>in</strong> momentul crearii tabloului, <strong>in</strong> timpul executiei (at<br />

runtime). Dupa crearea d<strong>in</strong>amica a structurii, tabloul este o structura de dimensiune fixa. Asadar,<br />

lungimea nu poate fi modificata.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!