To over come these problems collections are recommended to use. Collections Arrays

Similar documents
This is just a compilations of some notes together with my own notes during the preparation for SCJP exam. Implementations

In Java, we can use Comparable and Comparator to compare objects.

Data Structure Interview Questions

2. Candidate can appear in SCJA/OCJA or SCJP/OCJP certifications. Module I

Common Language Runtime

- Replacement of a single statement with a sequence of statements(promotes regularity)

But for better understanding the threads, we are explaining it in the 5 states.

SAS Viya 3.2 Administration: Mobile Devices

SW-G using new DryadLINQ(Argentia)

Design Patterns. Collectional Patterns. Session objectives 11/06/2012. Introduction. Composite pattern. Iterator pattern

Operating systems. Module 7 IPC (Interprocess communication) PART I. Tami Sorgente 1

$ARCSIGHT_HOME/current/user/agent/map. The files are named in sequential order such as:

CS4500/5500 Operating Systems Synchronization

Please contact technical support if you have questions about the directory that your organization uses for user management.

C pointers. (Reek, Ch. 6) 1 CS 3090: Safety Critical Programming in C

Lab 5 Sorting with Linked Lists

C Sc 335 Practice Test 1 Section Leader Name 150pts. 3. List two Java structures that allow for polymorphic messages (2pts)

Using SPLAY Tree s for state-full packet classification

SOLA and Lifecycle Manager Integration Guide

Programming Project: Building a Web Server

History of Java. VM (Java Virtual Machine) What is JVM. What it does. 1. Brief history of Java 2. Java Version History

INSTALLING CCRQINVOICE

Lecture 6 -.NET Remoting

1 Version Spaces. CS 478 Homework 1 SOLUTION

Creating a TES Encounter/Transaction Entry Batch

Constituent Page Upgrade Utility for Blackbaud CRM

Synoptic Display Studio Developers Guide

Lecture Handout. Database Management System. Overview of Lecture. Inheritance Is. Lecture No. 11. Reading Material

TRAINING GUIDE. Lucity Mobile

LAB 7 (June 29/July 4) Structures, Stream I/O, Self-referential structures (Linked list) in C


Creating Relativity Dynamic Objects

Admin Report Kit for Exchange Server

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture2 Functions

ISTE-608 Test Out Written Exam and Practical Exam Study Guide

CS510 Concurrent Systems Class 1a. Linux Kernel Locking Techniques

Create Your Own Report Connector

Maximo Reporting: Maximo-Cognos Metadata

Assignment 10: Transaction Simulation & Crash Recovery

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2

Creating Relativity Dynamic Objects

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

CSE 3320 Operating Systems Synchronization Jia Rao

It has hardware. It has application software.

Chapter 3 Stack. Books: ISRD Group New Delhi Data structure Using C

Overview of OPC Alarms and Events

Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use.

Project #1 - Fraction Calculator


Querying Data with Transact SQL

Relius Documents ASP Checklist Entry

Access the site directly by navigating to in your web browser.

Getting Started with the Web Designer Suite

Oracle BPM 10rR3. Role Authorization resolution using groups. Version: 1.0

MySqlWorkbench Tutorial: Creating Related Database Tables

Announcing Veco AuditMate from Eurolink Technology Ltd

Infrastructure Series

Xilinx Answer Xilinx PCI Express DMA Drivers and Software Guide

Sometimes it's necessary to issue requests to objects without knowing anything about the operation being requested or the receiver of the request.

isupport Case Management Project ANXT Maintain Next Activity Design Specification Document ANXT Maintain Next Activity

Lecture Handout. Database Management System. Overview of Lecture. Vertical Partitioning. Lecture No. 24

Java Programming Course IO

Ascii Art Capstone project in C

Faculty Textbook Adoption Instructions

Configure Data Source for Automatic Import from CMDB

Data Requirements. File Types. Timeclock

Structure Query Language (SQL)

CS510 Concurrent Systems Class 2. A Lock-Free Multiprocessor OS Kernel

