• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 3 fuera de 28 páginas
Examen

Java Exam With 100% Correct Answers

Document preview thumbnail
Vista previa 3 fuera de 28 páginas

JAVA EXAM WITH 100% CORRECT ANSWERS

Vista previa del contenido

JAVA EXAM WITH 100% CORRECT
ANSWERS

What does thread safe mean? - Answer-Code that is safe to call by multiple threads
simultaneously

When multithreading, local primitive variables are stored . - Answer-In each thread's
own stack. That means that local variables are never shared between threads. That
also means that all local primitive variables are thread safe.

Can you think of a guarantee to know if a given object is thread safe? - Answer-If an
object created locally never escapes the method it was created in, it is thread safe.

Are object member variables thread safe? - Answer-No, object member variables
(fields) are stored on the heap along with the object. Therefore, if two threads call a
method on the same object instance and this method updates object member variables,
the method is not thread safe.

Are you holding a lock when you access a volatile variable? - Answer-access to a
volatile variable never has the potential to block: we're only ever doing a simple read or
write, so unlike a synchronized block we will never hold on to any lock;

Are you holding a lock when you access a synchronized method? - Answer-access to a
volatile variable never has the potential to block: we're only ever doing a simple read or
write, so unlike a synchronized block we will never hold on to any lock;

In which situation would you not use volatile? - Answer-When we want to read-update-
write as an atomic operation (unless we're prepared to "miss an update"); Accessing a
volatile variable never holds a lock.

What is the most common mistake when starting a thread? - Answer-To call the run()
method of the Thread instead of start(). in that case, the run() method is executed by
the thread that created the thread.

What is a critical section? - Answer-A section of code that is executed by multiple
threads and where the sequence of execution for the threads makes a difference in the
result

,What is a race condition? - Answer-When the result of multiple threads executing a
critical section may differ depending on the sequence in which the threads execute.

How can you prevent race conditions? - Answer-Make sure that the critical section is
executed as an atomic instruction. So that when a thread is executing it, no other can
execute it until the first thread has left the critical section.

How can you avoid race conditions? - Answer-By proper thread synchronization in
critical sections.


If you overwrite clone(), which 3 rules must this method obey? - 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? - 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? - Answer-A Marker interface, has no method.
Serializable, Clonable are marker interfaces.

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

Why can Annotations replace marker interfaces? - 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? - 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? - Answer-The class must implement the
java.io.Serializable interface

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

What is serialVersionUID? - 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? - 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? - Answer-8 bits

What is the size of char? - Answer-16 bits

What is the size of short? - Answer-16 bits

What is the size of int? - Answer-32 bits

what is the size of long? - Answer-64 bits

what is the size of float? - Answer-32 bits

what is the size of double? - Answer-64 bits

What is the range of byte - Answer--128 to 127

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

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

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

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

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

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

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

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

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

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

Información del documento

Subido en
12 de julio de 2025
Número de páginas
28
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$13.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
Scholarsstudyguide
3.8
(169)
Vendido
853
Seguidores
476
Artículos
16409
Última venta
1 semana hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes