In Java, how does System.out.println() work?

‡ The thought process that one should use to arrive at an answer is purposely illustrated above. Without knowing the exact answer beforehand, you can arrive at an approximate one by applying some basic knowledge of Java. Most interviewers wouldn't expect you to know how System.out.println() works off the top of your head, but would rather see you use your basic Java knowledge to arrive at an answer that's close to exact. ‡ The more exact answer is this: inside the System class is the declaration of 'out' that looks like: 'public static final PrintStream out', and inside the Prinstream class is a declaration of 'println()' that has a method signature that looks like: 'public void println()'.

it is clear that the JVM is platform (operating system) dependent. and you will obviously pick whichever JVM is targeted for the operating system that you are running. it should be easier to deduce an answer to the question. and since the machine language depends on the operating system being will be given a list of JVM's corresponding to different operating systems. Since the JVM must translate the bytecode into machine language. This fact can be verified by trying to download the JVM .‡ Given the previous information. platform dependent? What is the advantage of using the JVM. and having Java be a translated language? .

overriding a method means that a method inherited from a base class is what's being changed. .between method overloading and method overriding? ‡ the differences between overloading and overriding. one must change either the type or the number of parameters for a method that belongs to the same class. When overloading. But.

public constructor if no programmer-defined constructor exists. Creating a private noargument constructor essentially prevents the usage of that default constructor. no-argument. . Note that the private constructor may even be empty. thereby preventing a caller from creating an instance of the class.What's the point of having a private constructor? ‡ Java always provides a default.

what's the difference between an object and a class? ‡ The term 'class' refers to the actual written piece of code in which the class is defined. or after the execution of a program. or a zebra). cat. ‡ we can say that whereas a class is a general concept (like an Animal). ‡ The term 'object' however refers to an actual instance of a class. . with a limited lifespan (like a lion. an object is a very specific embodiment of that class. during. The properties of a class do not change before. Every object must belong to a class.In Java.

It's also good to point out in an interview that the final modifier. when applied to an instance variable. class. ‡ And. turns off late binding. what does the 'final' modifier mean when applied to a method. and an instance variable? ‡ When applied to a method definition the final modifier indicates that the method may not be overridden in a derived class. when applied to either a class or a method. ‡ When applied to a class. the final modifier indicates that the class can not be used as a base class to derive any class from it. and thus prevents polymorphism.In Java. the final modifier simply means that the instance variable can't be changed. .

.io. Here's what a transient variable looks like: ‡ public class SomeClass implements java. which is an interface residing in the java. . } ‡ So.. if we were to write a serializable object to a any transient variable that was part of that object will not be saved to the file. it means that any object of that class can be converted into a sequence of bits so that it can be written to some storage medium (like a file). Then..In Java. .Serializable { // this variable will not persist private transient String package. what does it mean if a class is serializable? What is a transient variable? ‡ A class is serializable when it implements the Serializable interface. or even transmitted across a network. Here's what a serializable class looks like: ‡ public class SomeClass implements java. A transient variable is not a part of the persistent state of a serialized object. } ‡ Suppose that there's a particular object data member (like a password) that we may not want to get saved when an object is serialized.Serializable { // this class is serializable . If a class is serializable. what we can do is declare that data member to be "transient".

Sign up to vote on this title
UsefulNot useful