Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

In which format Data store Happen in API Baas and why?

Answer»

In which format Data STORE Happen in API BAAS and why?
Here data is stored in the form of JSON formatted OBJECTS. With the help of this it is very easy for the USER and he can store EVERY different type of data easily in the API Baas.

2.

Write code to reverse a string in Java?

Answer»

Write code to reverse a string in Java?
Below is the code to reverse string in Java below code will helps you on that:-

public class StringReverseClass
{
public static void main(String ARGS[])
{
String STR = "Crackyourinterview";
String reverse = new STRINGBUFFER(str).reverse().toString();
System.out.printf("Word Enter: %s, Word after Reverse %s", str, reverse);
}

public static String reverse(String source)
{
if (source == null || source.isEmpty())
{
return source;
}
String reverse = "";
for (int i = source.length() - 1; i >= 0; i--)
{
reverse = reverse + source.charAt(i);
}
return reverse;
}
}

OUTPUT:-
Word Enter: Crackyourinterview, Word after Reverse weivretniruoykcarC

3.

What is Java LinkedList and its features

Answer»

What is Java LinkedList and its features
Java LinkedList is linear Java data structures and all the elements are stored in non-contiguous memory LOCATIONS. And doubly linked list is used in Java LinkedList. Below are the 9 MAIN features of Java LinkedList
(1)It inherits the AbstractList class and implements List and Deque interfaces.
(2)It can CONTAIN duplicate elements.
(3)It can maintain insertion order.
(4)It is non-synchronized
(5)MANIPULATION is fast in this because no SHIFTING needs to occur
(6)It can be used as a list, stack or queue.
(7)The elements are linked using pointers and addresses.
(8)Each element is known as a node.
(9)It is part of java.util

4.

what is OOAD

Answer»

OOAD is a Software Engineering approach that models a system as a group of interacting objects and its object REPRESENTS some entity or attribute in this system and its object defined by its class, its state, and its behavior.In other defination we can say that OOAD is a methodology which helps to analyze,design and develop application using objects and their relations and message based communication to each other.In OOAD everything rotates on objects and classes. OOAD INTRODUCED a PARADIGM shift from thinking and programming procedurally to objects oriented programming.This approach helps in designing complex real time systems.Some of its features like DATA Abstraction and Encapsulation, INHERITANCE and Polymorphism form are basic fundamentals of object oriented programming.

5.

Deine covariant return type in core java?

Answer»

Deine covariant return type in core JAVA?
From java5 now we can override any method by changing return type and if the return type of subclass overriding method is subclass type. And this is known as covariant return type. And covariant return type also SPECIFIES that the return type may vary in the same direction as the subclass. Below example will be more clear the covariant return type:-

class baseclass
{
baseclass get()
{
return this;
}
}

class subclass EXTENDS baseclass
{
subclass get()
{
return this;
}
void MESSAGE()
{
System.out.println("welcome to covariant return type");
}

public static void main(String args[])
{
NEW baseclass().get().message();
}
}

6.

Different Memory Allocations available in Java?

Answer» DIFFERENT MEMORY Allocations available in Java?
Below are the five significant types of memory allocations in Java.
(1)CLASS Memory
(2)Heap Memory
(3)Stack Memory
(4)Program Counter-Memory
(5)NATIVE METHOD Stack Memory
7.

Difference between JDK and JRE?

Answer»

Difference between JDK and JRE?
Below are five main differences between JDK and JRE:-
(1)JDK:-FULL form for JDK is Java Development Kit.
(1)JRE:-Full form for JRE is Java Runtime Environment.

(2)JDK:-JDK is Platform Dependent unlike JVM.
(2)JRE:-JRE is also Platform Dependent unline JVM.

(3)JDK:-JDK is Kit that is dedicated for Software development.
(3)JRE:-And on other hand JRE is set of software and library designed for Execute java PROGRAM.

(4)JDK:-And JDK package is a set of tools which is mainly used for debugging and developing.
(4)JRE:-And JRE package is one that only supports FILES and libraries for a runtime environment.

(5)JDK:-JDK package will be provided with and installer file.
(5)JRE:-JRE package does not get an installer but has only a runtime environment.

8.

String handling and find the output of Java program?

Answer»

String HANDLING and find the output of Java program?
Below is the syntax for handling string in java program by USING addition of string with numeric values.
class Teststring
{
public STATIC void MAIN (String args[])
{
System.out.println(40 + 30 + "crackyourinterview");
System.out.println("crackyourinterview" + 40 + 30);
}
}


And Output of above program is given below
70crackyourinterview
crackyourinterview4030

9.

Is it possible to declare a constructor as final in corejava?

Answer»

Is it possible to declare a CONSTRUCTOR as final in corejava?
Below are the some points which will help you to understand about above question
(1)We cannot declare constructor as final because we cannot inherit this.
(2)And ANOTHER point is that Constructors are not a ORDINARY methods so no sense to declare constructors as final.
(3)And if we declare constructors as Final and we get COMPILER ERROR.