Once the Address Verification process is activated, the process can be accessed by employees in one of two ways:

Framework Components Our ETL parameter framework will include primarily two components.

IMPORTING INFOSPHERE DATA ARCHITECT MODELS INFORMATION SERVER V8.7

COP2800 Homework #3 Assignment Spring 2013

DECISION CONTROL CONSTRUCTS IN JAVA

TRAINING GUIDE. Overview of Lucity Spatial

Product Release Notes

USER MANUAL. RoomWizard Administrative Console

The Abstract Data Type Stack. Simple Applications of the ADT Stack. Implementations of the ADT Stack. Applications

B Tech Project First Stage Report on

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2 Iterative Code Design handout Style Guidelines handout

softpanel generic installation and operation instructions for nanobox products

These tasks can now be performed by a special program called FTP clients.

Aras Innovator 11. Package Import Export Utilities

Assignment #5: Rootkit. ECE 650 Fall 2018

ClassFlow Administrator User Guide

The Java if statement is used to test the condition. It checks Boolean condition: true or false. There are various types of if statement in java.

Because this underlying hardware is dedicated to processing graphics commands, OpenGL drawing is typically very fast.

Log shipping is a HA option. Log shipping ensures that log backups from Primary are

EView/400i Management Pack for Systems Center Operations Manager (SCOM)

ME Week 5 Project 2 ilogic Part 1

Element Creator for Enterprise Architect

Arius 3.0. Release Notes and Installation Instructions. Milliman, Inc Peachtree Road, NE Suite 1900 Atlanta, GA USA

Customer Self-Service Center Migration Guide

Stealing passwords via browser refresh

RISKMAN REFERENCE GUIDE TO USER MANAGEMENT (Non-Network Logins)

ROCK-POND REPORTING 2.1

Simple Regression in Minitab 1

INSERTING MEDIA AND OBJECTS

NVIDIA S KEPLER ARCHITECTURE. Tony Chen 2015

CaseWare Working Papers. Data Store user guide

Transcription:

Q1. What are limitatins f bject Arrays? The main limitatins f Object arrays are These are fixed in size ie nce we created an array bject there is n chance f increasing r decreasing size based n ur requirement. Hence If we dn t knw size in advance, arrays are nt recmmended t use Arrays can hld nly hmgeneus elements. There is n underlying data structure fr arrays and hence n readymade methd supprt fr arrays. Hence fr every requirement prgrammer has t cde explicitly T ver cme these prblems cllectins are recmmended t use Q2. What are differences between arrays and cllectins? Cllectins Arrays 1. Arrays r fixed in size and hence nce we created 1. Cllectins are grw able in nature and hence an array we are nt allwed t increase r decrease based n ur requirement we can increase r decrease the size based n ur requirement. the size. 2. Memry pint f view arrays are nt 2. Memry pint f view cllectins are recmmended t use recmmended t use. 3. Perfrmance pint f view arrays are 3. Perfrmance pint f view cllectins are nt recmmended t use recmmended t use. 4. Arrays can hld nly hmgeneus elements 4. Cllectins can hld bth hmgeneus and hetergeneus elements. 5. Arrays can hld bth primitives as well as 5. Cllectins can hld nly bjects. bjects 6. Fr any requirement, there is n ready methd supprt cmpulsry prgrammer has t cde explicitly. Q3. What are differences between arrays and ArrayList? Refer the answer f Q2 Q4. What are differences between arrays and Vectr? Refer the answer f Q2 6. Fr every requirement ready made methd supprt is available. Being a prgrammer we have t knw hw t use thse methds and we are nt respnsible t implement thse. Q5. What is Cllectin API? It defines set f classes and interfaces which can be used fr representing a grup f bjects as single entity Q6. What is Cllectin framewrk?

