Skip to main content

Posts

Showing posts from June, 2015
Machine language is OS dependent Given the previous information, it should be easier to figure out an answer to the original question. Since the JVM must translate the bytecode into machine language, and since the machine language depends on the operating system being used, it is clear that the JVM is platform (operating system) dependent  – in other words, the JVM is  not  platform independent. The JVM is not platform independent The key here is that the JVM depends on the operating system – so if you are running Mac OS X you will have a different JVM than if you are running Windows or some other operating system. This fact can be verified by trying to download the JVM for your particular machine – when trying to download it, you will be given a list of JVM’s corresponding to different operating systems, and you will obviously pick whichever JVM is targeted for the operating system that you are running. JVM translates bytecode into machine language Every...
What are some of the differences between using recursion to solve a problem versus using iteration? Which one is faster? Which one uses more memory? The fact is that recursion is rarely the most efficient approach to solving a problem, and iteration is almost always more efficient. This is because there is usually more overhead associated with making recursive calls due to the fact that the call stack is so heavily used during recursion (for a refresher on this, read here:  Recursion tutorial ). This means that many computer programming languages will spend more time maintaining the call stack then they will actually performing the necessary calculations. Does recursion use more memory than iteration? Generally speaking, yes it does. This is because of the extensive use of the call stack. Should I use recursion or iteration? Recursion is generally used because of the fact that it is simpler to implement, and it is usually more ‘elegant’ than iterative solutions...
Can every recursive function be converted into an iterative function? Yes, any problem that can be solved recursively can also be solved through the use of iteration. In case you don’t know,  iteration  is the use of a looping construct like a while loop, for loop, etc in order to solve a problem, whereas recursion is the use of a function that calls itself to solve a problem. The reason that iteration can be used to solve any problem that recursion solves is because recursion uses the call stack behind the scenes, but a call stack can also be implemented explicitly (in code) and iteratively (through a for loop, while loop, or any kind of loop). So, whatever recursion gives us behind the scenes can be also be done by implementing a call stack directly in the code itself. http://www.programmerinterview.com/index.php
How to create a immutable object in Java? Does all property of immutable object needs to be final? To create a object immutable You need to make the class final and all its member final so that once objects gets crated no one can modify its state. You can achieve same functionality by making member as non final but private and not modifying them except in constructor. Also its NOT necessary to have all the properties final since you can achieve same functionality by making member as non final but private and not modifying them except in constructor. What is difference between String, StringBuffer and StringBuilder? When to use them? The main difference between the three most commonly used String classes as follows. StringBuffer and StringBuilder objects are mutable whereas String class objects are immutable. StringBuffer class implementation is synchronized while StringBuilder class is not synchronized. Concatenation operator "+" is internally implemented by Jav...
What is the difference between Abstract Class and Interface? Abstract classes usually represent an abstract concept or an entity with partial or no implementation. On the other hand, an interface is an abstract type that is used to specify a contract that should be implemented by classes. Abstract classes should be inherited (or extended), while interfaces should be implemented. Abstract classes may contain abstract methods, whereas an interface should only contain abstract methods. Abstract classes can contain any variables, but Interfaces can only define constants. A class cannot inherit from more than one abstract class but can implement multiple interfaces. An Interface cannot implement another interface. However an interface can extend a class. // I say all motor vehicles should look like this: interface MotorVehicle { void run (); int getFuel (); } // my team mate complies and writes vehicle looking that way class Car implements MotorVehicle { i...