Last Updated on February 21, 2023 by Prepbytes
Wipro is Multi National Company headquartered in India. Wipro’s business divisions include IT services, digital services, and consulting services. The company provides a wide range of services, such as application development and maintenance, data analytics, cloud computing, cybersecurity, and IoT solutions. Wipro has a diverse customer base that spans industries such as healthcare, finance, retail, manufacturing, and telecommunications.
Wipro is one of the dream companies for many freshers graduating from college and has always been the first company for candidates entering the IT Industry. In this article, we are going to cover the Java Interview Questions that were asked in the Interviews with Wipro.
Wipro Java Interview Questions: Language Fundamentals
This section contains the list of Java Questions which were asked in the Interviews with Wipro.
Q1. What is Java Collection Framework?
Ans. Java Collection Framework is a set of classes and interfaces that provides an organized way to store, manage, and manipulate a group of objects in Java. It is part of the Java Standard Library and is included in all versions of Java since JDK 1.2.
The Java Collection Framework includes various types of collection classes such as lists, sets, and maps. Each collection class has its own unique features, and they are designed to work with different types of data.
Some of the commonly used collection classes in the Java Collection Framework are
- ArrayList: A resizable array that implements the List interface.
- HashSet: A set that does not allow duplicates and has no specific order.
- HashMap: A map that stores key-value pairs and does not allow duplicate keys.
The Java Collection Framework also includes interfaces that define the behavior of the collection classes. For example, the List interface defines methods to add, remove, and access elements from a list. This makes it easy to use the different collection classes interchangeably and to create custom collections that implement the required interface.
Q2. Difference between Interface and Abstract Class in Java.
Ans. In Java, both interfaces and abstract classes are used to define abstractions that can be implemented by other classes. The differences between these two are given below in brief.
- Abstract classes can have both abstract and non-abstract methods, while interfaces can only have abstract methods: An abstract class can have both abstract and non-abstract methods, whereas an interface can only have abstract methods. Non-abstract methods in an abstract class can provide a default implementation, while methods in an interface have to be implemented by the implementing class.
- A class can implement multiple interfaces, but can only inherit from one abstract class: A class can implement multiple interfaces, but it can only inherit from one abstract class. This means that interfaces are more flexible in terms of defining multiple behaviors that a class can implement.
- Abstract classes can have instance variables, while interfaces cannot: Abstract classes can have instance variables that can be inherited by their subclasses, while interfaces cannot have any instance variables.
- Abstract classes can have constructors, while interfaces cannot: Abstract classes can have constructors that are called when an instance of a subclass is created, while interfaces cannot have constructors.
Q3. What is an Exception in Java?
Ans. In Java, an exception refers to an event or condition that occurs during the execution of a program that disrupts the normal flow of instructions. When an exceptional condition arises, such as an error or other unexpected behavior, Java creates an object called an "exception object" that contains information about the exception, including the type of exception and the state of the program when the exception occurred in the program.
Exceptions in Java can be caused by a variety of reasons, including programming errors, hardware failures, network errors, and user input errors. The Java programming language provides a built-in mechanism for handling exceptions through try-catch blocks.
In a try-catch block, code that may cause an exception is enclosed in a "try" block, and the code that handles the exception is enclosed in a "catch" block. If an exception is thrown in the try block, control is transferred to the catch block, which can then handle the exception in an appropriate manner, such as logging an error message, notifying the user, or taking corrective action.
Q4. What is the primary benefit of Encapsulation in Java?
Ans. Encapsulation is a fundamental principle of object-oriented programming that refers to the concept of bundling data and methods that operate on that data within a single unit, or class. The primary benefit of encapsulation in Java is that it provides a mechanism for hiding the internal details of an object from the outside world while exposing only the necessary functionality through a well-defined interface.
Here are some of the specific benefits of encapsulation in Java:
- Data Protection: Encapsulation helps to protect the data of an object from being accessed or modified by unauthorized code.
- Code Modularity: Encapsulation promotes code modularity by creating a clear separation between an object’s internal workings and its external interface
- Increased Flexibility: Encapsulation makes it possible to change the implementation of an object’s methods or data structure without affecting other parts of the code that use that object.
- Improved Maintainability: By encapsulating an object’s data and methods, it becomes easier to maintain and debug the code.
Q5. What do you mean by final, finally, and finalize in Java?
Ans. In Java, "final," "finally," and "finalize" are three distinct keywords with different meanings and uses. Here’s a brief explanation of each:
- "final": "final" is a keyword used to declare a variable, method, or class as unchangeable or immutable. When you declare a variable as final, you cannot reassign a new value to that variable. Similarly, when you declare a method as final, you cannot override that method in any subclass. When you declare a class as final, you cannot extend that class.
- "finally": "finally" is a block of code that is used in a try-catch block to ensure that a section of code is always executed, regardless of whether an exception is thrown or not. The "finally" block is executed after the try block and any associated catch blocks have finished executing. This is often used to clean up resources that were used in the try block.
- "finalize": "finalize" is a method that is called by the garbage collector when an object is about to be destroyed. This method is used to perform any necessary cleanup tasks, such as closing open files or releasing other resources. However, it is generally not recommended to rely on the "finalize" method for cleanup, as the garbage collector may not immediately destroy an object and call its "finalize" method.
Q6. Define Packages in Java.
Ans. In Java, a package is a mechanism used to organize and group related classes, interfaces, and sub-packages. Packages help to prevent naming conflicts and make it easier to manage large projects with many classes.
A package is declared using the package keyword at the beginning of a Java source file. For example, to declare a package named "com.example.myapp", you would include the following statement at the beginning of each source file in that package:
package com.example.myapp;
Classes within a package can be accessed by other classes within the same package without any special access modifiers. However, to access a class from another package, you need to import the class using the import statement. For example:
import com.example.myapp.MyClass;
This makes the class named "MyClass" within the "com.example.myapp" package available to the current source file.
Java provides a number of built-in packages, such as java.lang, java.util, and java.io, which contain commonly used classes and interfaces. Additionally, developers can create their own packages to organize their own classes and interfaces.
Packages can be organized into a hierarchical structure, with sub-packages containing further sub-packages and classes. For example, the package "com.example.myapp" might contain sub-packages such as "com.example.myapp.util" and "com.example.myapp.gui".
Using packages is an important part of writing scalable and maintainable Java code, and is a key feature of the Java programming language.
Q7. Describe Multithreading in Java.
Ans. Multithreading in Java is the ability to have multiple threads of execution operating in a single program. A thread is a lightweight process that runs within the context of a single program, sharing the same memory space and resources with other threads in the program.
In Java, multithreading is achieved through the java.lang.Thread class, which provides the ability to create, start, pause, resume, and stop threads. Java also provides a number of concurrency utilities, such as the Executor framework, to simplify the management of threads.
To create a new thread, you can extend the Thread class or implement the Runnable interface, which defines the run() method that contains the code to be executed in the thread. Once the thread is created, you can start it by calling its start() method. The start() method automatically calls the run() method in the new thread, which runs asynchronously with the other threads in the program.
Java provides several mechanisms to coordinate and control the execution of threads, such as synchronization and locks, which allow multiple threads to access shared resources in a controlled manner. It also provides tools for communication between threads, such as the wait(), notify(), and notifyAll() methods, which allow threads to signal each other when certain conditions are met.
Multithreading can improve the performance and responsiveness of Java applications, especially in situations where there are long-running or blocking operations that would otherwise cause the application to become unresponsive. However, multithreading can also introduce new challenges, such as race conditions and deadlocks, which can be difficult to debug and fix.
Q8. What is the difference between Array and ArrayList?
Ans.
Array | ArrayList |
---|---|
Fixed-size | Dynamic size |
Primitive data types and objects can be stored | Only objects can be stored |
Memory is allocated at compile-time | Memory is allocated at runtime |
Not flexible, cannot be resized easily | Flexible, can be resized easily |
Performance is faster | Performance is slower |
Can contain both homogeneous and heterogeneous data types | Can contain only homogeneous data types |
Has no built-in methods for adding or removing elements | Has built-in methods for adding and removing elements |
Can be multi-dimensional | Can be only single dimensional |
Length is accessed using length property | Size is accessed using size() method |
Array elements are accessed using index numbers | ArrayList elements are accessed using get() and set() methods |
Q9. What do you mean by Interface in Java?
Ans. In Java, an interface is a collection of abstract methods and constant variables. An interface defines a contract that specifies what methods a class implementing the interface should have. It defines a set of methods and their signatures but does not provide any implementation for those methods.
An interface is declared using the interface keyword and can include methods, constants, and default methods. Here is an example of a simple interface in Java:
public interface MyInterface {
void myMethod();
}
This interface declares a single method called myMethod() which has no implementation. Any class that implements this interface is required to provide an implementation for this method.
To implement an interface in Java, a class must use the implements keyword in its declaration and provide implementations for all the methods declared in the interface. Here is an example of a class that implements the MyInterface interface:
public class MyClass implements MyInterface {
@Override
public void myMethod() {
// Implementation of myMethod
}
}
This class provides an implementation for the myMethod() method declared in the MyInterface interface. By implementing the interface, the class is agreeing to adhere to the contract defined by the interface, and other code can use instances of the class in a polymorphic manner based on the interface.
Q10. What is Destructor? Does Java have Destructor?
Ans. A destructor is a member function in object-oriented programming languages that is used to release resources that were acquired by an object during its lifetime. A destructor is called when an object is destroyed, which usually happens when it goes out of scope, is deleted, or when the program terminates.
In Java, there is no direct equivalent of a destructor. Java uses garbage collection to automatically free memory that is no longer being used by objects. When an object is no longer referenced by any variables or other objects, the garbage collector will automatically free the memory used by the object.
While Java does not have a destructor, it does have a finalize() method which can be used to perform cleanup tasks before an object is a garbage collected. However, the use of the finalize() method is discouraged in Java because it can cause performance issues and can be unpredictable in terms of when it will be called. Instead, it is generally recommended to use try-with-resources or other mechanisms to ensure that resources are properly released when they are no longer needed.
Wipro Java Interview Questions: Coding
Here is some Coding Questions that were asked in Wipro Coding Round.
Q1. Write a program to Reverse a Number in Java
Ans.
public class Main { public static void main(String[] args){ int number = 677654, reverse = 0; while(number != 0){ int remainder = number % 10; reverse = reverse * 10 + remainder; number = number/10; } System.out.println("The reverse of the given number is: " + reverse); } }
Output:
The reverse of the given number is: 456776
Q2. Write a program to Left Rotate an Array in Java
Ans.
class Main { public static void main(String[] args) { int [] arr = {1, 2, 3, 5, 6, 4, 5}; System.out.println("Original array: "); for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } System.out.println(); int j, first; first = arr[0]; for(j = 0; j < arr.length-1; j++){ arr[j] = arr[j+1]; } arr[j] = first; System.out.println("Array after left rotation: "); for(int i = 0; i< arr.length; i++){ System.out.print(arr[i] + " "); } } }
Output:
Original array:
1 2 3 5 6 4 5
Array after left rotation:
2 3 5 6 4 5 1
Q3. Write a program to check whether Two Matrices are identical or not.
Ans.
class PrepBytes{ static final int N = 4; static int areSame(int A[][], int B[][]){ int i, j; for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (A[i][j] != B[i][j]) return 0; return 1; } public static void main (String[] args){ int A[][] = { {1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4}}; int B[][] = { {1, 1, 1, 1}, {2, 2, 2, 2}, {3, 3, 3, 3}, {4, 4, 4, 4}}; if (areSame(A, B) == 1) System.out.print("Matrices are identical"); else System.out.print("Matrices are not identical"); } }
Output:
Matrices are identical
Q4. Convert Binary Number into Decimal Equivalent in Java
Ans.
class Main { public static int convertBinaryToDecimal(long num) { int decimalNumber = 0, i = 0; long remainder; while (num != 0) { remainder = num % 10; num /= 10; decimalNumber += remainder * Math.pow(2, i); ++i; } return decimalNumber; } public static void main(String[] args) { long num = 110111; int decimal = convertBinaryToDecimal(num); System.out.println("Binary to Decimal"); System.out.println(num + " = " + decimal); } }
Output:
Binary to Decimal
110111 = 55
Q5. Write a Program to Second Largest Number in an array.
Ans.
public class Main{ public static int getSecondLargest(int[] a, int total){ int temp; for (int i=0; i<total; i++){ for (int j = i+1; j<total; j++){ if (a[i]>a[j]){ temp = a[i]; a[i] = a[j]; a[j] = temp; } } } return a[total-2]; } public static void main(String args[]){ int a[]={1,2,5,6,3,2}; System.out.println("Second Largest: "+getSecondLargest(a,6)); } }
Output:
Second Largest: 5
Frequently Asked Questions (FAQs)
Q1. What is the interview process at Wipro?
Ans. The interview process at Wipro typically includes a written test (Online Assessment, Written Communication Test, Online Coding Rounds) , a technical interview, and an HR interview.
Q2. What is the written test at Wipro?
Ans. The written test at Wipro assesses your aptitude, reasoning, and technical skills.
Q3. What is the technical interview at Wipro?
Ans. The technical interview at Wipro assesses your technical knowledge and skills related to the job role you have applied for.
Q4. What kind of questions are asked in the Wipro interview?
Ans. The questions asked in the Wipro interview depend on the job role you have applied for. They may include technical questions, problem-solving questions, and behavioral questions.
Q5. What are the skills required to get a job at Wipro?
Ans. The skills required to get a job at Wipro vary depending on the job role, but generally include strong technical skills, problem-solving skills, communication skills, and a willingness to learn.
Q6. What are some tips for preparing for the Wipro interview?
Ans. Some tips for preparing for the Wipro interview include researching the company, practicing your technical skills, and preparing answers to common interview questions.
Q7. How can I prepare for the Wipro written test?
Ans. You can prepare for the Wipro written test by practicing aptitude and technical skills, and by studying previous year question papers.