It defines set f classes and inter faces which can be used fr representing a grup f bjects as single entity Q7. What is the difference between Cllectins and Cllectin? Cllectin is an interface which can be used fr representing a grup f individual bjects as single entity and it acts as rt interface f cllectin frame wrk. Cllectins is an utility class t define several utility methds fr Cllectin implemented class bjects. Q8. Explain abut Cllectin interface? This interface can be used t represent a grup f bjects as a single entity. It acts as rt interface fr entire cllectin framewrk. It defines the mst cmmnly used methds which can be applicable fr any cllectin implemented class bject Q9. Explain abut List interface? List interface is a child interface f Cllectin interface. This can be used t represent grup f individual bjects in as a single entity where Duplicates are allwed Insertin rder is preserved Q10. Explain abut Set interface? Set is a child interface f Cllectin interface. it can be used t represent a grup f individual bjects as a single entity where Duplicate bjects are nt allwed. Insertin rder is nt preserved Q11. Explain abut SrtedSet interface? it is child interface f Set interface. it can be used t represent a grup f individual bjects in t a single entity where All the bjects are arranged in sme srting rder (Can be natural srting rder r custmizede). Duplicates are nt allwed. Q12. Explain abut NavigableSet? It is child interface f SrtedSet and prvides several utility methds fr navigatin purpses

It desn t allws duplicates Insertin rder is preserved It is intrduced in 1.6 versin Q13. Explain abut Queue interface? If we want t represent a grup f individual bjects prir t prcessing, then we shuld g fr Queue interface. It is child interface f Cllectin interface. It has intrduced in 1.5 versin. Q14. Explain abut Map interface? Remember it is nt a child Interface f Cllectin Interface and hence Map and Cllectin Interfaces desn t have any relatinship. It can be used fr representing a grup f Objects as key, value pairs. Bth keys and values shuld be bjects Keys can t be duplicated but values can be duplicated. it has intrduced in 1.2 versin Q15. Explain abut SrtedMap? If we want t represent a grup f bjects as key value pairs where all the entries are arranged accrding sme srting rder f keys then we shuld g fr SrtedMap. It is child interface f Map. It has intrduced in 1.2 versin Q16. Explain abut NavigableMap? It is child interface f SrtedMap and defines several methd fr navigatin purpse It is intrduced in 1.6 versin Q17. Explain abut ArrayList class? ArrayList is a Cllectin which can be used t represent a grup f bjects as a single entity. it is a implemented class fr List interface Intrduced in 1.2 versin The underlying data structure is resizable r grwable array. Insertin rder is preserved Duplicates are allwed Hetergeneus bjects are allwed null insertin is pssible This class implements RandmAccess, Serializable, Clneable interfaces Best chice fr retrieval purpse and wrst if ur frequent peratin is insertin r deletin in the middle

Q18. What is RandmAccess Interface? If a cllectin class implements RandmAccess interface then we can access any f its element with the same speed. RandmAccess interface is marker interface and it dsent cntains any methds. ArrayList and vectr classes implements this interface. Q19. Explain abut LinkedList class? LinkedList is a Cllectin implemented class which can be used fr representing a grup f bjects as a single entity. LinkedList is the implemetatin class fr List interface Intrduced in 1.2 versin Underlying data Structure is DubleLinkedList Allws duplicates Insertin rder is preserved Allws hetergeneus bjects null insertin is pssible LinkedList class implements Seriallizable and Clneable interface but nt RandmAccess interface Best chice if frequent peratin is insertin r deletin an bjects in middle but wrst chice if frequent peratin is retrieval. Q20. Explain abut Vectr class? Vectr is a legacy cllectin class which can be used t represent a grup f bjects. Intrduced in 1.0 versin. it is legacy class The underlying data structure is resizable r grwable array. Insertin rder is preserved Duplicates are allwed Hetergeneus bjects are allwed It is a implemented class fr List interface null insertin is pssible Vectr class implements RandmAccess,Serializable,Clneable interfaces Best Chice if frequent peratin is retrieval and wrst chice if frequent peratin is insertin r deletin in the middle. All methds present in Vectr class are synchrnized hence Vectr class bject is thread safe. Q21. What is difference between ArrayList and Vectr? Vectr ArrayList 1. N methd is synchrnized in the ArrayList 1. All methds in Vectr are synchrnized. class 2. ArrayList bject is nt thread safe. 2. Vectr is thread safe. 3. Relatively perfrmance is high 3. Relatively perfrmance is lw

