miércoles, 29 de marzo de 2017

Types of Questions #2

Java Question 1

How does the same Java code run on multiple operating systems?

JVM or Java virtual machine. And how that Java programs run inside of this JVM. It is also important to mention here that when you compile Java code, you're actually compiling the code to bytecode. Since that bytecode is interpreted by the JVM. And the JVM has implementations from many different operating systems. That code can be run anywhere the JVM can run.

Java Question 2

What does the final keyword do?

The simple answer is that final makes a class unable to be subclass. It makes a method unable to be overwritten, and a variable, assignable only once. The better answer is one that further clarifies. That final variable values are not known at compile time, and that this differs from constant. It is also a good idea to talk about how final does not mean a variable is completely immutable. That if a final modifier is put in front of the reference type, the object the variable refers to cannot change, but the properties of that object itself can.

Java Question 3

What is the difference between an interface and an abstract class?

The biggest difference is that an abstract base class can have instance methods, which allows you to have a default behavior, while an interface can declare constants in interface methods, but it can provide an implementation for those methods. It is also good to talk about how an abstract class being a regular class, can have private and protected members as well. There are many different answers to this question. But one really good reason to point out is that, if you need a default implementation, and an abstract class makes it easy to define one, this is definitely a question you should be prepared to answer though. 

No hay comentarios:

Publicar un comentario