Cross Country Infotech
20+ Starwalk Services Interview Questions and Answers
Q1. Do you have any Java certficate? If no then please leave you are rejected.
Java certification is not mandatory for a Java Developer role.
Certification is not a measure of practical skills and experience.
Experience and skills are more important than certification.
Certification can be helpful in some cases, but not mandatory.
Certification can be expensive and time-consuming.
Employers may value certification differently.
Examples of Java certifications: Oracle Certified Professional Java SE 11 Developer, Java SE 8 Programmer, etc.
Q2. 9. When is memory allocated, when class is created or instance is created or when it is?
Memory is allocated when an instance of a class is created.
Memory allocation happens when an object is created using the 'new' keyword.
Static variables are allocated memory when the class is loaded.
Memory is released when the object is no longer referenced or when the program terminates.
Q3. 13. Other than inheritance what you will use to connect two classes?
We can use composition, aggregation, or association to connect two classes.
Composition is a strong form of aggregation where the lifetime of the contained object is controlled by the container object.
Aggregation is a weaker form of composition where the contained object has an independent lifecycle.
Association is a relationship between two classes where one class uses the functionality of another class.
Examples of association are dependency, inheritance, and realization.
Examp...read more
Q4. 14. What are different types of Access Modifiers in Java?
Access modifiers in Java are used to set the accessibility of classes, methods, and variables.
There are four types of access modifiers in Java: public, private, protected, and default.
Public: accessible from anywhere in the program.
Private: accessible only within the same class.
Protected: accessible within the same class, same package, and subclasses.
Default: accessible within the same package only.
Q5. 3. What is difference between Abstract class and Interface.
Abstract class can have implementation while interface cannot. A class can implement multiple interfaces but can only extend one abstract class.
Abstract class can have constructors while interface cannot.
Abstract class can have instance variables while interface cannot.
Abstract class can have non-abstract methods while interface can only have abstract methods.
A class can implement multiple interfaces but can only extend one abstract class.
Abstract classes are used when there ...read more
Q6. 5. What is difference between composition and inheritance
Composition is a way to combine objects to create complex structures, while inheritance is a way to create new classes based on existing ones.
Composition is a 'has-a' relationship, where an object contains other objects as its parts.
Inheritance is an 'is-a' relationship, where a subclass inherits properties and behaviors from its superclass.
Composition allows for greater flexibility and modularity in design, as objects can be easily swapped out or added.
Inheritance can lead t...read more
Q7. 20. What are different types of collections?
Collections are used to store and manipulate groups of objects in Java. There are three main types of collections.
The three main types of collections are List, Set, and Map.
List is an ordered collection that allows duplicates. Example: ArrayList.
Set is an unordered collection that does not allow duplicates. Example: HashSet.
Map is a collection that maps keys to values and does not allow duplicate keys. Example: HashMap.
Q8. 7. What is difference between throw and throws
throw is used to explicitly throw an exception while throws is used to declare an exception that a method may throw.
throw is used within a method to throw an exception when a certain condition is met
throws is used in the method signature to declare the exceptions that the method may throw
throw is followed by an instance of an exception class while throws is followed by the name of the exception class
throw is used to handle exceptions within a method while throws is used to pr...read more
Q9. 17. Can subclass inherit the properties of Parent class if we not load parent class
No, subclass cannot inherit properties of parent class if parent class is not loaded.
In order for a subclass to inherit properties of a parent class, the parent class must be loaded.
If the parent class is not loaded, the subclass will not have access to its properties.
This is because inheritance is a compile-time concept and requires the parent class to be present during compilation.
Attempting to access properties of an unloaded parent class will result in a compilation error...read more
Q10. 16. Can subclass access private methods parent class?
No, subclass cannot access private methods of parent class.
Private methods are only accessible within the same class where they are defined.
Subclasses can access protected and public methods of parent class.
Private methods can be accessed indirectly through public or protected methods of parent class.
Q11. 10. What is stack in programming?
A stack is a data structure that follows the Last In First Out (LIFO) principle.
Elements are added and removed from the top of the stack.
Push() adds an element to the top of the stack.
Pop() removes the top element from the stack.
Peek() returns the top element without removing it.
Used in programming for function calls, expression evaluation, and memory management.
Q12. 11. What is queue in programming?
A queue is a data structure that follows the FIFO (First In First Out) principle.
Elements are added to the back of the queue and removed from the front.
Common operations include enqueue (add to back) and dequeue (remove from front).
Examples include a line of people waiting for a movie or a printer queue.
Java provides the Queue interface and its implementations like LinkedList and PriorityQueue.
Q13. 2. Give me Real life example of Polymorphism
Polymorphism is when an object can take on multiple forms and behave differently based on the context.
A car can be a vehicle, but it can also be a sports car or a family car, each with different behaviors.
A shape can be a square, rectangle, or triangle, each with different methods for calculating area and perimeter.
A media player can play different types of media, such as audio or video, each with different playback controls.
Q14. 4. Can we have multi level inheritance in Java
Yes, Java supports multi level inheritance.
Multi level inheritance is the process of inheriting a class from another derived class.
It helps in creating a hierarchy of classes with each level inheriting properties from the previous level.
For example, class C can inherit from class B, which in turn inherits from class A.
Java does not support multiple inheritance, where a class can inherit from multiple classes at the same level.
Q15. 12. Difference between error and exception
Errors are unrecoverable, while exceptions are recoverable.
Errors are caused by the environment in which the application is running, while exceptions are caused by the application itself.
Errors cannot be handled by the application, while exceptions can be handled using try-catch blocks.
Examples of errors include OutOfMemoryError and StackOverflowError, while examples of exceptions include NullPointerException and ArrayIndexOutOfBoundsException.
Q16. 1. What are four pillars of OOPS ?
The four pillars of OOPS are Abstraction, Encapsulation, Inheritance, and Polymorphism.
Abstraction: Hiding implementation details and showing only necessary information.
Encapsulation: Binding data and methods together to protect data from outside interference.
Inheritance: Creating new classes from existing ones, inheriting properties and methods.
Polymorphism: Ability of objects to take on multiple forms or behaviors.
Q17. 21. Difference between array and heap?
Arrays are fixed in size and stored in stack memory, while heap is dynamic and stored in heap memory.
Arrays are declared with a fixed size, while heap can grow or shrink dynamically.
Arrays are stored in stack memory, while heap is stored in heap memory.
Arrays can only store elements of the same data type, while heap can store objects of different types.
Examples of arrays include int[], char[], and String[], while examples of heap objects include ArrayList, HashMap, and Linked...read more
Q18. 22. Can we add duplicates to Set?
No, Set does not allow duplicates.
Set is a collection that does not allow duplicates.
If you try to add a duplicate element to a Set, it will not be added.
You can use a List if you need to allow duplicates.
Q19. 23. Can we add duplicates to Array?
Yes, duplicates can be added to an array.
Arrays in Java can contain duplicate elements.
Duplicate elements can be added to an array using the add() method of ArrayList class.
For example, int[] arr = {1, 2, 3, 3, 4}; or ArrayList
list = new ArrayList<>(Arrays.asList(1, 2, 3, 3, 4));
Q20. 15. What is protected ?
protected is a Java access modifier that allows access within the same package and subclasses.
Protected members can be accessed within the same package and subclasses.
It is used to provide encapsulation and prevent direct access from outside the class.
Protected members can be accessed using the dot operator.
Example: protected int num; can be accessed in a subclass using obj.num;
Q21. 19. What are collections?
Collections are objects that group multiple elements into a single unit.
Collections are used to store, retrieve, manipulate and communicate aggregate data.
Java provides a set of interfaces and classes that implement various types of collections.
Examples of collections include List, Set, Map, Queue, etc.
Collections can be used to improve code readability, reusability, and performance.
Q22. 8. Can we have multiple try block
Yes, we can have multiple try blocks in Java.
Multiple try blocks can be used to handle different exceptions separately.
Each try block must have at least one catch or finally block.
Nested try blocks can also be used.
Example: try { //code } catch (Exception e) { //code } try { //code } catch (IOException e) { //code }
Example of nested try blocks: try { try { //code } catch (Exception e) { //code } } catch (Exception e) { //code }
Q23. 6. What is exception handing
Exception handling is the process of handling errors and exceptions that occur during program execution.
Exceptions are objects that represent errors or exceptional situations that occur during program execution.
Exception handling involves catching and handling these exceptions to prevent program crashes.
Java provides try-catch-finally blocks for handling exceptions.
Examples of exceptions include NullPointerException, ArrayIndexOutOfBoundsException, and FileNotFoundException.
Q24. 18. Can class be private?
Yes, a class can be private in Java.
A private class can only be accessed within the same outer class.
It cannot be accessed from outside the class or even from subclasses.
Private classes are often used for implementation details that should not be exposed to other classes.
Example: private class Node in a LinkedList implementation.
Interview Process at Starwalk Services
Top Java Developer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month