4. Intrduced in 1.2 versin and it is nn legacy 4. Intrduced in 1.0 versin and it is legacy Q22. Hw we can get synchrnized versin f ArrayList? Cllectins class cntains synchrnizedlist() methd fr this Public static List synchrnizedlist(list l) EX ArrayList l= new ArrayList(); List l2=cllectins.synchrnizedlist(l); Similarly we can get synchrnized versins f Set and Map bjects by the fllwing methds. Public static List synchrnizedset(set s) Public static List synchrnizedmap(map m) Q23. What is difference between size and capacity f a Cllectin Object? size means number f bjects present where as capacity means n f bjects it can accmmdate. Q24. What is difference between ArrayList and Linked List? ArrayList 1. The underlying data structure is resizable r grwable array. 2. This is Best chice if frequent peratin is retrieval and wrst chice if frequent peratin is insertin r deletin in the middle. 3. This class implements Serializable, Clneable and RandmAccess interfaces. LinkedList 1. The underlying data structure is Duble Linked List. 2. This is Best chice if frequent peratin is insertin r deletin in the middle and wrst chice if frequent peratin is retrieval. 3. This class implements Serializable, Clneable but nt RandmAccess interface. Q25. What are legacy classes and interfaces present in Cllectins framewrk? Enumeratin--Interface Dictnary -----Abstract class Hashtable -----Cncrete class Prperties -----Cncrete class Vectr ---------Cncrete class Stack ---------Cncrete class Q26. what is difference Enumeratin and Iteratr? Enumeratin Iteratr 1. It is legacy interface and intrduced in 1.0 versin 1 It is nn-legacy and intrduced in 1.2 versin 2Applicable nly fr legacy classes and it is nt universal 2Applicable fr any Cllectin implemented class bject.

cursr 3While iterating the elements we are nt allwed t remve the bjects just we can perfrm nly read peratin 4By using elements() methd we can get Enumeratin bject 3While iterating we can perfrm remval als in additin t read peratin. 4. By using iteratr() methd we can get Iteratr bject Q27. What are limitatins f Enumeratin? While iterating the elements we are nt allwed t perfrm remval peratin It is applicable nly fr legacy classes and it is nt a universal cursr. It can retrieve the elements nly in frward directin Q28. What is difference between enum and Enumeratin? An enum can be used t define a grup f named cnstants.it has intrduced in 1.5 versin Ex Class Beer{ KO,KF,RC,FO } Enumeratin is cursr t retrieve Objects ne by ne frm Cllectin bjects. Q29. What is difference between Iteratr and ListIteratr? ListIteratr is the child interface f the Iteratr Iteratr is the single directin cursr where as ListIteratr is bidirectinal cursr. While iterating the elements by Iteratr we can perfrm nly read and remve peratins. But by using ListIteratr we can perfrm read,remval, replace and additin f new bjects als. Iteratr is applicable fr every Cllectn implemented class bject but ListIteratr is applicable nly fr List implemented class bjects. Iteratr can be get by using iteratr() f Cllectin interface where as ListIteratr can be get by using listiteratr() methd f List interface bth are intrduced in 1.2 versin Q30. What is relatin between ListIteratr and Iteratr? ListIteratr is child interface f Iteratr Q31. Explain abut HashSet class? The underlying data structure is Hashtable null values are accepted duplicates are nt allwed insertin rder is based n hashcde f the bject hence insertin rder is nt preserved

