0% found this document useful (0 votes)
2 views4 pages

Cognizant Interview SQL Java

The document provides a comprehensive guide for preparing for Cognizant interviews, focusing on SQL, Java, CSS, and JavaScript questions. It includes important Java concepts such as OOP principles, exception handling, and data structures, along with their differences and use cases. Additionally, it covers key SQL topics and hints at upcoming sections on CSS and JavaScript.

Uploaded by

mohammadrafis576
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Cognizant Interview SQL Java

The document provides a comprehensive guide for preparing for Cognizant interviews, focusing on SQL, Java, CSS, and JavaScript questions. It includes important Java concepts such as OOP principles, exception handling, and data structures, along with their differences and use cases. Additionally, it covers key SQL topics and hints at upcoming sections on CSS and JavaScript.

Uploaded by

mohammadrafis576
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Cognizant Interview Preparation: SQL, Java, CSS & JavaScript Questions with Answers

SQL Database Important Questions with Answers

...[SQL content already added]...

Java Important Topics with Answers

1. What are the features of Java?

• Platform Independent
• Object-Oriented
• Robust and Secure
• High Performance via Just-In-Time compiler
• Multithreaded and Portable

2. Explain the four pillars of OOPs in Java.

• Encapsulation: Wrapping data with code (Getters/Setters)


• Abstraction: Hiding implementation details
• Inheritance: Reusing existing class features
• Polymorphism: One name, many forms (Overloading/Overriding)

3. Difference between JDK, JRE, and JVM

• JDK: Java Development Kit (JRE + Development Tools)


• JRE: Java Runtime Environment (JVM + Libraries)
• JVM: Java Virtual Machine (executes bytecode)

4. Difference between == and .equals()

• == compares object references


• .equals() compares object content

Example:

String a = new String("hello");


String b = new String("hello");
System.out.println(a == b); // false
System.out.println(a.equals(b)); // true

5. What is a constructor in Java? Types?

• A constructor initializes an object. Types:


• Default
• Parameterized
• Copy constructor (by convention)

1
6. What is method overloading and overriding?

• Overloading: Same method name, different parameters (compile-time)


• Overriding: Redefining method in subclass (runtime)

7. Difference between abstract class and interface

Feature Abstract Class Interface

Methods Can have both concrete & abstract All methods abstract (Java 7)

Access Can have access modifiers All methods public (Java 7)

Inheritance One class only Multiple interfaces

8. What are access modifiers in Java?

• private: Within class


• default: Within package
• protected: Package + subclass
• public: Everywhere

9. What is encapsulation? How is it implemented? Encapsulation hides internal details using private
variables and public getters/setters.

class Person {
private String name;
public String getName() { return name; }
public void setName(String n) { name = n; }
}

10. What is polymorphism? Give real-time examples. Polymorphism = many forms. Real-time: Printer
class printing PDF, DOC, Images.

• Overloading = compile-time
• Overriding = runtime

11. What is exception handling in Java? Managing runtime errors using try , catch , finally ,
and throw/throws .

12. Difference between throw and throws

• throw is used to manually throw exception


• throws declares exception type in method signature

13. Use of final, finally, and finalize

• final: Const or unchangeable


• finally: Block always executed
• finalize(): Called by GC before destroying object

2
14. Checked vs Unchecked Exceptions

• Checked: Compile-time (IOException)


• Unchecked: Runtime (NullPointerException)

15. Difference between String, StringBuffer, and StringBuilder

Type Mutable Thread-safe

String No Yes

StringBuffer Yes Yes

StringBuilder Yes No

16. Difference between ArrayList and LinkedList

• ArrayList: Fast access, slow insertion/deletion


• LinkedList: Slow access, fast insertion/deletion

17. Difference between HashMap and Hashtable

• HashMap: Not thread-safe, allows null keys/values


• Hashtable: Thread-safe, no nulls

18. Difference between Set, List, and Map

• Set: No duplicates
• List: Ordered with duplicates
• Map: Key-value pairs

19. How to iterate over Map/List?

for(String item : list) {}


for(Map.Entry<String, String> entry : map.entrySet()) {}

20. What is the use of generics in Java? Ensures type safety at compile time.

List<String> names = new ArrayList<>();

21. What is multithreading? Running multiple threads (tasks) simultaneously. Achieved via Thread
or Runnable .

22. Runnable vs Thread class

• Runnable: Implements interface (preferred)


• Thread: Extends class

3
23. What are static variables and methods? Belong to class, not object.

static int count;


static void show() {}

24. Difference between this and super keyword

• this : Current class instance


• super : Parent class instance

25. What is garbage collection? Process of freeing memory by destroying unused objects, done by JVM
automatically.

(Next: CSS and JavaScript Questions with answers...)

You might also like