JAVA FAQ's

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

FREQUENTLY ASKED QUESTIONS IN JAVA

1.What is a transient variable? A transient variable is a variable that may not be serialized. 2. Which containers use a border Layout as their default layout?
The window, Frame and Dialog classes use a border layout as their default layout. .

3. Why do threads block on I/O?


i/o #$eration is $erformed..

Threads block on i/o that is enters the waiting state! so that other threads may e"ecute while the

4. How are Observer and Observable used?


#b%ects that subclass the #bservable class maintain a list of observers. &hen an #bservable ob%ect is u$dated it invokes the u$date ! method of each of its observers to notify the observers that it has changed state. #b%ects that observe #bservable ob%ects im$lement the #bserver interface '. What is synchronization and why is it important? &ith res$ect to multithreading, synchronization is the ca$ability to control the access of multi$le threads to shared resources. &ithout synchronization, it is $ossible for one thread to modify a shared ob%ect while another thread is in the $rocess of using or u$dating that ob%ect(s value. This often leads to significant errors ). Can a lock be ac uired on a class? *es, a lock can be ac+uired on a class. This lock is ac+uired on the class(s ,lass ob%ect.. .

7. What!s new with the stop "#$ suspend "# and resume "# methods in %&' ()*? 8. Is null a keyword?
The null value is not a keyword

The sto$ !, sus$end ! and resume ! methods have been de$recated in -D. /.2.

0. What is the preferred size of a component? The $referred size of a com$onent is the minimum com$onent size that will allow the com$onent to dis$lay normally /1. What method is used to specify a container!s layout? The set 2ayout ! method is used to s$ecify a container(s layout. .

11. Which containers use a +low Layout as their default layout?

The 3anel and A$$let classes use the Flow 2ayout as their default layout /2. What state does a thread enter when it terminates its processin,? &hen a thread terminates its $rocessing, it enters the dead state. .

13. What is the Collections -.I?

The ,ollections A34 is a set of classes and interfaces that su$$ort o$erations on collections of ob%ects

/5. Which characters may be used as the second character of an identifier$ but not as the first character of an identifier? The digits 1 through 0 may not be used as the first character of an identifier but they may be used after the first character of an identifier /'. What is the List interface? The 2ist interface $rovides su$$ort for ordered collections of ob%ects /). How does %ava handle inte,er overflows and underflows? 4t uses those low order bytes of the result that can fit into the size of the ty$e allowed by the o$eration /6. What is the /ector class? The 7ector class $rovides the ca$ability to im$lement a growable array of ob%ects /8. What modifiers may be used with an inner class that is a member of an outer class? A non9local! inner class may be declared as $ublic, $rotected, $rivate, static, final, or abstract. .

19. What is an Iterator interface?


The 4terator interface is used to ste$ through the elements of a ,ollection. .

20. What is the difference between the 00 and 000 operators?


shifted out..

The :: o$erator carries the sign bit when shifting right. The ::: zero9fills bits that have been

21. Which method of the Component class is used to set the position and size of a component? ;et <ounds !. 22. How many bits are used to represent 1nicode$ -2CII$ 13+4(5$ and 13+46 characters?
=nicode re+uires /) bits and A;,44 re+uire 6 bits. Although the A;,44 character set uses only 6 bits, it is usually re$resented as 8 bits. =TF98 re$resents characters using 8, /), and /8 bit $atterns. =TF9/) uses /)9bit and larger bit $atterns..

23. What is the difference between yieldin, and sleepin,?


&hen a task invokes its yield ! method, it returns to the ready state. &hen a task invokes its slee$ ! method, it returns to the waiting state..

24. Which 7ava)util classes and interfaces support event handlin,?


The >vent #b%ect class and the >vent 2istener interface su$$ort event $rocessing. .

25. Is size of a keyword?


The size of o$erator is not a keyword..

26. What are wrapped classes?


&ra$$ed classes are classes that allow $rimitive ty$es to be accessed as ob%ects. .

