• Verkeerd document? Gratis ruilen
  • Geschreven door studenten die geslaagd zijn
  • Direct beschikbaar na je betaling
  • Online lezen of als PDF
Verkopen
Kies je studieland
Kies je taal
Document preview thumbnail
Voorbeeld 4 van de 41 pagina's
Tentamen (uitwerkingen)

Java UPDATED ACTUAL Exam Questions and CORRECT Answers

Document preview thumbnail
Voorbeeld 4 van de 41 pagina's

Java UPDATED ACTUAL Exam Questions and CORRECT Answers If you overwrite clone(), which 3 rules must this method obey? - CORRECT ANSWER 1) the new object should be new: memory address should differ 2) Both should be an object of the same class 3) Both should be in the same state: ().equals(a) == true Why do we need to implement the Clonable interface? - CORRECT ANSWER - At runtime it would throw the CloneNotSupportedException if we don't implement the Cloneable interface. A class implements the Cloneable interface to indicate to the O() method that it is legal for that method to make a field-for-field copy of instances of that clas

Voorbeeld van de inhoud

Java UPDATED ACTUAL Exam Questions
and CORRECT Answers
If you overwrite clone(), which 3 rules must this method obey? - CORRECT ANSWER -
1) the new object should be new: memory address should differ
2) Both should be an object of the same class
3) Both should be in the same state:
a.clone().equals(a) == true


Why do we need to implement the Clonable interface? - CORRECT ANSWER - At
runtime it would throw the CloneNotSupportedException if we don't implement the Cloneable
interface. A class implements the Cloneable interface to indicate to the Object.clone() method
that it is legal for that method to make a field-for-field copy of instances of that class.


What is a marker interface? - CORRECT ANSWER - A Marker interface, has no method.
Serializable, Clonable are marker interfaces.


How do you clone an object? - CORRECT ANSWER - MyClone a = (MyClone) c.clone()
- TypeCast is nessesary.
- handle CloneNotSupportedException


Why can Annotations replace marker interfaces? - CORRECT ANSWER - Annotations
can convey metadata about the class to its consumers without creating a separate type for it.
Annotations let you pass information to classes that "consume" it.


What is Double-Checked Locking? - CORRECT ANSWER - To reduce the overhead of
acquiring a lock by first testing the locking criterion without actually acquiring the lock.


How do you make an object serializable? - CORRECT ANSWER - The class must
implement the java.io.Serializable interface

,Java object serialization is performed using which classes? - CORRECT ANSWER - Java
object serialization (writing) is done with the ObjectOutputStream and deserialization (reading)
is done with the ObjectInputStream.


What is serialVersionUID? - CORRECT ANSWER - In addition to implementing the
Serializable interface, a class intended for serialization should also contain a private static final
long variable named serialVersionUID.
The serialVersionUID variable is used by Java's object serialization API to determine if a
deserialized object was serialized (written) with the same version of the class, as it is now
attempting to deserialize it into.
If you make changes to the class that affect serialization, you should also change its
serialVersionUID value.


What is escape analysis? - CORRECT ANSWER - escape analysis is a method for
determining the dynamic scope of pointers - where in the program a pointer can be accessed.


What is the size of byte? - CORRECT ANSWER - 8 bits



What is the size of char? - CORRECT ANSWER - 16 bits



What is the size of short? - CORRECT ANSWER - 16 bits



What is the size of int? - CORRECT ANSWER - 32 bits



what is the size of long? - CORRECT ANSWER - 64 bits



what is the size of float? - CORRECT ANSWER - 32 bits



what is the size of double? - CORRECT ANSWER - 64 bits

,What is the range of byte - CORRECT ANSWER - -128 to 127



What is the range of short? - CORRECT ANSWER - -32,768 to 32,767



What is the range of int? - CORRECT ANSWER - -2,1 billion to 2,1billion



How do you check if a number is even? - CORRECT ANSWER - check if number AND 1
is 0


How do you test if the n-th bit is set? - CORRECT ANSWER - Shift n times to the right
and then AND


How can you set the n-th bit - CORRECT ANSWER - Shift n times to the left and OR



How can you unset the nth bit - CORRECT ANSWER - Shift n times to the left and invert,
then AND


How can you toggle the nth Bit? - CORRECT ANSWER - Shift n times to the left and
XOR


How can you turn off the rightmost 1Bit? - CORRECT ANSWER - AND with (number -
1)


How can you return only 1 or 0 for the rightmost 1Bit value? - CORRECT ANSWER -
number & ( - number)


How can you also declare -x bitwise? - CORRECT ANSWER - ~x + 1

, What is ~0 bitwise? - CORRECT ANSWER -0



How can you right propagate the rightmost 1-bit? - CORRECT ANSWER - number OR
(number - 1), does not work for 0


What is -1 in twos complement? - CORRECT ANSWER - 1111 1111



How can you isolate the rightmost 0-bit? - CORRECT ANSWER - invert number AND
(number + 1)


How can you turn on the rightmost 0-bit. - CORRECT ANSWER - number OR (number +
1)


what algorithm is Arrays.sort? - CORRECT ANSWER - An improved quicksort with
average nlog(n) runtime


how can you sort a range of an array in-place? - CORRECT ANSWER - Arrays.sort(int[]
a, int fromIndex, int toIndex)
works with all primitive types and comparables


How can you sort an array using parallel tasks - CORRECT ANSWER -
Arrays.parallelSort usesmergesort and ForkJoin common pool to execute any parallel tasks.
works with all primitive types and comparables


How is the comparable interface implemented? - CORRECT ANSWER - public interface
Comparable<T>{
int compareTo(T o) {
return 1; //if this > that
return 0; //if this == that
return -1; //if this < that

Documentinformatie

Geüpload op
17 april 2025
Aantal pagina's
41
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden
$13.99

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
STANFORDGRADESS
4.0
(242)
Verkocht
1706
Volgers
109
Items
123758
Laatst verkocht
1 uur geleden




Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen