Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| ||||
Core Java - Interview Questions and Answers for 'Table' - 61 question(s) found - Order By Newest | ||||
Advanced level question. Frequently asked in High end product companies. Frequently asked in Google , Cognizant and Deloitte ( Based on 2 feedback ) | ||||
| ||||
Ans. 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references. Example - String str1 = "String1"; String str2 = "String1"; // It doesn't create a new String and rather reuses the string literal from pool // Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too 2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence it's not fit to be cached. 3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   string   string class   immutable  immutability   advanced Asked in 39 Companies expert   frequent | ||||
Try 4 Question(s) Test | ||||
Asked multiple times in Capgemini. | ||||
| ||||
Ans. String is immutable in java and stored in String pool. Once it's created it stays in the pool until unless garbage collected, so even though we are done with password it's available in memory for longer duration and there is no way to avoid it. It's a security risk because anyone having access to memory dump can find the password as clear text. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   immutable  immutability   string pool   garbage collection   advanced Asked in 6 Companies Expert | ||||
Frequently asked in all types of companies especially Indian Services companies. Frequently asked in CTS (Based on 2 feedback) | ||||
| ||||
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements. This bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to and if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashcode   advanced  hashtable Asked in 33 Companies intermediate   frequent | ||||
Try 1 Question(s) Test | ||||
Very frequently asked across all types of companies. | ||||
| ||||
Ans. Hashtable is synchronized whereas HashMap is not.HashMap allows null values whereas Hashtable doesnt allow null values. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   hashtable   hashmap vs hashtable Asked in 14 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment or hacker over internet. Once a String constant is created in Java , it stays in string constant pool until garbage collected and hence stays there much longer than what's needed. Any unauthorized access to string Pool pose a threat of exposing these values. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Security  String pool   string immutable  immutability expert   rare | ||||
| ||||
Ans. Because it doesn't make the change in the existing string but would create a new string by concatenating the new string to previous string. So Original string won't get changed but a new string will be created. That is why when we say str1.concat("Hello"); It means nothing because we haven't specified the reference to the new string and we have no way to access the new concatenated string. Accessing str1 with the above code will still give the original string. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  string  string immutable  immutability  string concat | ||||
| ||||
Ans. We can make a class immutable by 1. Making all methods and variables as private. 2. Setting variables within constructor. Public Class ImmutableClass{ private int member; ImmutableClass(int var){ member=var; } } and then we can initialize the object of the class as ImmutableClass immutableObject = new ImmutableClass(5); Now all members being private , you cant change the state of the object. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   immutable  immutability   immutable  immutability class   technical lead Asked in 5 Companies intermediate   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. HashTable has been deprecated. As an alternative, ConcurrentHashMap has been provided. It uses multiple buckets to store data and hence much better performance than HashTable. Moreover, there is already a raw type HashMap. The only difference between the HashTable and HashMap is that Hashtable is synchronized whereas HashMap is not. Most of the synchronized collections have been deprecated and their raw alternative have been presented as preferred.Synchronization has a cost. Using synchronized collection in places where there is no need of it leads to useless utilization of resources. As these collections are rarely used in a static context or shared among threads, Java might have thought it better to just provide the raw collection and let developers implement synchronization if he feels the need to do so. HashMap is now presented as the default and the preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable. Because of this, Java thought it right to deprecate the use of HashTable.' Synchronization has a cost. Using synchronized collection at a place where there is hardly any need of it would means useless utilization of resources. As these collections are rarely used in static context or shared among threads, Java might have thought it better to just provide the raw collection and let developer implement synchronization if he feels the need to do so. As HashMap has been presented as default and preferred way of using Map with read optimized hashing, and ConcurrentHashMap has been provided for synchronized access which provides better performance than HashTable, Java thought it right to deprecate the use of HashTable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hashtable  synchronized collections  Why synchronized collections have been deprecated  Why HashTable has been deprecated  HashTable vs HashMap expert | ||||
Try 3 Question(s) Test | ||||
| ||||
Ans. Yes , for HashMap. HashMap implements Map interface. HashMap allows one null key and any number of null values. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   hashtable   yes-no Asked in 1 Companies | ||||
Very Frequently asked. Usually asked along with String Class related questions. | ||||
| ||||
Ans. Class using which only immutable (objects that cannot be changed after initialization) objects can be created. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   immutable  immutability   immutable  immutability class   string class   basic interview question Asked in 18 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
Very frequently asked. Usually asked with questions related to String. Frequently asked at CTS / Cognizant | ||||
| ||||
Ans. Object that can't be changed after instantiation. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   immutable  immutability Asked in 27 Companies basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Only declaring variables as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object but the object is still mutable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   final   immutable  immutability   immutable  immutability object | ||||
| ||||
Ans. The properties class is a subclass of Hashtable that can be read from or written to a stream. | ||||
Sample Code for Load Properties using Property Class | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashtable   map   synchronization   synchronized | ||||
| ||||
Ans. Since String is immutable, its hashcode is cached at the time of creation and it doesnt need to be calculated again. This makes it a great candidate for key in a Map and its processing is fast than other HashMap key objects. This is why String is mostly used Object as HashMap keys. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string class   string   immutable  immutability   hashmap   immutable  immutability   hashcode   hash code   advanced Asked in 2 Companies expert   frequent | ||||
| ||||
Ans. These are the tables that are created temporarily and are deleted once the Stored Procedure is complete. For example - we may like to pull some info from a table and then do some operations on that data and then store the output in final output table. We can store the intermediary values in a temp table and once we have final output with us, we can just delete it. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  database   sql   temp tables   tables | ||||
| ||||
Ans. No, We cannot have duplicate keys in HashMap. If we attempt to do so , the previous value for the key is overwritten. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashmap   map   hashtable | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. The external tables feature is a complement to existing SQL Loader functionality. It enables to access data in external sources as if it were in a table in the database. We have used it few times for replicating tables across different database systems. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  external table oracle Asked in 1 Companies   rare | ||||
| ||||
Ans. Strings are immutable in Java and not final. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  is string final  final  string  immutable  immutability  immutability | ||||
| ||||
Ans. Java.util.Map | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   hashtable   map basic   rare | ||||
| ||||
Ans. Java is a portable-language because without any modification we can use Java byte-code in any platform(which supports Java). So this byte-code is portable and we can use in any other major platforms. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   bytecode   jvm   compiler   portable   features of java   basic interview question | ||||
| ||||
Ans. Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   string   hashcode   hash code   string comparison  hashtable Asked in 17 Companies basic   frequent | ||||
| ||||
Ans. First Annotation will set the Entity name as EMPLOYEES and hence will try to map with the same Table name. The second annotation will make the Entity mapped to table EMPLOYEES irrespective of the Entity Name ( which is class name in this case ). Third Annotations will set the different names for Enitity and Table and will explicitly map them. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate annotations   entity annotation   table annotation | ||||
| ||||
Ans. NOT NULL | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  sql   oracle   database   ddl   constraint   table creation | ||||
| ||||
Ans. The following code returns the list of Employee objects having employee name starting with A and Dept Name ( Department , Employee Mapped ). session.createCriteria(Employee.class,"emp") .createAlias("emp.department", "dept",Criteria.INNER_JOIN) .add( Restrictions.like("name", "A%") ) .add(Restrictions.eq("dept.name","Finance") .list(); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hibernate   hibernate criteria   hibernate table mapping | ||||
| ||||
Ans. Stateless objects are the objects without instance fields (instance variables). The class may have compile time constants i.e static final fields.Immutable objects are the objects which have state but the state cannot be changed after initialization. Both are Thread safe. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   stateless objects   immutable  immutability objects   objects   singleton scope | ||||
| ||||
Ans. They can be shared across multiple threads as they are thread safe. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   stateless objects   immutable  immutability objects   objects | ||||
| ||||
Ans. Map | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  hashtable   java   collections | ||||
Ans. HashMap came before HashTable. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  map   hashmap   hashtable   collection   java | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. HashMap | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   collections   map  hashtable Asked in 2 Companies basic   frequent | ||||
| ||||
Ans. tb | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  html   table   html tags | ||||