best suitable if frequent peratin is search peratins HashSet class implements Serializable and Clneable it is implementatin class fr Set interface hetergeneus bjects are allwed it is intrduced in 1.2 versin Q32. If we are trying t insert duplicate values in Set what will happen? If we are trying t insert duplicate bjects t the HashSet, we wnt get any cmpile time r run time errrs just the add(object ) returns false and it desn t add that bject. Q33. What is LinkedHashSet? It is the child class f HashSet. The main difference between HashSet and LinkedHashSet is: In the case f HashSet insertin rder is nt preserved, but in the case f LinkedHashSet insertin will be preserved. Q34. Differences between HashSet and LinkedHashSet? HashSet 1The Underlying datastructure is Hashtable LinkedHashSet 1The underlying datastructure is cmbinatin f LinkedList and Hashtable 2Insertin Order is nt preserved 2 Insertin rder is preserved. 3Intrduced in 1.2 versin 3 Intrduced in 1.4 versin Q35. What are majr enhancements in 1.4 versin f cllectin frame wrk? LinkedHashSet LinkedHashMap IdentityHashMap Q36. Explain abut TreeSet? It is Cllectin bject which can be used t represent a grup f bjects accrding t sme srting rder. The underlying datastructure is Balanced tree Duplicates are nt allwed All bjects are stred accrding t sme srting rder hence insertin rder is nt preserved Hetergeneus bjects are nt allwed vilatin leads t ClassCastExceptin Fr an Empty TreeSet as firs element null value can be inserted but after inserting that first value if we are trying t insert any ther bjects then we will get NullPinterExceptin Fr an nn empty TreeSet if we are trying t inser null value at run time u will get NullPinterExceptin

Q37. What are differences between List and Set interfaces? List Set 1Insertin Order is preserved 1Insertin Order is nt preserved 2Duplicate Objects are allwed 2 Duplicate Objects are nt allwed 3The implemented classes are ArrayList,LinkedList, 3 The implemented classes are Vectr and Stack classes HashSet, LinkedHashSet and Tree Q38. What is Cmparable interface? This interface can be used fr defining natural srting rder f the bjects. It is present in java.lang package It cntains a methd public int cmparet(object bj1) Q39. What is Cmparatr interface? This interface can be used fr implementing custmized srting rder. It is present in java.util package It cntains tw methds public int cmpare(object,object) public blean equals(object) Q40. What are differences between Cmparable and Cmparatr? Cmparable Cmparatr 1This can be used fr natural srting rder 1This can be used fr implementing custmized srting 2This interface present in java.lang package 2 This is present in java.util package 3Cntains nly ne methd: 3 It cntains tw methds. public int cmpare(object,object) public int cmparet(object bj1) public Blean equals(object) 4 It is marker interface 4 It is nt a marker interface. Q41. What is difference between HashSet and TreeSet? HashSet TreeSet 1The underlying data structure is Hashtable 1The underlying data structure is balanced tree 2Hetergeneus bjects are allwed 2 Hetergeneus bjects are nt allwed bydefalut 3Insertin rder is nt preserved and it is based n hashcde f the bjects 3 Insertin rder is nt preserved and all the bjects are inserted accrding t sme srting rder. 4null insertin is pssible 4 As the first element nly null insertin is pssible and in all ther cases we will get NullPinterExceptin Q42. What is Entry interface? It is inner interface f Map. In the Map each key value pair is cnsidered as Entry bject.