27. &oes ,arba,e collection ,uarantee that a pro,ram will not run out of memory?
$rograms to create ob%ects that are not sub%ect to garbage collection .

?arbage collection does not guarantee that a $rogram will not run out of memory. 4t is $ossible for $rograms to use u$ memory resources faster than they are garbage collected. 4t is also $ossible for

28. What restrictions are placed on the location of a packa,e statement within a source code file?
A $ackage statement must a$$ear as the first line in a source code file e"cluding blank lines and comments!.

29. Can an ob7ect!s finalize "# method be invoked while it is reachable?


An ob%ect(s finalize ! method cannot be invoked by the garbage collector while the ob%ect is still reachable. @owever, an ob%ect(s finalize ! method may be invoked by other ob%ects.

30. What is the immediate super class of the -pplet class? 3anel. 31. What is the difference between preemptive schedulin, and time slicin,?
=nder $reem$tive scheduling, the highest $riority task e"ecutes until it enters the waiting or dead states or a higher $riority task comes into e"istence. =nder time slicing, a task e"ecutes for a $redefined slice of time and then reenters the $ool of ready tasks. The scheduler then determines which task should e"ecute ne"t, based on $riority and other factors. .

32. 8ame three Component subclasses that support paintin,)


The ,anvas, Frame, 3anel, and A$$let classes su$$ort $ainting. .

33. What value does readLine "# return when it has reached the end of a file?
The read2ine ! method returns null when it has reached the end of a file. .

34. What is the immediate super class of the &ialo, class? &indow. 35. What is clippin,?
,li$$ing is the $rocess of confining $aint o$erations to a limited area or sha$e. .

36. What is a native method?


A native method is a method that is im$lemented in a language other than -ava. .

37. Can a for statement loop indefinitely?

*es, a for statement can loo$ indefinitely. For e"am$le, consider the followingA for BB!.

38. What is order of precedence and associatively$ and how are they used?

#rder of $recedence determines the order in which o$erators are evaluated in e"$ressions. Associatity determines whether an e"$ression is evaluated left9to9right or right9to9left .

39. When a thread blocks on I/O$ what state does it enter?


A thread enters the waiting state when it blocks on 4/#.

40. 3o what value is a variable of the 2trin, type automatically initialized?


The default value of an ;tring ty$e is null.

41. 3o what value is a variable of the 2trin, type automatically initialized?


The default value of an ;tring ty$e is null.

42. What is the catch or declare rule for method declarations?

4f a checked e"ce$tion may be thrown within the body of a method, the method must either catch the e"ce$tion or declare it in its throws clause..

43. What is the difference between a 9enuItem and a Checkbo:9enuItem?


checked or unchecked..

The ,heckbo"Cenu4tem class e"tends the Cenu4tem class to su$$ort a menu item that may be

44. What is a task!s priority and how is it used in schedulin,?


A task(s $riority is an integer value that identifies the relative order in which it should be e"ecuted with res$ect to other tasks. The scheduler attem$ts to schedule higher $riority tasks before lower $riority tasks..

45. What class is the top of the -W3 event hierarchy?


The %ava.awt.A&T>vent class is the highest9level class in the A&T event9class hierarchy. .

46. When a thread is created and started$ what is its initial state?
A thread is in the ready state after it has been created and started. .

47. Can an anonymous class be declared as implementin, an interface and e:tendin, a class?
An anonymous class may im$lement an interface or e"tend a su$erclass, but may not be declared to do both..

48. What is the ran,e of the short type?


The range of the short ty$e is 9 2D/'! to 2D/' 9 /..

49What is the ran,e of the char type?


The range of the char ty$e is 1 to 2D/) 9 /..

50. In which packa,e are most of the -W3 events that support the event4dele,ation model defined?
$ackage. The A&T>vent class is defined in the %ava.awt $ackage. .

Cost of the A&T9related events of the event9delegation model are defined in the %ava.awt.event

51. What is the immediate superclass of 9enu? Cenu4tem.

You might also like