0% found this document useful (0 votes)
10 views6 pages

Cognizant Interview SQL Java (1)

The document provides a comprehensive guide for preparing for interviews at Cognizant, covering important topics in SQL, Java, CSS, and JavaScript, along with coding questions and HR interview tips. It includes detailed explanations of key concepts, differences between various programming constructs, and sample coding logic. Additionally, it offers insights into how to effectively present oneself during HR interviews and answers to common interview questions.

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)
10 views6 pages

Cognizant Interview SQL Java (1)

The document provides a comprehensive guide for preparing for interviews at Cognizant, covering important topics in SQL, Java, CSS, and JavaScript, along with coding questions and HR interview tips. It includes detailed explanations of key concepts, differences between various programming constructs, and sample coding logic. Additionally, it offers insights into how to effectively present oneself during HR interviews and answers to common interview questions.

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/ 6

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

...[Java content already added]...

CSS Interview Questions with Answers

...[CSS content already added]...

JavaScript Interview Questions with Answers

...[JavaScript content already added]...

Java Exception Handling & Strings

11. What is exception handling in Java? Exception handling in Java is a powerful mechanism that
handles runtime errors, maintaining the normal flow of application execution. Java provides five
keywords: try , catch , throw , throws , and finally .

• try : Wraps code that might throw an exception.


• catch : Catches and handles the exception.
• finally : Executes code after try-catch , regardless of exception.
• throw : Used to explicitly throw an exception.
• throws : Declares exceptions in method signatures.

12. Difference between throw and throws?

• throw is used to explicitly throw a single exception.


• throws is used in method signature to declare possible exceptions.

Example:

void demo() throws IOException {


throw new IOException("Error");
}

1
13. Use of final, finally, and finalize()?

• final : Restricts user. Variables can’t be changed, methods can’t be overridden, and classes
can’t be inherited.
• finally : Executes code after try-catch, used for cleanup like closing connections.
• finalize() : Method invoked by garbage collector before object destruction.

14. Difference between checked and unchecked exceptions?

• Checked exceptions are checked at compile-time (e.g., IOException , SQLException ).


• Unchecked exceptions occur during runtime (e.g., NullPointerException ,
ArithmeticException ).

15. Difference between String, StringBuffer, and StringBuilder?

• String : Immutable, creates new object if modified.


• StringBuffer : Mutable, synchronized (thread-safe).
• StringBuilder : Mutable, not synchronized (faster in single-threaded).

Java Collections & Arrays

16. Difference between ArrayList and LinkedList?

• ArrayList : Backed by dynamic array. Fast for retrieval, slow for insertion/deletion.
• LinkedList : Uses doubly linked list. Fast for insertion/deletion, slower for random access.

17. Difference between HashMap and Hashtable?

• HashMap : Allows one null key and multiple null values, not synchronized.
• Hashtable : Doesn’t allow null keys or values, synchronized (thread-safe).

18. Difference between Set, List, and Map?

• Set : No duplicate elements. Implemented by HashSet , TreeSet , etc.


• List : Ordered collection, allows duplicates. Implemented by ArrayList , LinkedList .
• Map : Stores key-value pairs. Keys are unique. Implemented by HashMap , TreeMap .

19. How to iterate over a Map or List in Java?

// List
for(String item : list) {
System.out.println(item);
}

// Map
for(Map.Entry<String, String> entry : map.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}

2
HTML Interview Questions with Answers

1. What is HTML? HTML stands for HyperText Markup Language. It is the standard language for
creating web pages by structuring content using elements.

2. What are semantic tags in HTML? Semantic tags clearly define their meaning: <header> ,
<footer> , <article> , <section> , <nav> , etc. Help with SEO and accessibility.

3. Difference between ** and ** ?

• <div> : Block-level element used for layout.


• <span> : Inline-level element used for styling small portions.

4. Purpose of ``? Declares the HTML version used (HTML5). Helps browser render the page correctly.

5. Difference between id and class attributes?

• id : Unique identifier (only one per page).


• class : Can be used on multiple elements for styling.

