Professional Documents
Culture Documents
OISISI - Java Odgovori
OISISI - Java Odgovori
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
.
.
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
.
Ima isto ime kao klasa, nema tip koji vraa, moe imati argumente i moe se
preklapati.
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", ,
. ( ) ,
, , , ...
,
.
11. JAVA poseduje standardnu klasu JPanel. Navedite dva razliita naina na koje se ona moe koristiti u
sklopu GUI aplikacija.
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 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.
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.
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."
,
.
,
. , ,
.