1.What is JVM and is it platform independent?
Java Virtual Machine (JVM) is the heart of java programming language. JVM is responsible for converting byte code into machine readable code. JVM is not platform independent, thats why you have different JVM for different operating systems. We can customize JVM with Java Options, such as allocating minimum and maximum memory to JVM. It’s called virtual because it provides an interface that doesn’t depend on the underlying OS.
2.How to reverse a string in java?
Write a java program to reverse a given string using recursive method.
3.What is the difference between JDK and JVM?
Java Development Kit (JDK) is for development purpose and JVM is a part of it to execute the java programs.JDK provides all the tools, executables and binaries required to compile, debug and execute a Java Program. The execution part is handled by JVM to provide machine independence.
4.How to create a pyramid of numbers in java?
Write a java program to create a pyramid of numbers in different patterns.
5.What is the difference between JVM and JRE?
Java Runtime Environment (JRE) is the implementation of JVM. JRE consists of JVM and java binaries and other classes to execute any program successfully. JRE doesn’t contain any development tools like java compiler, debugger etc. If you want to execute any java program, you should have JRE installed.
6.How do you remove all white spaces from a string in java?
Write a java program to remove all white spaces from a given string.
7.Which class is the superclass of all classes?
java.lang.Object is the root class for all the java classes and we don’t need to extend it.
8.How to find duplicate characters in a string in java?
Write a java program to find duplicate characters and their count in a given string. For example, in a string “Better Butter”, duplicate characters and their count is t : 4, e : 3, r : 2 and B : 2.
9.Why Java doesn’t support multiple inheritances?
Java doesn’t support multiple inheritance in classes because of “Diamond Problem”. To know more about diamond problem with example, read Multiple Inheritance in Java.However multiple inheritance is supported in interfaces. An interface can extend multiple interfaces because they just declare the methods and implementation will be present in the implementing class. So there is no issue of diamond problem with interfaces.
10.How do you check the equality of two arrays in java?
Write a java program to check the equality of two arrays using different methods.
11.Why Java is not pure Object Oriented language?
Java is not said to be pure object oriented because it support primitive types such as int, byte, short, long etc. I believe it brings simplicity to the language while writing our code. Obviously java could have wrapper objects for the primitive types but just for the representation, they would not have provided any benefit.As we know, for all the primitive types we have wrapper classes such as Integer, Long etc that provides some additional methods.
12. Anagram program in java
Write a java program to check whether two given strings are anagram or not. Two strings are said to be anagram if they contain same set of characters but in different order. For example, “Mother In Law” and “Hitler Woman” are anagram
13.What is difference between path and class path variables?
PATH is an environment variable used by operating system to locate the executables. That’s why when we install Java or want any executable to be found by OS, we need to add the directory location in the PATH variable. If you work on Windows OS, read this post to learn how to setup PATH variable on Windows.Classpath is specific to java and used by java executables to locate class files. We can provide the classpath location while running java application and it can be a directory, ZIP files, JAR files etc.
14. Armstrong number program in java
Write a java program to check whether a given number is Armstrong number or not. A number is called an Armstrong number if it is equal to sum of its digits each raised to the power of number of digits in it. For example: 153, 9474, 54748 are some Armstrong numbers.
15.What is the importance of main method in Java?
main() method is the entry point of any standalone java application. The syntax of main method is public static void main(String args).main method is public and static so that java can access it without initializing the class. The input parameter is an array of String through which we can pass runtime arguments to the java program. Check this post to learn how to compile and run java program.
16.How to find duplicate elements in an array?
Write a java program to find duplicate elements in the given array.
17.What is overloading and overriding in java?
When we have more than one method with same name in a single class but the arguments are different, then it is called as method overloading.Overriding concept comes in picture with inheritance when we have two methods with same signature, one in parent class and another in child class. We can use @Override annotation in the child class overridden method to make sure if parent class method is changed, so as child class.
18.How to find sum of all digits of a number in java?
Write a java program to find sum of all digits of a given number.
19.How to find second largest number in an integer array?
Write a java program to find second largest number in an array of numbers.
20.How to perform matrix operations in java?
Write a java program to perform matrix operations like matrix addition, matrix subtraction, matrix multiplication and transpose of a matrix.