ELK Education Consultants Fresher Interview Questions with Answers – Part 1
This blog explains about ELK Education Consultants Fresher Interview Questions with Answers – Part 1 and is given below :
1. Why Java is platform independent?
The meaning of platform independent is that, the java source code can run on all operating systems.
A program is written in a language which is a human readable language. It may contain words, phrases etc which the machine does not understand.
The compiler converts the high-level language (human language) into a format understood by the machines. Therefore, a compiler is a program that translates the source code for another program from a programming language into executable code.
Step by step Execution of Java Program:
- Whenever, a program is written in JAVA, the javac compiles it.
- The result of the JAVA compiler is the .class file or the bytecodeand not the machine native code (unlike C compiler).
- The bytecode generated is a non-executable code and needs an interpreter to execute on a machine. This interpreter is the JVM and thus the Bytecode is executed by the JVM.
- And finally program runs to give the desired output.
- In the case of Java, it is the magic of Bytecode that makes it platform independent.
- This adds to an important feature in the JAVA language termed as portability. Every system has its own JVM which gets installed automatically when the jdk software is installed. For every operating system separate JVM is available which is capable to read the .class file or byte code.
- An important point to be noted is that while JAVA is platform-independent language, the JVM is platform-dependent.Different JVM is designed for different OS and byte code is able to run on different OS.
2. Write the difference between String and StringBuffer
There are many differences between String and StringBuffer. A list of differences between String and StringBuffer are given below:
|1)||String class is immutable.||StringBuffer class is mutable.|
|2)||String is slow and consumes more memory when you concat too many strings because every time it creates new instance.||StringBuffer is fast and consumes less memory when you cancat strings.|
|3)||String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.||StringBuffer class doesn’t override the equals() method of Object class.|
|BASIS FOR COMPARISON||STRING||STRINGBUFFER|
|Basic||The length of the String object is fixed.||The length of the StringBuffer can be increased.|
|Modification||String object is immutable.||StringBuffer object is mutable.|
|Performance||It is slower during concatenation.||It is faster during concatenation.|
|Memory||Consumes more memory.||Consumes less memory.|
|Storage||String constant pool.||Heap Memory.|
3. Write the difference between throw and throws in exception handling
There are many differences between throw and throws keywords. A list of differences between throw and throws are given below:
|1)||Java throw keyword is used to explicitly throw an exception.||Java throws keyword is used to declare an exception.|
|2)||Checked exception cannot be propagated using throw only.||Checked exception can be propagated with throws.|
|3)||Throw is followed by an instance.||Throws is followed by class.|
|4)||Throw is used within the method.||Throws is used with the method signature.|
|You cannot throw multiple exceptions.||You can declare multiple exceptions e.g.
public void method()throws IOException,SQLException.
|6) throw keyword is used to throw an exception explicitly.||throws keyword is used to declare one or more exceptions, separated by commas.|
|7) Only single exception is thrown by using throw.||Multiple exceptions can be thrown by using throws.|
|8) throw keyword is used within the method.||throws keyword is used with the method signature.|
|9) Syntax wise throw keyword is followed by the instance variable.||Syntax wise throws keyword is followed by exception class names.|
|10) Checked exception cannot be propagated using throw only.Unchecked exception can be propagated using throw.||For the propagation checked exception must use throws keyword followed by specific exception class name.|
4. What is Machine Learning Algorithms
We will describe 8 algorithms used in Machine Learning. The objective here is not to go into the details of the models but rather to give the reader elements of understanding on each of them.
- “The Decision Tree”
- “Random Forests”
- The “Gradient Boosting” / “XG Boost”
- “Genetic Algorithms”
- “Support Vector Machines”
- The “K nearest neighbors”
- “Logistic Regression”
5. Why multiple inheritance not supported in Java ?
Multiple inheritance is where we inherit the properties and behavior of multiple classes to a single class. C++, Common Lisp, are some popular languages that support multiple inheritance.
JAVA: A simple, object oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high performance, multithreaded, dynamic language.
In order to enforce simplicity should be the main reason for omitting multiple inheritance. For instance, we can consider diamond problem of multiple inheritance.
We have two classes B and C inheriting from A. Assume that B and C are overriding an inherited method and they provide their own implementation. Now D inherits from both B and C doing multiple inheritance. D should inherit that overridden method, where we have an ambiguity.
In C++ there is a possibility to get into this trap though it provides alternates to solve this. In java this can never occur as there is no multiple inheritance. Here even if two interfaces are going to have same method, the implementing class will have only one method and that too will be done by the implementer. Dynamic loading of classes makes the implementation of multiple inheritance difficult.