6. Types of input in HTML5? text , email , password , number , range , date , color ,
file , search , url , etc.

7. Use of the `` tag? Defines metadata about the HTML document (charset, description, author,
viewport for responsiveness).

8. Difference between ** and ** ?

• <script> : Embeds/external JS.


• <noscript> : Shown when browser doesn’t support JS.

9. Purpose of the `` tag? Defines a form to collect user input. Contains controls like input, textarea,
submit.

10. Difference between block-level and inline elements?

• Block: Starts on new line ( <div> , <p> , <h1> , etc.)


• Inline: Resides in line with content ( <a> , <span> , <strong> )

Coding Questions with Sample Logic (Java)

1. Reverse of a String

String input = "hello";


StringBuilder reversed = new StringBuilder(input).reverse();
System.out.println(reversed);

2. Factorial Code

3
int fact = 1;
for(int i = 1; i <= n; i++) {
fact *= i;
}

3. Sum of 2 Numbers

int sum = a + b;
System.out.println("Sum: " + sum);

4. Prime Numbers from 1 to N

for(int i = 2; i <= n; i++) {


boolean isPrime = true;
for(int j = 2; j <= Math.sqrt(i); j++) {
if(i % j == 0) {
isPrime = false;
break;
}
}
if(isPrime) System.out.println(i);
}

5. Add 2 Dictionaries (Java Maps)

Map<String, Integer> map1 = new HashMap<>();


Map<String, Integer> map2 = new HashMap<>();
map1.put("a", 1);
map2.put("b", 2);
map1.putAll(map2);
System.out.println(map1);

6. Leap Year Check

if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {


System.out.println("Leap Year");
} else {
System.out.println("Not a Leap Year");
}

7. Odd and Even Numbers

if(num % 2 == 0)
System.out.println("Even");

4
else
System.out.println("Odd");

8. Palindrome Check

String original = "madam";


String reversed = new StringBuilder(original).reverse().toString();
if(original.equals(reversed))
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");

9. Remove Duplicates from Array (Java)

int[] arr = {1, 2, 2, 3};


Set<Integer> set = new HashSet<>();
for(int num : arr) set.add(num);
System.out.println(set);

HR Questions (Cognizant)

1. Self Introduction Start with name, education background, technical skills, certifications, project
experience, achievements, and hobbies. Keep it under 2 minutes.

2. Project in your Resume Mention:

• Project Title
• Technologies Used
• Role and Contribution
• Outcome
• Challenges faced and how you solved them

3. Certifications Mention relevant ones like:

• Java Certification
• AWS Cloud Practitioner
• SQL Databases

4. Relocation “Yes, I am open to relocation as I see it as an opportunity for growth and new
experiences.”

5. Strengths Adaptability, Communication, Problem Solving, Teamwork, Learning Attitude

6. Hobbies Coding, Gaming, Reading tech blogs, Cricket, Travelling

7. Internships Explain where, duration, technologies learned, real-world exposure.

5
8. Why Cognizant? Cognizant is known for its employee-centric culture, global presence, diverse
projects, and excellent learning platforms. I believe it will help me grow.

9. Comfortable Language "I am most comfortable with Java and have also worked with SQL, HTML,
and CSS."

Real Interview Questions (from Cognizant Candidates)

1. Introduce Yourself — [Covered in HR section above]

2. Remove Duplicates in Array — [Covered in Coding section above]

3. What are Lists? Lists are ordered, index-based collections that allow duplicates. Example:
ArrayList , LinkedList .

4. What is Dictionary? In Python: A key-value pair collection. In Java: Equivalent is Map interface
( HashMap , TreeMap ).

5. What is Inheritance? Inheritance allows one class to inherit properties of another using extends .
Promotes code reuse.

6. Tell me about Pillars of OOPS — [Already explained above: Abstraction, Encapsulation, Inheritance,
Polymorphism]

7. Strengths and Weaknesses — [Also covered in HR section above]

✅ All Interview Questions Fully Answered for SQL, Java, HTML, CSS, JavaScript, Coding, and HR Sections
with complete elaboration.

You might also like