Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

1. U sklopu JAVA programskog jezika KLASA ima dve fundamentalno razliite uloge. Navedite ih.

Classes in Java have two very different functions. First of all, a class can group together variables and subroutines that are contained in that class. These variables and subroutines are called static members of the class. You've seen one example: In a class that defines a program, the main() routine is a static member of the class. The parts of a class definition that define static members are marked with the reserved word "static", just like the main()routine of a program. However, classes have a second function. They are used to describe objects. In this role, the class of an object specifies what subroutines and variables are contained in that object. . , . . , main () . "static", main() . , . . , .. 2. ta se podrazumeva pod blokom (block statement) u sklopu JAVA programskog jezika? Koja je
njegova namena?

A block statement is just a sequence of Java statements enclosed between braces, { and }. The body of a subroutine is a block statement. Block statements are often used in control structures. A block statement is generally used to group together several statements so that they can be used in a situation that only calls for a single statement. For example, the syntax of a while loop calls for a single statement: "while (condition) do statement". However, the statement can be a block statement, giving the structure: "while (condition) { statement; statement; ...}". A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed. {} . . . ( while : "while (condition) do statement" : "while (condition) { statement; statement; ...}".

3. Pretpostavite da "crna kutija" poseduje interfejs i implementaciju. U emu se, u tom sluaju, sastoji
osnovna razlika izmeu pojmova interfejs i implementacija?

The interface of a black box is its connection with the rest of the world, such as the name and parameters of a subroutine or the dial for setting the temperature on a thermostat. The interface of a black box should be fairly straightforward, well-defined, and easy to understand. The implementation refers to internal workings of the black box. To use the black box, you need to understand its interface, but you don't need to know anything about the implementation. , . , . . , , . 4. Navedite dva osnovna razloga korienja imenovanih konstanti (deklaracija final) u sklopu JAVA
programskog jezika.

A constant has a meaningful name, which makes the program easier to read. It's easier to understand what a name like INTEREST_RATE is for than it is to figure out how a literal number like 0.07 is being used. A second reason for using named constants is that it's easy to modify the value of the constant if that becomes necessary. If a literal value is used throughout the program, the programmer has to track down each occurrence of the value and change it. When a constant is used correctly, it is only necessary to change the value assigned to the constant at one point in the program. A third reason is that using the final modifier protects the value of a variable from being changed. This is especially important for member variables that are accessible from outside the class where they are declared. . ( ), INTEREST_RATE , , 0.07. . , . , .

final . .

5. ta u sklopu JAVA deklaracija predstavlja null i kakva je uloga ove deklaracije?

null is the reserved constant used in Java to represent a void reference i.e a
pointer to nothing. When a variable is of object type (that is, declared with a class as its type rather than one of Java's primitive types), the value stored in the variable is not an object. Objects exist in a part of memory called the heap, and the variable holds a pointer or reference to the object. Null is a special value that can be stored in a variable to indicate that it does not actually point to any object. null , . ( , , ), . heap, . Null .

6. ta je konstruktor i kakva je njegova uloga u sklopu JAVA klase? A constructor is a special kind of subroutine in a class. It has the same name as the name of the class, and it has no return type, not evenvoid. A constructor is called with the new operator in order to create a new object. Its main purpose is to initialize the newly created object, but in fact, it can do anything that the programmer wants it to do. . , , void. new . . Posebna metoda (funkcija lanica) koja obezbeuje inicijalizaciju objekta klase naziva se KONSTRUKTOR (constructor). Implicitno se poziva pri kreiranju objekta klase.

Ima isto ime kao klasa, nema tip koji vraa, moe imati argumente i moe se preklapati.

7. ta osnovna uloga polimorfizma u objektnom programiranju? Polymorphism refers to the fact that different objects can respond to the same method in different ways, depending on the actual type of the object. This can occur because a method can be overridden in a subclass. In that case, objects belonging to the subclass will respond to the method differently from objects belonging to the superclass. (Note: If B is a subclass of A, then a variable of type A can refer to either an object of type A or an object of type B. Let's say that var is such a variable and that action() is a method in class A that is redefined in class B. Consider the statement "var.action()". Does this execute the method from class A or the method from class B? The answer is that there is no way to tell! The answer depends on what type of object var refers to, a class A object or a class B object. The method executed by var.action() depends on the actual type of the object that var refers to, not on the type of the variable var. This is the real meaning of polymorphism.) , . . , . Polimorfizam je mehanizam OO jezika koji omoguava izvravanje metodenaslednika (potomka child), mada se objektu pristupa kao da je u pitanju predak (parent). Pravilno iskorien, ovaj mehanizam prua mogunost ukljuivanja novih klasa u projekat, bez potrebe izmene postojeih klasa Funkcije (metode) lanice izvedene klase (child) koje imaju novu verziju u sklopu izvedene klase nazivaju se virtualnim funkcijama (metodama). Deklaracija virtual ispred deklaracije funkcije (metode). Polimorfizam omoguava ponovno korienje koda (code reusability).

8. JAVA programski jezik koristi "garbage collection" za rukovanje memorijom. ta je njegova uloga? 9. ta je alternativa za korienje "garbage collection" i koje posledice po JAVA programe ona moe
imati?

The purpose of garbage collection is to identify objects that can no longer be used, and to dispose of such objects and reclaim the memory space that they occupy. If garbage collection is not used, then the programmer must be responsible for keeping track of which objects are still in use and disposing of objects when they are no longer needed. If the programmer makes a mistake, then there is a "memory leak," which might gradually fill up memory with useless objects until the program crashes for lack of memory. "garbage collection" , . "garbage collection" , , . , " "("memory leak"), .

10. GUI programi moraju rukovati dogaajima. ta se podrazumeva pod dogaajima? Navedite bar dva
primera dogaaja u sklopu GUI programa.

An event is anything that can occur asynchronously, not under the control of the program, to which the program might want to respond. GUI programs are said to be "event-driven" because for the most part, such programs simply wait for events and respond to them when they occur. In many (but not all) cases, an event is the result of a user action, such as when the user clicks the mouse button, types a character, or clicks a button. The program might respond to a mouse-click on a canvas by drawing a shape, to a typed character by adding the character to an input box, or to a click on a button by clearing a drawing. More generally, a programmer can set up any desired response to an event by writing an event-handling routine for that event. , , . GUI "event-driven", , . ( ) , , , , ... , .

Dogaaj (Event) u Javi je obavetenje da se dogodilo neto zanimljivo (klik mia, selekcija, promena u komponenti, promena fokusa, pomeranje mia) Obrada dogaaja predstavlja reakciju na to obavetenje. Kada kreiramo korisniki interfejs nisu nam nam svi dogaaji interesantni, niti elimo da reagujemo na sve mogue dogaaje. Dakle, pri kreiranju GUI-a, odrediemo koji su nam dogaaji u radu sa komponentama od znaaja i prilikom obavetenje o tim dogaajima, izvriemo obradu tih dogaaja na nain na koji to nama odgovara.

11. JAVA poseduje standardnu klasu JPanel. Navedite dva razliita naina na koje se ona moe koristiti u
sklopu GUI aplikacija.

A JPanel is a type of component. That is, it is a visible element of a GUI. By itself, a JPanel is simply a blank rectangular region on the screen. However, a JPanel is a "container", which means that other components can be added to it and will then appear on the screen inside the JPanel. A JPanel can also be used as a drawing surface. In order to do this, it is necessary to create a subclass of JPanel and define a paintComponent()method in that subclass. An object belonging to that subclass can then be added to an applet or other component. The paintComponent() method defines how that object will draw itself on the screen. JPanel . GUI - . JPanel . , JPanel "container", JPanel - . JPanel .. , JPanel - paintComponent() . paintComponent() . 12. JAVA poseduje standardnu klasu MouseEvent. Koja je njena uloga? ta radi objekat klase
MouseEvent?

When an event occurs, the system packages information about the event into an object. That object is passed as a parameter to the event-handling routine. Different types of events are represented by different classes of objects. An object of type MouseEvent represents a mouse or mouse motion event. It contains information about the location of the mouse cursor and any modifier keys that the user is holding down. This information can be obtained by calling the instance methods of the object. For example, if evt is a MouseEvent object, then evt.getX() is the x-coordinate of the mouse cursor, and evt.isShiftDown() is a boolean value that tells you whether the user was holding down the Shift key.

, . . . MouseEvent .. . Dogaaji mia su dostupni svim podklasama klase Component. Postoje dva sluaa koji rade sa ovim dogaajem. To su MouseListener za osnovne dogaaje u vezi sa miom i MouseMotionListener za dogaaje koji se odnose na kretanje mia. Ova dva sluaa su razdvojena zbog performansi jer se dogaaji koji se odnose na pomeranje mia deavaju esto.

13. JAVA Swing poseduje JComponent klasu. ta se, u tom smislu, podrazumeva pod terminom
komponenta? Navedite bar tri primera SWING komponenti.

A JComponent represents a visual component of the computer's graphical user interface. A JComponent is not completely independent. It must be added to a "container," such as an applet or a frame. Examples of JComponents are JButtons, JTextFields, and JPanels.

Uopteno govorei komponenta predstavlja grafiki entitet odreene vrste koji se moe prikazati na ekranu (dugme, meni, toolbar...). U programskom jeziku Java, komponenta je objekat (instanca) bilo koje klase koja je potklasa (naslednik) klase Component. JComponent . JComponent . "", applet frame. : JButtons, JTextFields, JPanels.

14. Kakva je uloga LayoutManager-a u JAVI?

A LayoutManager implements some policy for laying out all the visual components that have been added to a container, such as a JPanel or the content pane of a JApplet. That is, it sets the sizes and positions of the components. Different types of layout managers have different rules about how components are to be arranged. Some standard layout manager classes are BorderLayout and GridLayout.

Upravljanje rasporedom komponenti je neophodno jer je princip u Javi da svaki program koji je u njoj razvijen podjednako dobro radi na svakoj platformi. Komponente same po sebi, ne izgledaju isto na svakoj platformi niti zauzimaju podjednak prostor na ekranu. Obrada ovih principa upravljanja rasporedom je posao menadera rasporeda (Layout Manager). Layout management je mehanizam koji nam omoguava definisanje pravila prostornog rasporeda vizuelnih komponenti. Ovim se omoguava pravilan prikaz komponenti pri promeni geometrije kontejnera kao i konzistentan prikaz na ureajima razliite rezolucije. LayoutManager , JPanel content pane JApplet - . , . LayoutManager- . layout manager BorderLayout GridLayout.

15. ta, po vaem miljenju, znai konstatacija da je program robustan?

A robust program is one that can handle errors and other unexpected conditions in some reasonable way. This means that the program must anticipate possible errors and respond to them if they occur. . , .

16. ta, u objektnom programiranju, pedstavljaju preduslovi (preconditions)? Navedite jedan primer preduslova.

A precondition is a condition that has to hold at given point in the execution of a program, if the execution of the program is to continue correctly. For example, the statement "x = A[i];" has two preconditions: that A is not null and that 0 <= i < A.length. If either of these preconditions is violated, then the execution of the statement will generate an error. Also, a precondition of a subroutine is a condition that has to be true when the subroutine is called in order for the subroutine to work correctly. . , "x = A[i];" : null 0 <= i < A.length.. , . , , .

17. JAVA poseduje predefinisanu klasu Throwable. ta ona predstavljat? Koja je njena uloga? The Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in acatch clause. Instances of two subclasses, Error and Exception, are conventionally used to indicate that exceptional situations have occurred. Typically, these instances are freshly created in the context of the exceptional situation so as to include relevant information (such as stack trace data). Throwable . ( ) Java Virtual Machine. , catch . , Error and Exception, .
18.Neke grupe izuzetaka (exceptions) zahtevaju obavezno rukovanje (mandatory exception handling). ta to znai? 19.Neke grupe izuzetaka (exceptions) zahtevaju obavezno rukovanje (mandatory exception handling). Koje su to klase u sklopu JAVA SWING biblioteke?

Subclasses of the class Exception which are not subclasses of RuntimeException require mandatory exception handling. This has two consequences: First, if a subroutine can throw such an exception, then it must declare this fact by adding a throws clause to the subroutine heading. Second, if a routine includes any code that can generate such an exception, then the routine must deal with the exception. It can do this by including the code in a try statement that has a catch clause to handle the exception. Or it can use a throws clause to declare that calling the subroutine might throw the exception. Exception RuntimeException . : , , throws clause. , , . , try catch block. throws clause metode . Ili samo: For those exception classes that require mandatory handling, the situation is different. If a routine can throw such an exception, that fact must be announced in a throws clause in the routine definition. Failing to do so is a syntax error that will be reported by the compiler. 20. Zbog ega metode treba da bace izuzetak u sluaju njegovog nastanka? Zato samo nebi
prekinuli dalje izvrenje programa?

Terminating the program is too drastic, and this tactic certainly doesn't lead to robust programs! It's likely that the subroutine doesn't know what to do with the error, but that doesn't mean that it should abort the whole program. When the subroutine throws an exception, the subroutine is terminated, but the program that called the subroutine still has a chance to catch the exception and handle it. In effect, the subroutine is saying "Alright, I'm giving up. Let's hope someone else can deal with the problem." , . , . , , .

You might also like