10.

Define the System Class in Java?

Answer»

Define the System Class in Java?
System Class is the ore class in Java. And we are not able to override its behavior throgh inheritance. And we cannot instantiate this class as it doesnot have any public constructors. Hence all of its methods are static here in System Class. System Class of Java contains several useful class fields and methods. And this will provides MANY facilities like standard input,standard output and the error output streams. Java System class comes in different MODULES of JAVA.BASE and in package of JAVA.LANG. And in Java System class we have 3 different types of field and 28 different types of methods. Below are the list of 3 fields:-
(1)static PrintStrean
(2)static InputStream
(3)static PrintStream
And below are the 28 methods:-
(1)arraycopy(object src, int srcPos, object dest, int destPos, int length)
(2)clearProperty(STRING key)
(3)console()
(4)currentTimeMillis()
(5)exit(int status)
(6)gc()
(7)getenv()
(8)getLogger(String name, RecourseBundle)
(9)getLogger(String name)
(10)getenv(String name)
(11)getProperties()
(12)getProperty(String key)
(13)getProperty(String key,String def)
(14)getSecurityManager()
(15)identityHashCode(Object x)
(16)inheritedChannel() throws IOException
(17)lineSeparator()
(18)load(String filename)
(19)mapLibraryName(String libname)
(20)nanoTime()
(21)runFinalizersOnExit(BOOLEAN value)
(22)runFinalization()
(23)setErr(PrintStream err)
(24)setIn(PrintStream in)
(25)setOut(PrintStream out)
(26)setSecurityManager(SecurityManager s)
(27)setProperties(Properties props)
(28)setProperty(String key, String value )

11.

Why delete function faster in the linked list as compare to array in Java?

Answer»

Why delete function faster in the linked LIST as COMPARE to array in Java?
Delete Function is faster in linked lists becasue in linked list user needs to make only some MINOR change to the pointer value. Once we change the poniter value node can point to the NEXT SUCCESSOR in the list.

12.

Difference between ArrayList and LinkedList

Answer»

Difference between ArrayList and LinkedList
Below are the 4 main difference between ArrayList vrs LinkedList
(1) ArrayList uses a DYNAMIC ARRAY to store the elements internally. On the other hand LinkedList uses a doubly linked list to store the elements internally.
(2) ArrayList is better when we are storing and accessing data. On the other hand LinkedList is better for manipulating data.
(3) If we do MANIPULATION with ArrayList it is very slow because it internally uses an array. If we remove any ELEMENT from the array, all the bits are shifted in memory. On the other hand Manipulation with LinkedList is faster than ArrayList because it uses a doubly linked list, so no bit shifting is required in memory.
(4) An ArrayList class can act as a list only because it implements List only. LinkedList class can act as a list and queue both because it implements List and Deque interfaces.

13.

Write code to find the Second Highest number in an ArrayList in Java?

Answer»

Write code to find the Second HIGHEST number in an ArrayList in Java?
Below is the code to get the Higest and the second higest number from given array here i have created a class for that.

public class SecondHigest
{
public static void main(String[] ARGS)
{
int array[] = { 1, 2, 3, 4, 5 ,6 ,7 ,8 ,9 ,10 ,11 ,12, 13, 14};
int highNumber = 0;
int secondHighNumber = 0;
for (int i = 0; i < array.length; i++)
{
if (array[i] > highNumber)
{
secondHighNumber = highNumber;
highNumber = array[i];
}
else if (array[i] > secondHighNumber)
{
secondHighNumber = array[i];
}
}
System.out.println(" nSecondHighest Number is:" + secondHighNumber);
System.out.println("Highest Number is: " +highNumber);
}
}
Output:

SecondHighest Number is:13

Highest number is: 14

14.

Difference between applications and applets

Answer»

1)Application must be run on local MACHINE whereas applet needs no EXPLICIT installation on local machine.
2)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser.
3)Application starts execution with its main method whereas applet starts execution with its INIT method.
4)Application can run with or WITHOUT graphical user INTERFACE whereas applet must run within a graphical user interface.

15.

Comparison between List, Set, and Queue in Java

Answer»

Comparison between LIST, Set, and QUEUE in Java
Below is the difference between above 3 in questions define:-
(1)List:-INSERTION ORDER is maintained in List
(1)Set:-In Hash set Insertion order is not maintained
(1)Queue:-In queue Insertion order is maintained.

(2)List:-In List we can contain duplicate elements
(2)Set:-In Set we cannot have duplicate elements
(2)Queue:-It can have duplicate elements

(3)List:-Insertion and removing of array can be DONE for any index in List.
(3)Set:-In set we can remove the specified element.
(3)Queue:-In Queue we can only do on the last inserted element can be popped out. Also, insertion of elements happens at end.