interface Map{ //mre cde here interface Entry{ Object getkey() Object getvalue() Object setvalue(object new) } } Q43. Explain abut HashMap? It is a Map Object which can be used used t represent a grup f bjects as keyvalue pairs. The underlying data structure is Hashtable Duplicaes keys are nt allwed duplicate values are allwed Insertin rder is nt preserved because insertin is based n hashcde f keys. Hetergeneus bjects are allwed fr bth keys and values null key is allwed nly nce null values are allwed multiple times Intrduced in 1.2 versin Q44. Explain abut LinkedHashMap? It is child class f HashMap. It is exactly same as HashMap except the fllwing difference. In the case f HashMap the insertin rder is nt preserved but in the case f LinkedHashMap insertin rder is preserved. Intrduced in 1.4 versin Q45. Differences between HashMap and LinkedHashMap? HashMap 1.The underlying data structure is Hashtable 2.Insertin rder is nt preserved and it is based n hashcde f keys 3.Intrduced in 1.2 versin LinkedHashMap 1.The underlying data structure is a cmbinatin f Hashtable and linkedlist 2 Insertin rder is preserved 3 Intrduced in 1.4 versin. Q46. Differences between HashMap and Hashtable? HashMap 1.The underlying data structure is Hashtable 2.N methd is synchrnized and hence HashMap bject is nt thread safe 3.Perfrmance is high 4.null insertin is pssible fr bth keys and values 5.Intrduced in 1.2 versin and it is nn legacy Hashtable 1.The underlying data structure f Hashtable 2.All methds are synchrnized and hence it is thread safe 3. Perfrmance is lw 4. null insertin is nt pssible fr bth key and value vilatin leads t NullPinterExceptin 5. Intrduced in 1.0 versin and it is legacy

Q47. What is IdentityHashMap? It is exactly same as HashMap except the fllwing difference. In the HashMap JVM uses equals() methd t identify duplicate keys but in the case f IdentityHashMap JVM uses == peratr fr this. Q48. What is difference between HashMap and IdentityHashMap? Refer Q47 fr the answer. Q49. What is WeakHashMap? It is exactly same as HashMap except the fllwing difference. In case f HashMap an Object is nt eligible fr garbage cllectin if it is assciated with HashMap even thugh it dsent have any external references. ie HashMap dminates garbage cllectr. But in case f WeakHashMap, if an Object is nt having any external references then it is always eligible fr garabage cllectin even thugh it is assciated with weakhashmap. ie garbage cllectr dminates WeakHashMap Q50. What is difference between HashMap and WeakHashMap? Refer Q49 fr the answer. Q51. What is TreeMap? TreeMap can be used t stre a grup f bjects as key-value pairs where all the entries are arranged accrding t sme srting rder f keys. The underlying data structure is RED-BLACK Tree Duplicates keys are nt allwed but values can be duplicated. Insertin rder is nt preserved because insertin is based n sme srting rder If we are depending n Natural srting rder then keys shuld be hmgeneus(vilatin leads t ClassCastExceptin) but values need nt hmgeneus In case f custmized srting rder we can insert hetergeneus keys and values Fr empty TreeMap as first entry with null values are allwed but after inserting that entry if we are trying t insert any ther entry we will get NullPinterExceptin Fr nn empty TreeMap if we are trying t insert null keys we will get NullPinterExceptin There are n restrictins fr null values. Q52. What is Hashtable Hashtable is a legacy Map and can be used t stre bjects as key value pairs.

The underlying data sturucture is Hashtabe Duplicates keys are nt allwed but duplicate values are allwed null insertin is nt pssible fr bth keys and values all methds are synchrnized insertin rder is nt preserved because it is based n hashcde f keys hetergeneus Objects are allwed fr bth keys and values intrduced in 1.0 versin it is legacy class Q53. What is PrirityQueue? It represents a data structure t hld grup f individual bjects prir t prcessing based n sme pririty.it can be natural srting rder and it can be custmized srting rder described by Cmparatr. It is the implementatin class f Queue interface. Insertin rder is nt preserved because here insertin is dne based n sme srting rder Duplicates are nt allwed null insertin is nt pssible even as first element als If we are depending n natural srting rder Objects shuld be hmgeneus vilatin leads t ClassCastExceptin If we are depending n custmized srting rder Objects can be hetergeneus als. Q54. What is Arrays class? It is utility class fr arrays. It defines several utility methds fr arrays like srting an array r searching an element in array present in java.util package Q55. We are planning t d an indexed search in a list f bjects. Which f the tw Java cllectins shuld yu use: ArrayList r LinkedList? ArrayList Q56. Why ArrayList is faster than Vectr? All methds present in the Vectr are synchrnized and hence any methd can be executed by nly ne thread at a time. It slws dwn the executin. But in ArrayList, n methd is synchrnized and hence multiple thread are allwed execute simultaneusly which speed up the executin.