Showing posts sorted by relevance for query 20-java-arraylist-interview-questions. Sort by date Show all posts
Showing posts sorted by relevance for query 20-java-arraylist-interview-questions. Sort by date Show all posts

Friday, November 1, 2019

Top Fifty Coffee Generics In Addition To Collection Interview Questions

Java Collection as well as Generic are a rattling of import topic for Java Interviews. They likewise nowadays around of the hardest questions to a programmer when it comes to interviews, particularly Generics. It's non slow to start sympathise what a item slice of code doing amongst those query grade as well as other signs as well as thus the pressure level of interviews likewise makes it hard to reply complex usage of Generics.  But, amongst proper training as well as paying attending to both Java Collection as well as Generic, yous tin solve that hurdle. If yous are looking for Java chore but hasn't done good inward the interviews yous convey given thus far thus yous convey come upwardly to the correct place. In this blog, I convey shared a lot of Java interview questions on diverse topics as well as difficulty levels.

There are Java questions for beginners equally good equally practiced programmers. They are theoretical questions based upon Java programming concepts equally good equally coding as well as information construction algorithms questions for programmers, as well as this article is exclusively going to brand that collection fifty-fifty to a greater extent than valuable.

In this article, I am going to part around of the oft asked Java Collection as well as Generic questions from Interviews. These are the questions yous convey often seen on a telephonic circular of Java interview equally good equally on face-to-face interviews. It's useful for both beginners having 2 to iii years of sense equally good equally experienced Java programmers amongst v to half-dozen years of experience.

This listing has a collection of questions which has both slow as well as tough questions inward it but the nearly of import matter is that nearly of the questions convey already been asked on interviews. I am certain yous mightiness convey likewise seen inward your interviews. knowing the answers of these questions volition non exclusively aid yous to crevice your Java interview but likewise sympathise Java Generics as well as Collection topic in-depth, which volition eventually aid yous to write meliorate Java programmers as well as code.

Btw, if yous are novel to Java or desire to solidify your Java cognition thus yous should cheque out a comprehensive course of written report like The Complete Java Masterclass earlier attempting to solve these questions. It volition aid yous immensely yesteryear filling gaps inward your cognition as well as going dorsum as well as forth. It's likewise the nearly up-to-date course of written report as well as covers every novel characteristic introduced betwixt Java 8 to Java 12 releases.





50+ Java Collection as well as Generic Interview Questions

Without wasting whatsoever to a greater extent than of your time, hither is my listing of 50+ Java interview questions on Collection as well as Generics. If yous convey done around operate inward Java thus yous should know the reply to these questions but if yous don't yous tin ever run across the answer. Instead of writing answers here, I convey linked them to relevant shipping thus that yous tin examine to solve the work yesteryear yourself hither as well as if yous demand yous tin acquire an in-depth give-and-take on private shipping to acquire the topic inward depth.


1)  What is the Java Collection Framework as well as How do yous select dissimilar collections? (answer)
Here is the diagram which answers this question:

 Java Collection as well as Generic are a rattling of import topic for Java Interviews Top 50 Java Generics as well as Collection Interview Questions


2)  What is Generics inward Java? (answer)
hint: Java characteristic to ensure type security at compile time.

3)  Which are your favorites classes from Java Collection Framework? (answer)
hint: Collection, List, Set, Map, ArrayList, Vector, LinkedList, HashMap etc

4)  When do yous role Set, List, as well as Map inward Java? (answer)
hint - role laid when yous don't demand duplicates, role List when yous demand fellowship amongst duplicates as well as role Map when yous demand to shop key-value pair.

5)  Which Sorted Collection convey yous used? (answer)
hint - TreeSet is 1 lawsuit of a sorted Collection

6)  How HashSet plant inward Java? (answer)
hint - same similar HashMap, using hashing as well as equals() as well as hashCode() method. HashSet is genuinely backed yesteryear HashMap where keys are elements yous shop inward HashSet as well as values are ever null.

7)  Which ii methods yous should override for an Object to hold upwardly used equally a fundamental inward hash-based Collections? (answer)
hint - equals as well as hashcode

8)  Can yous role HashMap inward a concurrent application? (answer)
hint - Yes, but exclusively if yous are reading from the HashMap as well as its initialized yesteryear a unmarried thread, otherwise no.

9) What is the divergence betwixt HashMap as well as Hashtable inward Java? (answer)
hint - HashMap is fast but non threadsafe, Hashtable is tedious but thread-safe

10) What is the divergence betwixt synchronized as well as concurrent Collection inward Java? (answer)

11) How ConcurrentHashMap plant inward Java? (answer)
partitions map into segments as well as lock them individually instead of locking the whole map.

12) What is PriorityQueue inward Java? (answer)
Influenza A virus subtype H5N1 information construction which ever keeps the highest or lowest chemical factor at the caput thus that yous tin access or take away it inward constant time.

13) What is type-erasure inward Generics?  (answer)
Its a business office of Java compiler which removes all type related information later compilation from Java thus that the generated code is same similar earlier Generics.

14) What is the divergence betwixt ArrayList as well as Vector inward Java?  (answer)

15) What is the divergence betwixt LinkedList as well as ArrayList inward Java?  (answer)

16) What is the divergence betwixt Hashtable as well as ConcurrentHashMap inward Java?  (answer)

17) What is the divergence betwixt LinkedHashSet as well as TreeSet inward Java?  (answer)

18) Difference betwixt extends as well as super inward Java Generics?  (answer)

19) What do yous hateful yesteryear thread-safe collection? Give an lawsuit of 2 thread-safe Collection inward Java?  (answer)

20) What is the human relationship betwixt equals as well as compareTo inward Java?  (answer)

21) What is the default size of ArrayList as well as HashMap inward Java?  (answer)

22) What is the charge factor, capacity, as well as Size of Collection inward Java?  (answer)

23) What is the divergence betwixt Iterator as well as Enumeration inward Java?  (answer)

24) When does ConcurrentModificationException occur?  (answer)

25) What is the divergence betwixt fail-safe as well as fail-fast Iterator inward Java?  (answer)

26) What is CopyOnWriteArrayList inward Java?  (answer)

27) When do yous role BlockingQueue inward Java?  (answer)

28) What is the divergence betwixt the peek() as well as poll() method of Queue interface?  (answer)

29) How do yous detect if an ArrayList contains an Object or not?  (answer)

30) Can nosotros shop Integer inward an ArrayList<Number> inward Java?  (answer)

31) How acquire method of HashMap plant inward Java?  (answer)

32) How do yous form a Collection inward Java?  (answer)

33) What is the divergence betwixt ListIterator as well as Iterator inward Java?  (answer)

34) What is the divergence betwixt HashSet as well as LinkedHashSet inward Java?  (answer)

35) When do yous role EnumSet inward Java?  (answer)

36) List downwards four ways to iterate over Map inward Java?  (answer)

37) How to create read-only Collection inward Java?  (answer)

38) What is IdentityHashMap inward Java?  (answer)

39) Difference betwixt IdentityHashMap as well as WeakHashMap inward Java?  (answer)

40) What is the divergence betwixt Comparator as well as Comparable inward Java?  (answer)

41) What is DeQueue? When do yous role it?  (answer)

42) How to do yous take away an Object from Collection?  (answer)

43) What is the divergence betwixt the remove() method of Collection as well as Iterator inward Java?  (answer)

44) What is the divergence betwixt ArrayList as well as ArrayList<?> inward Java?  (answer)

45) What is the divergence betwixt PriorityQueue as well as TreeSet inward Java?  (answer)

46) How tin I avoid "unchecked cast" warnings?  (answer)

47) What is the "diamond" operator inward Java?  (answer)

48) What is covariant method overriding inward Java?  (answer)

50) What is the divergence betwixt bounded as well as unbounded wildcards inward Java generics?  (answer)


That's all inward this listing of 50 Java Generics as well as Collections Interview Questions.  They are a rattling of import topic from Java Interview signal of view, particularly collections. Make certain yous fix them good earlier going for whatsoever interviews. If yous demand farther training yous tin likewise cheque out these Java Interview books as well as courses:

Resources
Java Interview Guide : 200+ Interview Questions as well as Answers
Spring Framework Interview Guide - 200+ Questions & Answers
questions)
  • Top 10 Spring Framework Interview Questions amongst Answers (see here)
  • 50+ Data Structure as well as Algorithms Problems from Interviews (questions)
  • 10 Great Hibernate Interview Questions for Java EE developers (see here)
  • 10 Great XML Interview Questions for Java Programmers (read here)
  • 20 Great Java Design Pattern Questions asked on Interviews (see here)
  • 10 pop Struts Interview Questions for Java developers (list)
  • 20 Tibco Rendezvous as well as European Monetary System Interview Questions (read more)
  • 10 oft asked Servlet Interview Questions amongst Answers (see here)
  • 20 jQuery Interview Questions for Java Web Developers (list)
  • 10 Great Oracle Interview Questions for Java developers (see here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 12 Good RESTful Web Services Questions from Interviews (read here)
  • Top 10 EJB Interview Questions as well as Answers (see here)
  • Top 10 JMS as well as MQ Series Interview Questions as well as Answers (list)
  • Review these 50 Java questions earlier interviews (review)
  • 10 Great JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO as well as Networking Interview Questions amongst Answers (see here)
  • Top 10 XSLT Interview Questions amongst Answers (read more)
  • 15 Data Structure as well as Algorithm Questions from Java Interviews (read here)
  • Top 10 Trick Java Interview Questions as well as Answers (see here)
  • Top forty Core Java Phone Interview Questions amongst Answers (list)

  • Thanks for reading this article thus far. If yous similar these Java Generics as well as Collections interview questions thus delight part amongst your friends as well as colleagues. If yous convey whatsoever questions or feedback thus delight drib a note.

    Thursday, October 31, 2019

    Top 21 Coffee Hashmap Interview Questions As Well As Answers

    The java.util.HashMap is 1 of the workhorses of JDK. Along alongside ArrayList, it is 1 of the most used classes from Java's collection framework. There is hardly a real-world Java project, where I haven't seen the usage of HashMap. It is an implementation of hash tabular array information construction together with it's non a surprise that HashMap is so useful, as individual has rightly said, "if you lot could direct maintain only 1 information structure, arrive a hash table". The hash tabular array information construction allows you lot to search for a value inwards O(1) fourth dimension if you lot direct maintain key. In Java, at that spot are several implementations of hash tabular array information construction exists similar Hashtable, ConcurrentHashMap, LinkedHashMap, etc but HashMap is your full general role map.

    Though, if you lot direct maintain a special demand you lot tin usage other hash tabular array implementations available inwards JDK. For example, if you lot desire to save the lodge of mapping together with so you lot tin consider using LinkedHashMap. If you lot desire to croak on mappings sorted together with so you lot tin usage TreeMap, which is a sorted map implementation.

    Similarly, if you lot demand a hash tabular array implementation which is thread-safe together with tin hold upwards used inwards a concurrent application without compromising the Scalability together with so consider using a ConcurrentHashMap from JDK 5.

    Btw, if you lot are novel to Java basis together with JDK API inwards particular, I advise you lot to offset croak through a comprehensive Java course of didactics similar The Complete Java Masterclass on Udemy. That volition non exclusively aid you lot to produce good on interviews but besides aid you lot to sympathise the fundamentals better.





    Java HashMap Interview Questions

    Here is my listing of HashMap questions from Java Interviews. This listing includes questions based on the internal implementation of HashMap, the Map API, how you lot usage HashMap together with mutual best practices spell using HashMap inwards a Java application.


    1. How does put() method of HashMap plant inwards Java? (answer)
    The put() method of HashMap plant inwards the regulation of hashing. It is responsible for storing an object into the backend array. The hashcode() method is used inwards conjunction alongside a hash portion to respect the right location for the object into the bucket. If a collision occurs together with so the entry object which contains both key together with value is added to a linked listing and that linked listing is stored into the bucket location.


    2. What is the requirement for an object to hold upwards used as key or value inwards HashMap? (answer)
    The key or value object must implement equals() together with hashcode() method. The hash code is used when you lot insert the key object into the map spell equals are used when you lot endeavor to shout upwards a value from the map.


    3. What volition direct house if you lot endeavor to shop a key which is already nowadays inwards HashMap? (answer)
    If you lot shop an existing key inwards the HashMap together with so it volition override the one-time value alongside the novel value together with put() volition render the one-time value. There volition non hold upwards whatsoever exception or error.


    4. Can you lot shop a cipher key inwards Java HashMap? (answer)
    Yes, HashMap allows 1 cipher key which is stored at the offset location of bucket array e.g. bucket[0] = value. The HashMap doesn't telephone phone hashCode() on cipher key because it volition throw NullPointerException, thence when a user telephone phone get() method alongside cipher together with so the value of the offset index is returned.

    5. Can you lot shop a cipher value within HashMap inwards Java? (answer)
    Yes, HashMap besides allows cipher value, you lot tin shop as many cipher values as you lot desire as shown inwards the hashmap illustration post inwards this blog.


    6. How does HashMap direct maintain collisions inwards Java? (answer)
    The java.util.HashMap uses chaining to direct maintain collisions, which agency novel entries, an object which contains both key together with values, are stored inwards a linked listing along alongside the existing value together with and so that linked listing is stored inwards the bucket location.

    In the worst case, where all key has the same hashcode, your hash tabular array volition hold upwards turned into a linked listing together with searching a value volition direct maintain O(n) fourth dimension as opposed to O(1) time.

    If you lot desire to larn to a greater extent than most hash tabular array information structure, I advise you lot consult a practiced information construction together with algorithm course of didactics like Data Structures together with Algorithms: Deep Dive Using Java on Udemy, which non exclusively embrace basic information construction similar array, linked list, binary tree, together with hash tabular array but besides advanced concepts similar O(n) sorting algorithms, Radix sort, Counting sort, etc.

     it is 1 of the most used classes from Java Top 21 Java HashMap Interview Questions together with Answers



    7. Which information construction HashMap represents? (answer)
    The HashMap is an implementation of hash tabular array information construction which is idle for mapping 1 value to other similar id to mention as you lot tin search for value inwards O(1) fourth dimension if you lot direct maintain the key.


    8. Which information construction is used to implement HashMap inwards Java? (answer)
    Even though HashMap represents a hash table, it is internally implemented past times using an array together with linked listing information construction inwards JDK.  The array information construction is used as a bucket spell a linked list is used to shop all mappings which province inwards the same bucket. From Java 8 onwards, the linked listing is dynamically replaced past times binary search tree, 1 time a number of elements inwards the linked listing cross a surely threshold to improve performance.


    9. Can you lot shop a duplicate key inwards HashMap? (answer)
    No, you lot cannot insert duplicate keys inwards HashMap, it doesn't allow duplicate keys. If you lot endeavor to insert an existing key alongside novel or same value together with so it volition override the one-time value but size of HashMap volition non modify i.e. it volition stay the same. This is 1 of the argue when you lot acquire all keys from the HashMap past times calling keySet() it returns a Set, non a Collection because Set doesn't allow duplicates.


    10. Can you lot shop the duplicate value inwards Java HashMap? (answer)
    Yes, you lot tin set duplicate values inwards HashMap of Java. It allows duplicate values, that's why when you lot shout upwards all values from the Hashmap past times calling values() method it returns a Collection together with non Set. Worth noting is that it doesn't render List because HashMap doesn't supply whatsoever ordering guarantee for key or value.

    If you lot desire to explore, you lot tin besides see answer)
    No, HashMap is non thread-safe inwards Java. You should non portion a HashMap alongside multiple threads if 1 or to a greater extent than thread is modifying the HashMap e.g. inserting or removing a map. Though, you lot tin easily portion a read-only HashMap.


    12. What volition direct house if you lot usage HashMap inwards a multithreaded Java application? (answer)
    If you lot usage HashMap inwards a multithreaded environs inwards such a way that multiple threads structurally modify the map e.g. add, take away or modify mapping together with so the internal information construction of HashMap may acquire corrupt similar or so links may croak missing, or so may indicate to wrong entries together with the map itself may croak completely useless. Hence, it is advised non to usage HashMap inwards the concurrent application, instead, you lot should usage a thread-safe map e.g. ConcurrentHashMap or Hashtable.


    13. What are different ways to iterate over HashMap inwards Java? (answer)
    Here are or so of the ways to iterate over HashMap inwards Java:
    past times using keySet together with iterator
    past times using entrySet together with iterator
    past times using entrySet together with enhanced for loop
    past times using keySet together with get() method

    You tin come across this article for an illustration of each of these ways to traverse a HashMap inwards Java.


    14. How produce you lot take away a mapping spell iterating over HashMap inwards Java? (answer)
    Even though HashMap provides remove() method to take away a key together with a key/value pair, you lot cannot usage them to take away a mapping spell traversing a HashMap, instead, you lot demand to usage the Iterator's take away method to take away a mapping as shown inwards the next example:

    Iterator itr = map.entrySet().iterator();  while(itr.hasNext()){   Map.Entry electrical flow = itr.next();    if(current.getKey().equals("matching"){      itr.remove(); // this volition take away the electrical flow entry.   } }

    You tin come across that nosotros direct maintain used Iterator.remove() method to take away the electrical flow entry spell traversing the map. See this article to larn to a greater extent than most it.


    15. In which lodge mappings are stored inwards HashMap? (answer)
    Random lodge because HashMap doesn't supply whatsoever ordering guarantee for keys, values, or entries. When you lot iterate over a HashMap, you lot may acquire the different lodge every fourth dimension you lot iterate over it.





    16. Can you lot form HashMap inwards Java? (answer)
    No, you lot cannot form a HashMap because dissimilar List it is non an ordered collection. Albeit, you lot tin form contents of HashMap past times keys, values or past times entries past times sorting together with and so storing the resultant into an ordered map similar LinkedHashMap or a sorted map e.g. TreeMap.


    17. What is the charge factor inwards HashMap? (answer)
    Influenza A virus subtype H5N1 charge factor is a number which controls the resizing of HashMap when a number of elements inwards the HashMap cross the charge factor e.g. if the charge factor is 0.75 together with when becoming to a greater extent than than 75% amount together with so resizing trigger which involves array copy.


    18. How does resizing happens inwards HashMap? (answer)
    The resizing happens when the map becomes amount or when the size of the map crosses the charge factor. For example, if the charge factor is 0.75 together with and so croak to a greater extent than than 75% amount together with so resizing trigger which involves array copy. First, the size of the bucket is doubled together with and so one-time entries are copied into a novel bucket.


    19. How many entries you lot tin shop inwards HashMap? What is the maximum limit? (answer)
    There is no maximum bound for HashMap, you lot tin shop as many entries as you lot desire because when you lot run out of the bucket, entries volition hold upwards added to a linked listing which tin back upwards an infinite number of entries, of course of didactics until you lot exhaust all the retentiveness you lot have.

    Btw, the size() method of HashMap render an int, which has a limit, 1 time a number of entries cross the limit, size() volition overflow together with if your computer program relies on that together with so it volition break.

    This number has been addressed inwards JDK 8 past times introducing a novel method called mappingCount() which returns a long value. So, you lot should usage mappingCount() for large maps. See Java SE 8 for Really Impatient to larn to a greater extent than most novel methods introduced inwards existing interfaces inwards JDK 8.

     it is 1 of the most used classes from Java Top 21 Java HashMap Interview Questions together with Answers


    21. What is the divergence betwixt capacity together with size of HashMap inwards Java? (answer)
    The capacity denotes how many entries HashMap tin shop together with size denotes how many mappings or key/value duo is currently present.


    21. What volition direct house if ii different keys of HashMap render same hashcode()? (answer)
    If ii keys of HashMap render same hash code together with so they volition destination upwards inwards the same bucket, thence collision volition occur. They volition hold upwards stored inwards a linked listing together.


    That's all most or so of the of import Java HashMap interview questions. I direct maintain tried to reply them as well, but if you lot disagree alongside an reply together with so experience complimentary to comment. Since HashMap is a rattling of import shape inwards Java together with as of import from Java interview indicate of view, it pays to sympathise this shape together with its implementation inwards deep.

    Further Learning
    The Complete Java Masterclass
    list)
  • 19 Java Overloading together with Overriding Interview Questions (list)
  • 15 Java NIO together with Networking Interview Questions alongside Answers (see here)
  • 21 Java ArrayList Interview Questions alongside Answers (list)
  • 20+ String Coding Problems from Interviews (questions)
  • 21 Java Final modifier Interview Questions (list)
  • 21 Java Inheritance Interview Questions alongside answers (list)
  • 75 Coding Interview Questions for Programmers (questions
  • 10 Date, Time, together with Calendar based Interview Questions alongside answers (list)
  • 5 main() method interview questions (list)
  • 15 SQL together with UNIX questions from Java Interviews (list)
  • 22 array concept interview questions from Java (list)
  • 15 Java Enum based Interview Questions (list)
  • 50+ Data Structure together with Algorithms Interview Questions (questions)

  • These questions volition non exclusively aid you lot to sympathise HashMap amend but besides encourage you lot to respect out to a greater extent than most HashMap, it's Java implementation together with hash tabular array information construction inwards general. If you lot direct maintain whatsoever other HashMap based Java questions, which was asked to you lot inwards an interview, experience complimentary to portion alongside us.

    P. S. - If you lot are preparing for Java Interviews together with looking for or so interesting questions for do together with so you lot tin besides depository fiscal establishment check out this Java Interview Guide: 200+ Interview Questions together with Answers course, which contains to a greater extent than than 200+ real-world questions from Java interviews together with their explanation.

    Sunday, February 27, 2011

    Top 25 Coffee Date, Time, As Well As Calendar Interview Questions Answers

    The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but many interviewers don't inquire plenty questions on this topic. Most of the questions are based on either Java Collection framework like  HashMap, ConcurrentHashMap, or ArrayList or on multi-threading concepts similar volatile, synchronized together with atomic variables. This is non skillful together with I mean value many interviewers bring realized that a skillful agreement of appointment together with fourth dimension API is also of import for a skillful Java developer. That's the mind argue for an increasing number of date, fourth dimension together with calendar based Java interview questions inwards recent time, peculiarly inwards concluding a twain of years.

    Since Java evolution task marketplace is really skillful at this 2d together with at that spot are a lot of jobs open, peculiarly inwards investment banking domain inwards the Asia Pacific, its likely the best fourth dimension to alter your job, especially if y'all are stuck alongside no learning, no salary growth together with non a pregnant bonus or incentives inwards concluding a twain of years.

    Apart from stability, growth is really of import because if y'all don't movement frontward y'all volition hold out stuck together with eventually movement backward, thence changing task is every bit of import every bit sticking to a task which is working for you.

    Btw, if y'all are novel to Java together with don't know much nearly Date together with Time classes together with so I advise y'all to showtime become through a comprehensive course of teaching like The Complete Java Masterclass on Udemy. It's also late updated to encompass the latest Java version together with non really expensive. You tin acquire it inwards precisely $10 inwards several Udemy flash sales which happens all approximately the year.




    Top 10 Date, Time together with Calendar Interview Questions together with Answers

    I bring been sharing interview questions on diverse Java topics from concluding a twain of years similar multithreading, collections, design patterns, coding problems, etc, but 1 topic which I haven't touched yet was appointment together with fourth dimension together with that's why I idea to portion some of the interesting appointment together with time-based questions from recent Java interviews. In this article, y'all volition uncovering those.


    1. Does SimpleDateFormat hold out prophylactic to usage inwards the multithreaded program? (answer)
    No, unfortunately, DateFormat together with all its implementations including SimpleDateFormat is non thread-safe, hence, should non hold out used inwards the multi-threaded plan until external thread-safety measures are applied e.g. confining SimpleDateFormat object into a ThreadLocal variable. I

    f y'all don't exercise that, y'all volition acquire an wrong final result piece parsing or formatting dates inwards Java. Though, for all practical appointment fourth dimension purpose, I highly recommend the joda-time library.


    2. How exercise y'all format a appointment inwards Java? e.g. inwards the ddMMyyyy format? (answer)
    You tin either usage SimpleDateFormat shape or joda-time library to format the appointment inwards Java. DateFormat shape allows y'all to format appointment on many pop formats. Please run across the reply for code samples to format the Date into dissimilar formats e.g. dd-MM-yyyy or ddMMyyyy.




    3. Can y'all say some deviation betwixt one-time together with novel Date Time API of Java 8?
    Even though novel Date together with Time API are a completely novel API, y'all tin deduce the next deviation betwixt them:
    1) In one-time API, Date was mutable but inwards Java 8 all appointment together with fourth dimension classes e.g. LocalDate, LocalTime or LocalDateTime are Immutable.
    2) In one-time API, SimpleDateFormat was non thread-safe, but inwards Java 8 Formatter are thread-safe.
    3) In one-time Date together with Calendar API, Year starts alongside 1900, Months starts alongside 0, which is corrected inwards Java 8, hither numbers brand to a greater extent than sense.
    4) Old Date together with Calendar API has precisely 1 shape Date to correspond appointment together with time, but Java 8 has separated classes for Date together with Time e.g. LocalDate together with LocalTime




    4. Which appointment the next Date illustration represent?
    Date aDate = novel Date(2015, 12, 25, 20, 40);

    This is a actually tricky query for whatever casual Java developers who bring non written appointment together with time-based code for himself because this volition non correspond the Christmas solar daytime or 25th Dec 2015. This code has got ii bugs, first, the yr starts from 1900 to, to correspond 2015, y'all demand to transcend 115 i.e. 2015-1900.

    The 2d number alongside this code is that calendar month is non correct. The calendar month starts from 0, so Dec would xi non 12, interesting right? That's why y'all should novel Date together with Time API from Java 8, which solves all these issues. Again, y'all tin check The Complete Java Masterclass to acquire to a greater extent than nearly novel Date together with Time API.

     The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers



    5. How exercise y'all re-create a Date inwards Java? (answer)
    It's a uncomplicated query to answer. The Date shape implements the clone() method, so precisely telephone telephone date.clone() to exercise a re-create of the Date object inwards Java.


    6. What is the human relationship betwixt java.sql.Date together with java.util.Date? (answer)
    This is 1 of the really interesting questions every bit non many developers know this fine but obvious detail. The java.sql.Date extends java.util.Date together with suppress all time-related methods to deed every bit precisely a appointment class. This is inwards straight violation of the Liskov commutation principle.


    7. Can y'all format Calendar inwards Java? (answer)
    No, Calendar cannot hold out formatted inwards Java. You tin solely format dates.


    8. How exercise y'all convert a Calendar to Date together with vice-versa? (answer)
    Well, y'all tin usage the Calendar.setTime() together with Calendar.getTime() method to convert the Calendar to Date together with vice-versa.


    9. What is the equivalent of Date shape inwards Java 8? (answer)
    The Instance shape is the equivalent to java.util.Date inwards Java 8 because it also represents a millisecond value or an illustration inwards the timescale. Java 8 has also added conversion method e.g. toInstant() together with fromDate() to convert illustration to java.util.Date together with vice-versa. See Java SE 8 for Really Impatient By Cay S. Horstmann for to a greater extent than details.

     The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers



    10. How exercise y'all convert a millisecond to Date inwards Java? (answer)
    One of the simplest query to answer, y'all tin telephone telephone the getTime() method which returns the millisecond from the Epoch.


    12. How exercise y'all acquire a calendar month together with yr from a Date object inwards Java? (answer)
    You tin convert a Date to Calendar together with and so usage its get() method alongside diverse fields to acquire the month, year, solar daytime of the calendar week together with other appointment particulars e.g.

    int solar daytime = calendar.get(Calendar.DATE); // returns the day
    int calendar month = calendar.get(Calendar.MONTH) + 1; // calendar month starts from 0
    int yr = calendar.get(Calendar.YEAR) + 1900; // yr starts from 1900


    13. How exercise y'all convert XMLGregorianCalendar to Date inwards Java? (answer)
    I bring discussed this employment before, delight banking concern jibe the link for the detailed answer.


    14. How exercise y'all acquire the electrical flow fourth dimension inwards GMT inwards Java? (answer)
    The Java appointment is independent of fourth dimension together with display fourth dimension inwards a electrical flow fourth dimension zone solely if y'all impress them. So, inwards gild to convert the electrical flow fourth dimension inwards GMT, y'all demand to usage Calendar alongside fourth dimension zone every bit shown inwards the given answer.


    15. Is Date shape hold out Immutable inwards Java?
    No, Date is non immutable. You tin alter it's internal to correspond a dissimilar date. This is the argue that when y'all bring a fellow member correspond Date, y'all must hold out careful non to leak its reference exterior using getDate() method, because together with so the customer tin modify the dry soil of the Immutable object, instead a re-create should hold out returned to the customer every bit suggested in Effective Java book yesteryear none other than Joshua Bloch, writer of several primal classes of JDK API.

     The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers



    16. How exercise y'all add together together with subtract a day, calendar month together with yr inwards a Date object? (answer)
    This is 1 of the mutual solar daytime to solar daytime task of a Java developer, y'all tin usage the code shared inwards the reply for adding or subtracting a solar daytime or calendar month from the Date object.


    17. How exercise y'all compare ii dates inwards Java to banking concern jibe if they are equal? (answer)
    This is 1 of the easier questions y'all volition run across inwards damage of science checking on Date classes. The java.util.Date shape implements the equals() method, which returns truthful if both Dates is same together with imitation otherwise.



    18. How exercise y'all uncovering if 1 appointment comes earlier or afterward some other appointment inwards Java? (answer)
    This is the follow-up query of the previous question. The interviewer farther checks the candidate's appointment comparing science yesteryear bespeak this question. The reply is simple, the java.util.Date shape provides before() together with after() method which returns truthful together with imitation if the appointment on which method is called comes earlier or afterward the other appointment passed every bit a method argument.


    19. How exercise y'all convert java.util.Date to java.sql.Date inwards Java JDBC? (answer)
    It's the follow-up query of sixth question. Since java.sql.Date is a subclass of java.util.Date y'all tin only acquire the fourth dimension inwards millisecond together with passed it to SQL appointment every bit shown below:

    Date similar a shot = novel Date();
    java.sql.Date sqlDate = novel java.sql.Date(now.getTime());

    Simple together with tardily right? but at that spot are some interesting follow-up questions when y'all write this code, I advise y'all banking concern jibe the reply link for to a greater extent than detailed discussion, where I bring answered those follow-up questions every bit well. You tin farther see  The Date together with Time API is a really of import 1 for solar daytime to solar daytime Java evolution locomote but ma Top 25 Java Date, Time, together with Calendar Interview Questions Answers


    Btw, y'all would demand a answer)
    This is similar to 1 of the previous questions where nosotros demand to acquire the electrical flow fourth dimension inwards GMT


    21. How exercise y'all exhibit timezone inwards formatted appointment inwards Java? (answer)
    run across the reply link for a code example


    22. What is the deviation betwixt java.util.Date together with java.sql.Date inwards Java? (answer)
    There are much deviation betwixt them but the most of import 1 is that java.sql.Date is from JDBC packet together with it acts every bit converted betwixt Date together with Time information types inwards database together with Date inwards Java.


    23. How exercise y'all calculate the deviation betwixt ii dates inwards Java? (program)
    There are multiple ways to calculate the deviation betwixt ii dates inwards Java e.g. y'all tin acquire the long millisecond values from ii dates together with acquire the deviation but that's non really valuable, y'all by together with large demand the deviation inwards days or hours, etc. See the plan to acquire to a greater extent than nearly those differences.


    24 How exercise y'all convert a String(YYYYMMDD) to appointment inwards Java? (answer)
    You tin usage SimpleDateFormat prior to JDK 8 together with DateTimeFormatter along alongside format together with parse method to convert a String to appointment inwards Java.

    That's all nearly the date, time, together with Calendar based Java Interview Questions. It's really of import for a Java developer to bring a company agreement of Date together with Time API of Java, both one-time together with novel because y'all volition non uncovering Java 8 inwards every projection y'all work. You even so demand to know how to locomote alongside one-time Date together with Calendar API piece maintaining the legacy projection for a twain of to a greater extent than years.

    Further Learning
    Complete Java Masterclass
    see here)
  • 15 Data Structure together with Algorithm Questions from Java Interviews (read here)
  • 20 Great Java Design Pattern Questions asked on Interviews (see here)
  • 10 often asked Servlet Interview Questions alongside Answers (see here)
  • Top 10 JSP Questions  from J2EE Interviews (read here)
  • 12 Good RESTful Web Services Questions from Interviews (read here)
  • 10 Great Hibernate Interview Questions for Java EE Developer (see here)
  • 10 Great JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO together with Networking Interview Questions alongside Answers (see here)
  • Top 10 Trick Java Interview Questions together with Answers (see here)
  • Top twoscore Core Java Phone Interview Questions alongside answers (list)
  • 50+ Data Structure together with Algorithm Interview Questions (data structure)
  • 20+ String based Coding Problems from Interviews (questions)


  • Thanks for reading this article so far. If y'all similar these questions together with so delight portion alongside your friends together with colleagues too. If y'all bring whatever questions or feedback together with so delight drib a note.

    P. S. - If y'all are looking to fill upwards gaps inwards your Java noesis or desire to acquire Java from scratch, hither are some useful free online Java courses to await out.

    Monday, March 30, 2020

    Top Ten Servlet Jsp Interview Questions For Coffee J2ee Programmer - Faq

    Servlets together with JSP Interview Questions are pith of whatever J2EE Interview. Its expected from candidate to convey adept cognition of Servlet, JSP, EJB , Struts or Spring inwards whatever J2EE interview. Consequently Servlets together with JSP Interview Questions are real mutual inwards whatever J2EE Interviews along amongst to a greater extent than or less questions from pith Java, Some interview Questions from Spring together with Some EJB interview questions. Since J2EE is primary platform for edifice company together with spider web application using Java programming language, its of import to fix good for J2EE interview, peculiarly If you lot are inwards application evolution space. Servlet together with JSP forms spider web layer of J2EE framework where Java Server pages is primary persuasion technology together with Servlets are primary Controller constituent of criterion MVC architecture. In this article nosotros volition meet couplet of nearly mutual or oftentimes asked JSP together with Servlet Interview questions together with answers, which tin assistance you lot on your J2EE interview grooming together with agreement to a greater extent than or less key concept of Java spider web applications.


    JSP Servlet Interview Questions Answers
     together with JSP Interview Questions are pith of whatever J Top 10 Servlet JSP Interview Questions for Java J2EE programmer - FAQHere is my listing of oftentimes asked JSP Servlet Interview questions to whatever Java programmer. Most of these Servlet JSP questions has appeared inwards diverse score of J2EE interviews including 2 to iii together with 2 to four years sense level. None of these questions require special inquiry together with neither of them are tricky questions, they all are focused on fundamentals which is key to clear whatever interview.



    Question 1: What is JSESSIONID inwards Java? When does JSESSIONID gets created ?
    One of my favourite Servlet JSP Interview inquiry for 2 to four years sense programmers on spider web development. JSESSION id is a cookie which is used to handle session inwards Java spider web application. JSESSIONID is created past times Web Container whenever a novel session is created. See What is JSESSIONID inwards Servlet JSP for to a greater extent than details.

    Question 2: What is departure betwixt include activity together with include directive inwards JSP?
    Another real pop JSP Interview questions, to a greater extent than often than non asked to 2 to iii years experienced J2EE programmer. There are couplet of differences, nearly of import of them is that include activity is request  time inclusion piece include directive is translation fourth dimension inclusion of to a greater extent than or less other resources e.g. JSP or html pages. This questions is likewise asked every bit departure betwixt file include together with page include. See Include activity vs Include directive for to a greater extent than differences.

    Question 3: How create you lot define application broad mistake page inwards JSP?
    Almost inwards every Servlet JSP interview you lot volition meet inquiry from mistake handling. You tin define 2 kinds of mistake pages inwards Java spider web application, i is using tag <error-page> inwards web.xml together with other is past times using mistake page JSP which uses isErrorpage to declare that this jsp page tin survive used every bit mistake page. Other JSP uses that page past times using attribute errorpage="error.jsp". Whenever you lot larn an unhandled exception inwards JSP, asking volition survive routed to mistake page. See How to utilisation mistake page inwards JSP for detailed reply of this question.

    Question 4: Difference betwixt sendredirect together with forrad inwards Servlet ?
    One of the classical Interview Question from Servlet together with JSP. This inquiry is every bit sometime every bit Vector vs ArrayList inwards pith Java. Anyway meet difference betwixt sendredirect together with forward to reply this Servlet Interview question.

    Question 5: How create take variable using <c:set> tag from JSTL ?
    This is i of the tricky Servlet JSP question. Many people assumes that <c:set> tin alone add together or laid variables inwards a particular range only you lot tin likewise take whatever variable from whatever range using JSTL <c:set> tag. See How to utilisation <c:set> JSTL tag inwards JSP for exact agency to take whatever variable from whatever range inwards JSP page.

    Question 6: What is departure betwixt Web Server together with Application Server ?
    This is rather unproblematic Servlet JSP inquiry to answer. If you lot convey used EJB together with then you lot should know that , Web Server doesn't comprise EJB container together with EJB tin non survive deployed on that. Application Server is used to deploy together with run EJB inwards J2EE environment. See 5 departure betwixt Application together with Web Server to meet to a greater extent than differences.

    Question 7: What is departure betwixt URL Encoding together with URL rewriting ?
    URL Encoding together with URL rewriting is full general spider web concept irrespective of Java programming language. URL Encoding refers to encoding URL e.g. replacing infinite amongst %20, you lot tin meet this when browser sends asking to Server. On the other mitt URL Rewriting is agency to handle Session inwards spider web application. See URL Encoding vs URL Rewriting for to a greater extent than differences.

    Question 8: How create you lot larn ServletContext reference within Servlet ?
    ServletContext is real of import object inwards Java Web application. ServletContext object is i per spider web application together with serves every bit application range together with utilisation to shop mutual config together with things which doesn't alter on per session. Its slowly to larn reference of ServletContext inwards jsp using application implicit variable only inwards Servlet is non available inwards HttpServletRequest until version 3.0. You demand HttpSession object to remember ServletContext inwards whatever Servlet. Influenza A virus subtype H5N1 adept follow-up questions is How create you lot larn ServletContext inwards Struts Action shape or Spring Controller classes. See How to remember ServletContext inwards Servlet, Spring together with Struts for to a greater extent than details.

    Question 9: What is departure betwixt ServletContext together with ServletConfig inwards Java ?
    One of those classical Servlet Interview Questions which you lot can't afford to miss. Again ServletContext is used to supply application broad configure piece ServletConfig is used to configure together with supply initialization parameter to i Servlet. See ServletContext vs ServletConfig for to a greater extent than differences.

    Question 10: Which opened upwards origin tag library convey you lot used ?
    This is an interesting Servlet JSP questions together with gives an chance to exhibit how many tag library you lot are familiar amongst together with which ones convey you lot used. Most J2EE programmer reply this inquiry amongst maxim JSTL pith tag library, Struts tag library , Spring tag library or display tag, which is quite pop tag library to display tabular information together with provides lot of characteristic out of box e.g. paging, sorting together with export functionality.

    Question 11: What is departure betwixt GET together with POST method inwards HTTP protocol?
    Another classical spider web interview question, non specific to Servlet or JSP only real of import inwards context of spider web evolution which is based on HTTP protocol. There several differences betwixt GET together with POST method including length of information required to Send to Server. GET is less secure together with tin alone post express information thus non useful to transfer sensitive information. See GET vs POST HTTP method for to a greater extent than differences.

    Question 12: What does load-on-start-up chemical element inwards web.xml do?
    One of the tough Servlet JSP Interview inquiry peculiarly to 2 years sense guy, who may non survive exposed to all tags of web.xml. load-on-startup is related to loading of Servlet. See What is load-on-startup tag inwards web.xml for to a greater extent than details.

    These were to a greater extent than or less Servlet together with JSP Interview questions together with reply you lot tin human face for quick revision purpose. If you lot convey faced whatever interesting Servlet JSP inquiry or if you lot are looking reply for whatever Servlet JSP inquiry than delight share.

    Further Learning
    Top 10 Spring MVC Interview question

    Thursday, October 31, 2019

    Difference Betwixt A Listing Together With Arraylist Reference Variable Inwards Java?

    Someone who is but starting amongst Java programming linguistic communication ofttimes has dubiety almost how nosotros are storing an ArrayList object inwards List variable, what is the deviation betwixt List in addition to ArrayList? Or why non but salvage the ArrayList object inwards ArrayList variable but similar nosotros produce for String, int, in addition to other information types. Well, the nous deviation betwixt List in addition to ArrayList is that List is an interface piece ArrayList is a class. Most importantly, it implements the List interface, which likewise agency that ArrayList is a subtype of List interface. In Java or whatever object-oriented language, supertype of a variable tin flame shop an object of subtype.

    This is known every bit Polymorphism because whatever virtual method volition live on executed from subclass only, fifty-fifty though they were called from the supertype. This is the beginning, similar a shot let's meet those 2 questions every bit well.

    Anyway, If you lot are non familiar amongst Inheritance in addition to other object-oriented programming concepts inwards Java, I propose you lot to initiative off acquire through a comprehensive course of education like The Complete Java Masterclass, which is the most up-to-date online course of education to acquire Java. Always updated for latest Java version similar Java 12. 



    Why shop ArrayList object on List variable?

    You powerfulness receive got seen something similar this:

    List<Movie> listOfMovies = new ArrayList<Movie>()

    Here nosotros are using a List every bit a type of variable to shop an object of ArrayList class, created using new() operator. This is known every bit programming for the interfaces. In fact, everywhere you lot involve to declare a reference variable, you lot should ever role the supertype, similar Map for passing HashMap, Set for giving HashSet in addition to List for passing ArrayList, LinkedList or Vector.

    You should role interface every bit type on the supply type of method, type of arguments, etc. every bit shown below? Now the big query comes, Why should you lot produce that?

    The reply is to accept payoff of Polymorphism. If you lot role interface than inwards futurity if the novel implementation is shipped, thence you lot are non required to alter your program.

    For example, an application written using List volition run every bit expected whether you lot transcend a LinkedList, Vector, or ArrayList because they all implement List interface, they obey the contract exposed yesteryear List interface.

    The solely deviation comes inwards performance, which is genuinely ane of the drivers for change. In short, if you lot programme using interface, tomorrow if a amend implementation of your interface is available thence you lot tin flame switch to that without making whatever farther alter on the client-side (part of the programme which uses that interface).


    Similarly, you lot should role interface type on method arguments:

    public void sort(List<? extends Comparable> input){        // logic to form the listing   }


    in addition to role interface type on the supply type of methods:

    public List<Employee> getEmployees(int departmentId){        // logic to supply employees for a given department }



    If you lot shop ArrayList's object into a reference type of ArrayList, every bit shown below, thence your code volition non run if you lot transcend a LinkedList, because ArrayList IS NOT a LinkedList.

    public List<Movies> getMovies(LinkedList<String> actors){        // this code volition non run if you lot transcend ArrayList }
    but next code volition work, fifty-fifty if you lot transcend ArrayList, Vector, CopyOnWriteArrayList or LinkedList, because it expects a List, which is an interface:

    public List<Movies> getMovies(List<String> actors){        // this code volition run if you lot transcend ArrayList, Vector etc }


    Your programme is pretty much hardcoded, it lacks the flexibility offered yesteryear Polymorphism in addition to Inheritance. This reply is likewise applicable to questions similar the deviation betwixt Map in addition to HashMap or Set in addition to HashSet because ultimately they are the same question, the deviation betwixt an interface in addition to their implementation.

    You must likewise follow SOLID Design Principles to write a amend programme inwards object-oriented programming languages similar Java or C++.

    Here are 10 object-oriented principles Every Java Developer should know

    tutorial)
  • How to form an ArrayList inwards ascending in addition to descending lodge inwards Java? (tutorial)
  • Difference betwixt ArrayList in addition to HashSet inwards Java? (answer)
  • What is the deviation betwixt TreeMap in addition to TreeSet inwards Java? (answer)
  • 10 Free courses to acquire Java in-depth (courses)
  • The deviation betwixt HashMap in addition to ConcurrentHashMap inwards Java? (answer)
  • 10 courses to acquire Data Structure in-depth (courses)
  • The deviation betwixt HashMap in addition to LinkedHashMap inwards Java? (answer)
  • 20+ basic algorithms interview questions for programmers (questions)
  • The deviation betwixt Hashtable in addition to HashMap inwards Java? (answer)
  • Top 10 courses to acquire Python inwards 2019 (courses)
  • The deviation betwixt HashSet in addition to TreeSet inwards Java? (answer)
  • 50+ Core Java Interview Questions in addition to Answers (questions)
  • The deviation betwixt ArrayList in addition to LinkedList inwards Java? (answer)
  • Top five Courses to acquire Spring Framework in-depth (courses)
  • The deviation betwixt Vector in addition to ArrayList inwards Java? (answer)


  • Thanks for reading this article thence far. If you lot similar this article thence delight portion amongst your friends in addition to colleagues. If you lot receive got whatever query or feedback, delight driblet a note.