16.

What are Basic Operators in Java?

Answer»

What are Basic Operators in Java?
we can SAY operators are the integral part of any programming languages. Operators are generally used to manipulate primitive data types. Operators are mainly classified and listed acording to precedence order. And Java operators are generally used to manipulate primitive data types.
We can classifiy operator in following categories:-
(1)ASSIGNMENT Operator
(2)Arithmetic Operators
(3)Relational Operators
(4)Unary Operators
(5)LOGICAL Operators
(6)Conditional(TERNARY) Operators
(7)InstanceOf Operator
(8)Bitwise Operators

17.

Difference between Local and Instance variable in Java with example

Answer»

Difference between Local and Instance variable in Java with example
First of all we will take Local variable. We can use local variable inside METHOD, constructor or any block in CLASSES. The main thing is that it has only local scope and cannot cross that scope means if we define in one block then scope is only that block same as happen with method. And one of the main benefits of using local variable is that other methods in the class cannot use or aware of the local variable define in the method. Below is the example of local variable
if(i>10)
{
string websitename="crackyourinterview.com";
}

in above CODE scope of string variable is only that if block.


Now comes to Instance variable. This variable is bounded to its object itself. We will declared this variable in the class. And these declare OUTSIDE the method. And when any object of class will use they will create a copy of the variable. So once some one made CHANGE to that variable will not reflect in any other instance of that class and scope of that to particular instance only.
class student{
Public string studentName;
public in studentage;
}

Here both of the variable are instance variable any method in the class can use these 2 variables.

18.

Can we inherited the constructor in Java?

Answer»

Can we INHERITED the CONSTRUCTOR in JAVA?
No we cann't inherited the constructor in Java.

19.

difference between C and Java on pointers

Answer»

(1)Both of these have pointers but JAVA pointers are not same as c pointers.
(2)Pointers in Java are not EXPLICIT like in C language.
(3)JVM internally uses pointers and these pointers cannot be directly manipulated.
(4)A pointer is a variable that holds the memory address of data. In Java there are only references which do not hold any memory address but
which are INDICES in a table and this table has then the real pointer to
the data.
(5)Pointer ARITHMETIC is not possible with Java pointers.

20.

Final keyword in Java and different contexts

Answer»

Final KEYWORD in JAVA and different contexts
Final is one of the special keyword used in Java and that is used as a non-access MODIFIERS. Below are the different contexts which is used Final keyword:-

(1)Final Variable:-Once we used final keyword with variable we cannot change its value once we assigned. If no values is assigned to the final keyword then by using the class constructor a value can be assigned to it.

(2)Final METHOD:-When we declare method as final then it cannot be overridden by the inheriting class.

(3)Final class:-When a class is declared as final in java then it cannot be extended by any subclass class but it can extend other class.

21.

What do you think why pointer are not used in Java?

Answer»

What do you think why POINTER are not used in Java?
Below are the three main points why Java not using POINTERS
(1)As we know pointer are UNSAFE and also increase the compleity of program so one reason why Java not use pointer.

(2)Java is also know for its simplicity in the code and pointer handling is little complex.

(3)As pointer relates to memory allocation on another hand Java used JVM which will handle memory allocation so there is no need of that.

22.

Basic of JDK, JRE and JVM and there difference?

Answer»

Basic of JDK, JRE and JVM and there difference?
Below is the 3 main difference between JDK, JRE and JVM
(1)Full form
JDK:-JDK stands for Java Development KIT.
JRE:-JRE stands for Java Runtime Environment.
JVM:-JVM stands for Java Virtual Machine.

(2)Basic operation
JDK:-JDK is the tool which is important to compile, document and PACKAGE Java programs.
JRE:-Its a runtime environment in which Java bytecode can be executed.
JVM:-JVM is an abstract machine. Basically its a specification which provides a run-time environment where Java bytecode can be executed.

(3)Implementation and Development
JDK:-JDK contains JRE PLUS development tools.
JRE:-JRE is an implementation of the JVM which physically exists.
JVM:-JVM basically follows three notations:-
(i)Specification,
(ii)Implementation
(III)Runtime INSTANCE.

23.

what is an object

Answer»

An object is an entity with certain attributes/ QUALITIES and behaviors to under stand this we take an example of a 'computer'. Computer is an object which has certain attributes LIKE WEIGHT,COLOR,screen size,manufacturer,noofkeys etc. It also has various behaviors or activities to do or act upon, as play games,browse Internet,CHECK emails , watch movies ,listen music,calc,notepad etc.

24.

what is a transient variable in java

Answer»

A variable that donot allow for object serialisation. so that the STATE of the value will always be defaulted after the deserialisation.It is CALLED transient variables to UNDERSTAND this we TAKE a example of it:-
If a variable a's value is set to 9 and it's default value is '0'now when the object has been serialized having a's value 9, but after deserialisation will be defaulted to '0' .