Showing posts sorted by relevance for query what-is-race-condition-in. Sort by date Show all posts
Showing posts sorted by relevance for query what-is-race-condition-in. Sort by date Show all posts

Saturday, November 9, 2019

10 Advanced Gist Coffee Interview Questions For Senior As Well As Experienced Programmer

Java interview questions for Senior in addition to Experienced programmer
Java is rattling big in addition to at that spot is no agency to laid upwards completely for whatever total coffee interview but at that spot is a degree of query depends upon your experience, if yous are fresher than questions asked inward Java interview are to a greater extent than oftentimes than non based on fundamentals similar Iterator vs Enumeration inward Java, Why principal is world static in addition to void or may live on ArrayList vs LinkedList inward Java. Things changes when yous apply for senior developer, Technical Pb or Team Lead Java positions, questions asked on that degree are to a greater extent than advanced in addition to less pop amid Java circles, yous may live on asked questions from blueprint pattern, questions from multi-threading, Collections and fifty-fifty asked to write code, blueprint classes in addition to laid upwards JUnit tests. In this Java article I volition part some advanced Core Java interview questions which is look inward Senior degree interviews to a greater extent than oftentimes than non on iv to six years in addition to six to eight years of experience. One of import affair to banknote is that yous tin non clear interview past times only mugging answers of these query because interviewer is most probable asked yous follow-up query based upon your response in addition to solely agency to acquire through it is to empathize the topic well.


10 total Java interview query for senior developers in addition to TechLead

Java interview questions for Senior in addition to Experienced programmer 10 Advanced total Java interview questions for senior in addition to experienced programmerHere are my listing of questions which is worth preparing if yous are going for total coffee interview for senior position, these questions are to a greater extent than oftentimes than non based upon Garbage collection , Concurrency, Collections, design, Coding in addition to testing.




How does ConcurrentHashMap industrial plant inward Java ? 
is ConcurrentHashMap is thread-safe?
Can nosotros supercede Hashtable to ConcurrentHashMap without external synchronization?
As yous come across at that spot are multiple query inward this category, those are to a greater extent than oftentimes than non followup in addition to tin live on answered if yous empathize ConcurrentHashMap well. yous tin come across this article about Hashtable in addition to ConcurrentHashMap to larn more.

What is CountDownLatch inward Java?
What is CyclicBarrier inward Java?
What is divergence betwixt CountDownLatch in addition to CyclicBarrier inward Java?
Concurrency is favorite topic on advanced total coffee interviews in addition to its expected from experienced in addition to senior Java developers to bring practiced agreement of multi-threading in addition to concurrency API inward Java. See these postal service well-nigh CountDownLatch inward Java in addition to Difference betwixt CountDowntLatch in addition to CyclicBarrier inward Java.

What is Race status ? Have yous faced whatever race condition?
What is deadLock inward Java? Write code to avoid deadlock inward Java
Raced weather condition in addition to deadlock are major challenges piece writing high functioning concurrent Java applications in addition to hands on sense of dealing amongst synchronization in addition to concurrency resultant expected from a senior in addition to sense Java programmer. Refer how to avoid deadlock inward Java in addition to What is race status inward Java for to a greater extent than details.


What is PermGen infinite ?
What is retention leak inward Java?
What is OutOfMemoryError inward PermGen mens?
What is divergence betwixt NoClassDefFoundError in addition to ClassNotFoundException inward Java?
These are some questions related to Errors in addition to Exceptions inward Java, OutOfMemoryError in addition to NoclassDefFoundError are most mutual nevertheless dreaded errors inward Java. come across the links for to a greater extent than details.

You tin besides notice answers of these questions past times searching on google, key indicate is to empathize it deeply.

Further Learning
Data Structures in addition to Algorithms: Deep Dive Using Java
Java Fundamentals: The Java Language
Complete Java Masterclass
Java Programming Interview Exposed

Top Xl Advanced Java/J2ee Interview Questions Answers For Experienced - Iii To V Years

I have got shared many posts most Java interview query inward the past times but nothing, especially for back upwardly engineer perspective. Since at that spot are a lot of L1 as well as L2 back upwardly task exists inward BFSI (Banking, Finance, as well as Insurance Industry) as well as they are also for the longer term, I decided to write this post. When you lot move for a back upwardly engineer role, especially for Java application live on it to heart as well as person Java or Java EE application, Interviewer expects you lot know basics of Java as well as tin start/stop the application, come across log files, warning developers, as well as other aspects of the back upwardly e.g. opening conference pair to solve production issues, communicating to stakeholders, as well as involving correct peoples. In this article, I volition percentage questions to assist with technical aspects e.g. the essential skills you lot demand to clear a back upwardly engineer interview.

Even though you lot volition live on interviewed to back upwardly Java application, it's expected from you lot to know SQL, UNIX, XML as well as other key technologies which you lot volition exercise inward your day-to-day job. In this post, you lot volition notice questions which are asked to banking concern represent whether a candidate has required skills to back upwardly Java application or not.


39 Interview Questions for Java JEE Support Engineers

Here is my collection of some of the best interview questions for Java as well as JEE back upwardly professionals. If you lot are working inward production services or supporting Java application, these interview query volition assist you lot to create good on your interview. If you lot moving from evolution to back upwardly role so also these questions volition give you lot a proficient thought most what is expected from a Java JEE back upwardly engineers.

1) How create you lot banking concern represent your Java procedure is running on Linux? (example)
You tin banking concern represent past times using "ps" ascendancy as well as "grep" ascendancy e.g. ps -ef | grep "myprocess". The keyword which you lot exercise with grep for search tin live on anything unique to your process, something which appears inward its ascendancy draw e.g. get upwardly of the shape which implements the primary method. You tin also create "ps -ef | grep java" to listing all Java process.



2) How create you lot banking concern represent how much retention as well as CPU your Java procedure is consuming?
First, you lot demand to notice the PID of your process, which you lot tin notice past times using the "ps" ascendancy equally shown inward the previous question. Once you lot notice the PID you lot tin exercise the "top" ascendancy to notice the CPU as well as retention usage. Alternatively, you lot tin also exercise the prstat ascendancy equally shown here.


3) What does -Xmx as well as -Xms parameters mean?
These are parameters to specify heap size inward Java. The -Xms defines the size of the heap when JVM starts upwardly as well as -Xmx is used to specify the maximum heap size for Java application i.e. your heap cannot grow beyond that as well as JVM volition croak past times throwing OutOfMemoryError if your heap doesn't have got plenty infinite to create novel objects. See here to acquire to a greater extent than most heap retention inward Java.


4) What is the departure betwixt JVM as well as JRE?
The JRE stands for Java Runtime Environment as well as JVM stands for Java Virtual Machine. You install JRE to run Java application e.g. Applet or Core Java application or Web server similar Tomcat. The JVM is business office of JRE. See here to acquire to a greater extent than differences betwixt JVM as well as JRE.


5) What is the departure betwixt JVM as well as JIT? (answer)
The JVM stands for Java Virtual machine spell JIT stands for Just inward fourth dimension Compiler. The JIT is business office of JVM as well as used to convert the Java bytecode into native machine code which runs faster. There is some threshold gear upwardly if a code runs to a greater extent than than the threshold it becomes the candidate of only inward fourth dimension compilation past times JIT.



6) How create you lot accept the heap dump of a Java process? 
There are many ways to accept the heap dump of a Java procedure e.g. Tomcat, but most mutual is past times using tools available inward JDK e.g. jVisualVM, jCmd, as well as jmap. Here is the ascendancy you lot tin exercise to accept the heap dump of Java process:

$ jmap -dump:live, file=/location/of/heap_dump.hprof  PID

The heap dump volition comprise all alive objects as well as they are stored inward heap_dump.hprof file. Remember, you lot also demand PID of Java procedure which you lot tin notice past times using "ps" as well as "grep" ascendancy equally discussed inward the source question. You tin come across Java Performance Companion past times Charlie Hunt to acquire to a greater extent than most taking as well as analyzing heap dump inward Java to notice retention leak as well as other retention related errors. 



7) How create you lot accept a thread dump of a Java process?
Taking thread dump is easier than taking heap dump because you lot don't demand to call back tool. In Linux, you lot tin only exercise the kill ascendancy to accept the thread dump e.g.

$ kill -3 PID 

volition impress the thread dump inward the log file or where System.out is redirected. Similarly, inward Windows, you lot tin exercise Ctrl + Break from the ascendancy prompt. Alternatively, you lot tin also exercise jConsole as well as VisualVM to accept the thread dump of Java application inward both Windows as well as Linux. You tin also read Java Performance The Definitive Guide By Scott Oaks to acquire to a greater extent than most thread dump as well as heap dump.



8) What is OutOfMemoryError inward Java? How create you lot bargain with that?
The Java virtual machine throws java.lang.OutOfMemoryError when at that spot is non plenty retention to run the application e.g. no to a greater extent than retention to create novel objects, no to a greater extent than retention to create novel threads etc. The most mutual OutOfMemoryError is the java.lang.OutOfMemoryError: coffee heap space, which comes when at that spot is no to a greater extent than retention left to create a novel object.


9) What is the departure betwixt 32-bit as well as 64-bit JVM? (answer)
The primary differences betwixt 32-bit as well as 64-bit JVM are that afterward is designed for 64-bit operating arrangement e.g. Windows 8 or afterward versions of Linux. From Java developer's perspective, the primary departure betwixt them comes from heap size. Influenza A virus subtype H5N1 64-bit JVM virtually has unlimited heap memory equally compared to 4GB of the theoretical bound of 32-bit JVM. If your plan needs to a greater extent than memory, meliorate run it on 64-bit JVM with large heap space. See hither to acquire to a greater extent than most 32-bit as well as 64-bit JVM.



13) What is Garbage Collector? (answer)
The garbage collector is a element of Java virtual machine which is responsible for reclaiming retention from dead objects. It's i of the key components as well as allows an application developer to focus on application evolution rather than doing retention management. Some of the pop garbage collectors are a Concurrent Mark-Sweep garbage collector as well as G1 garbage collector inward recent times.


14) How create you lot analyze a heap dump?
There are many tools to analyze heap dump inward Java e.g. you lot tin exercise the jhat tool which comes along with JDK. You tin also exercise Eclipse Memory Analyzer to analyze heap dump to notice out whatever retention leak inward Java spell dealing with OutOfMemoryError inward Java. See Java Performance The Definitive Guide By Scott Oaks to acquire to a greater extent than about analyzing Java Heap dump.

 I have got shared many posts most Java interview query inward the past times but zero Top xl Advanced Java/J2EE Interview Questions Answers for Experienced - iii to five Years



15) What is the departure betwixt Web Server as well as Application Server? (answer)
The primary departure betwixt Web as well as Application Server comes from the fact that you lot cannot run EJB on the Web server similar Tomcat or Jetty. The application server similar WebLogic as well as WebSphere provides the runtime surroundings for EJB as well as other advanced services required past times Java EE or J2EE specification.


16) What is the departure betwixt Apache httpd as well as Tomcat?
Though both httpd as well as Tomcat are products of Apache software foundation, the httpd is to a greater extent than pop as well as used across the spider web as well as non only inward Java world. The httpd is a spider web server which tin serve static HTML files as well as dynamic content using PHP, Perl or Python, spell Tomcat is a Servlet container which provides the runtime surroundings for Servlet as well as JSP. You tin also exercise both Apache httpd as well as Tomcat together inward Java world.


17) Can you lot exercise Apache as well as Tomcat together?
Yes, you lot tin exercise Apache as well as Tomcat together. There are many Java spider web application which is fronted past times Apache spider web server to deliver static resources e.g. HTML files, images, configuration files etc. You tin so configure Apache to forwards the asking to Tomcat.


18) How create you lot start as well as halt Tomcat inward Linux?
When you lot install Tomcat inward Linux past times unzipping the downloaded package, you lot tin come across that at that spot is a startup.sh as well as shutdown.sh file inward the tomcat/bin directory. These scripts are used to start as well as halt Tomcat inward Linux. These scripts internally telephone phone Catalina.sh, the primary script to start Tomcat engine.



19) How create you lot start as well as halt Apache inward Linux?
The Apache server runs equally httpd daemon inward Linux as well as you lot tin either exercise kill command after finding the PID of httpd procedure equally shown hither or you lot tin exercise the apachectl script equally shown below to start as well as halt Apache spider web server inward Linux

Starting Apache spider web server inward Linux

$ apachectl start

Stopping Apache web server inward Linux

$ apachectl stop

Restarting Apache spider web server inward Linux

$ apachectl restart
or:
/sbin/service httpd restart

You mightiness demand root access to create if Apache spider web server is non running on your application account.


20) What is JDBC?
The JDBC stands for Java Database connectivity as well as it provides API to connect a database from Java programs. Different Java vendors e.g. MySQL, Oracle, Microsoft SQL Server, PostgreSQL they implement the API as well as provides their driver implementation to allow Java to connect to their database. Since almost every venture application has a database, JDBC is real of import for whatever existent globe projects.


21) What is the departure betwixt JDBC as well as JNDI?
As I said inward the previous answer, the JDBC stands for Java Database Connectivity as well as provides APIs as well as guidelines to connect a database from Java, spell JNDI stands for Java Naming as well as Directory Interface as well as provides a logical construction for retrieving resources e.g. database, messaging queues, venture Java beans without knowing their physical house e.g. host or port. You tin register a resources with JNDI as well as so residuum of your application element tin access them using JNDI name. The database connexion puddle is the most mutual resources accessed via JNDI inward web servers similar Tomcat or WebLogic.


22) What is database connexion pool? (answer)
As it get upwardly suggests, it only a puddle of database connections. Since creating a novel database connexion inward real-time is an expensive procedure as well as tin potentially deadening downwards the response time, many application maintains a puddle of active database connection. When a request comes inward they retrieve a connexion from the pool, acquire the information from the database as well as so render the connexion dorsum to puddle so that it tin live on reused. This way, response fourth dimension is improved inward most of the Java spider web application. See here to setup a database connexion puddle inward Tomcat using Spring framework.


23) Your Java application is connected to a Database via a connexion pool. Suddenly your database goes down? Is that an number with your Java application? Do you lot demand to restart your Java application?

hint: Since your Java application is using a connexion pool, it has active connections to database which volition acquire disconnected i time DB goes down. If you lot attempt to execute a query, you lot volition have Socket errors.



24) How create you lot shipping spider web service asking from Linux? (answer)
There are some commands available inward Linux e.g. curl as well as wget which allows you lot to shipping HTTP commands, which you lot tin exercise to telephone phone as well as essay your spider web services from Linux. Particular, Curl is used extensively to essay RESTful Web Services because it tin shipping POST request, GET request, asking with headers as well as also authenticate using both basic as well as digest authentication.

If you lot are working with REST API, I advise learning curl, it's real convenient to banking concern represent if your API is working properly using curl from the ascendancy line. You tin fifty-fifty write a script to automate those stuff.


25) What is the departure betwixt HTTP as well as HTTPS? (answer)
This is i of the mutual as well as like shooting fish in a barrel questions. Of course, you lot know the departure betwixt HTTP as well as HTTPS right? well, HTTP is insecure but HTTPS is secure, the extra "s" is for security, which agency it non exclusively encode as well as encrypt the message earlier sending but also verify the identity of the server past times using  SSL certificates provided past times global certificate government e.g. GoDaddy, Thawte, VeriSign, Digicert, GeoTrust, as well as Comodo.  See here to acquire to a greater extent than how SSL as well as Certifications run inward Java spider web application.


26) What is the departure betwixt the GET as well as POST method? (answer)
Another uncomplicated but ofttimes asked query on Java back upwardly interviews. The primary departure betwixt the GET as well as POST is that GET is both idempotent and rubber but POST is not. You tin burn GET asking multiple fourth dimension as well as it volition give the same number but multiple POST submission should ever live on avoided. GET is also used to read information from server as well as POST is used to shipping information to the server.


27) What is the departure betwixt Servlet as well as JSP? (answer)
This is some other interesting Java JEE back upwardly Interview Question. Even though both Servlet as well as JSP is used to create dynamic HTML the key departure betwixt them is their purpose. Servlet is meant for Java developers as well as you lot write to a greater extent than Java than HTML as well as that's why it serves equally Controller inward many pop MVC framework e.g. DispatcherServlet inward Spring MVC.

On the other hand, JSP is designed for HTML developers as well as it's to a greater extent than HTML than Java as well as that's why it is used equally "view" inward MVC frameworks similar Spring as well as Struts. See the link inward the reply for to a greater extent than detailed comparison.



28) What is the departure betwixt Struts as well as Spring MVC?
This is i time again a pop as well as ofttimes asked query on Java JEE Interviews. Even though both are pop spider web MVC framework for Java applications, the key departure is that Spring brings dependency injection source as well as Struts brings it afterward using Struts 2.0.

Spring is also a suite of libraries e.g. you lot acquire Spring Security to implement safety inward your application, so at that spot is Spring Boot, Spring Data, Spring Cloud as well as many to a greater extent than useful libraries nether Spring umbrella.

answer)
There are many differences betwixt JDBC as well as Hibernate but the most of import i is that JDBC provides an API to connect to the database as well as execute the query but Hibernate is an ORM (Object Relational modeling) framework, which agency it allows you lot to run with objects spell it takes aid of saving as well as retrieving object from database.

In short, inward JDBC you lot demand to write SQL queries to acquire as well as shop information from database but inward Hibernate you lot only bargain with objects, Hibernate takes aid of issuing SQL queries to the database.


30) What is the departure betwixt Stack retention as well as heap? Which i is faster? (answer)
These are only 2 dissimilar retention areas used to shop dissimilar kinds of variables. The stack is local to every thread spell heap retention is shared alongside all threads. Since Stack is closer to thread as well as unremarkably implemented using CPU registers they are faster than heap memory. The stack is used to shop local variables equally good method telephone phone frames spell heap is used to shop objects as well as shape metadata. See the detailed reply for to a greater extent than points.


31) What is the departure betwixt TCP/IP as well as UDP protocol? (answer)
There are several differences betwixt TCP as well as UDP protocol but the most of import of them is that TCP provides a guarantee of message delivery spell UDP doesn't give whatever guarantee. Because of this guarantee TCP sends to a greater extent than messages than UDP as well as thus eat to a greater extent than bandwidth as well as slower than UDP. TCP is also connexion oriented protocol spell UDP is connectionless. See the detailed reply for to a greater extent than points.

 I have got shared many posts most Java interview query inward the past times but zero Top xl Advanced Java/J2EE Interview Questions Answers for Experienced - iii to five Years



32) Your Java application is connecting to some other Java application (server) running on the remote host as well as listening on port 17865. Now, you lot don't have got access to that remote host to move as well as come across if the procedure is running. How create notice if the server is upwardly as well as running?
hint: you tin exercise the telnet command



33) You are supporting a Java spider web application which connects to many heart as well as person Java procedure as well as gets information from them to the distribution to clients? One customer complains that the asking for information is taking also long as well as it's almost similar hung? How create you lot troubleshoot this problem?

hint: banking concern represent the log, banking concern represent database, banking concern represent the file system


34) The Java application you lot back upwardly connects to a database via a DNS, which automatically switches to the secondary database server when the primary goes down. You notice that inward the trial of a failover, your Java application is non connecting to secondary DB server? How create you lot troubleshoot this problem?

hint: banking concern represent which version your Java application is running. Some JRE caches the DNS e.g. JRE 1.6

answer)
The deadlock is a status which tin occur betwixt 2 or multiple threads. In this case, each of the thread waits for each other as well as cannot progress. In Java, this unremarkably happens when thread 1 holds the lock required past times thread 2 as well as thread 2 holds the lock required past times thread 1. If your Java plan is hung so it could live on a deadlock. You tin accept a thread dump as well as notice out if whatever thread is waiting for the lock concord past times other as well as vice-versa. You tin also exercise jConsole tool to notice deadlock.


36) What is the race condition? (answer)
The race status is some other multithreading as well as concurrency põrnikas which happens due to racing betwixt 2 threads, for example, if i thread is updating a variable as well as minute thread tries to read the value earlier it finished. You tin avoid race weather condition past times properly synchronizing your code.


37) What is the departure betwixt PATH as well as CLASSPATH? (answer)
Both are key surroundings variable used past times Java platform, but the key departure betwixt them is that PATH points to the JDK binaries or native libraries e.g. java.exe, spell CLASSPATH points to Java binaries e.g. JAR files, which contains bytecode. PATH is also arrangement marker concept independent of Java but CLASSPATH is purely Java concept as well as used past times JVM to charge classes required past times Java application you lot are running.


38) How create you lot notice the Java version used past times your application? (answer)
You tin run the coffee -version ascendancy inward the ascendancy prompt to notice out the version of Java used past times your application. If you lot have got multiple JDK or JRE installed so brand certain you lot exercise the i which is used past times your application.


39) What is JAVA_HOME surroundings variable? (answer)
The JAVA_HOME is zero but a user defined surroundings variable which points to the installation directory of JDK. For example, if you lot have got installed JDK inward /opt/jdk_1.6_20 inward Linux so the JAVA_HOME variable volition betoken to this directory. Same goes for Windows or whatever other operating system.


That's all most 39 essential questions fro Java JEE Support Engineer. It's only a pocket-size gear upwardly of questions you lot tin hold off inward whatever service based companionship or investment banks but does call back to create key skills required for back upwardly engineers e.g. UNIX, SQL, Java, as well as others. In the adjacent business office of this article, I volition percentage some of the ofttimes asked questions from Java Support Engineer on SQL, UNIX, as well as other supporting technologies.


Other topic based Java Interview questions for to a greater extent than practice
  • 21 Java Inheritance Interview Questions as well as Answers (list)
  • 15 Data Structure as well as Algorithm Questions from Java Interviews (read here)
  • Top 10 Spring Framework Interview Questions with Answers (see here)
  • Top twenty Hibernate Interview Questions as well as Answers (list)
  • 10 JDBC Interview Questions for Java Programmers (questions)
  • 15 Java NIO as well as Networking Interview Questions with Answers (see here)
  • 20 Java Design Pattern Questions asked on Interviews (see here)
  • 10 Struts Interview Questions for Java developers (list)
  • 30 OOP Interview Questions with Answer (see)
  • 19 Method overloading as well as overriding interview questions (see here)
  • 10 ofttimes asked Servlet Interview Questions with Answers (see here)
  • 15 Java Enum based interview questions with answers (read)
  • 10 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)
  • 10 Hibernate Interview Questions for Java EE developers (see here)
  • 21 Final modifier interview questions with reply (read)
  • 10 XML Interview Questions for Java Programmers (read here)
  • Top 10 XSLT Interview Questions with Answers (read more)
  • Top 10 Trick Java Interview Questions as well as Answers (see here)
  • Top xl Core Java Phone Interview Questions with answers (list)

This list of Java interview questions for Java, JEE, as well as J2EE back upwardly engineers should live on plenty to create for whatever Java interview. You tin crevice both fresher as well as sense marker interview past times preparing these Java interview questions, at to the lowest degree source few rounds. If you lot human face upwardly whatever other interesting query which is non inward this list, so delight permit me know via comments as well as I'll add together it.

Further Learning
Java Web Fundamentals By Kevin Jones
Spring Framework 5: Beginner to Guru
JSP, Servlets as well as JDBC for Beginners: Build a Database App


Sunday, November 24, 2019

Java Arraylist Tutorial - The Mega List

I conduct maintain written several ArrayList tutorials, touching unlike ArrayList concepts in addition to many how to exercise examples amongst ArrayList. In this tutorial, I am giving a summary of each of them. Why? So that whatever Java beginner who wants to acquire ArrayList inwards detail, tin dice through the relevant tutorial in addition to learn. It's equally good on asking of many of my readers, who asked inwards yesteryear to portion all the relevant tutorials inwards ane place. Why should y'all acquire ArrayList? Because it's the most of import Collection bird inwards Java. You volition oft uncovering yourself using ArrayList in addition to HashMap inwards tandem. It's your dynamic array which tin resize itself equally it grows. In to a greater extent than or less other word, ArrayList is equally much of import equally an array. When I started learning Java, my bespeak to ArrayList starts equally a dynamic array, because at that spot were many scenarios where nosotros don't know the size of the array inwards advance. We terminate upwards either allocating less infinite or to a greater extent than space, both are non ideal. Btw, y'all should equally good banking concern check out Head First Java 2d Edition if y'all are newbie in addition to Effective Java 2nd Edition, if y'all know Java but wants to dice a Java expert.


What is inwards this tutorial of ArrayList?

In this list, y'all volition uncovering ii kinds of Java ArrayList tutorials, first, how to exercise something amongst ArrayList e.g. how to declare ArrayList amongst values, how to sort ArrayList inwards contrary order, how to filter elements from ArrayList, how to convert ArrayList to an array in addition to so on. The instant type of tutorial is for concept edifice which is based on unlike properties of ArrayList e.g. what is the divergence betwixt Vector in addition to ArrayList etc. These are equally good the type of query y'all volition oft come across inwards telephone circular of Java Interviews. So, those volition aid y'all to exercise good at that spot equally well.




How to exercise ArrayList Tutorials

Below is ane of the most comprehensive how to guide for Java ArrayList. You volition acquire almost everything most AraryList yesteryear going through thise list. These are equally good solution of many mutual requirement Java developers human face upwards inwards their hateful solar daytime to hateful solar daytime evolution work, ofcourse related to ArrayList.

How to initialize ArrayList inwards ane line? (the trick)
Java doesn't back upwards collection literals similar to array but y'all tin initialize the arraylist inwards only ane line, at the same fourth dimension y'all declare it yesteryear next this squeamish footling trick. It's improve than to a greater extent than or less other choice called double pair initialization, which is considered anti-pattern inwards Java because it creates annonymous bird everyime y'all piece of occupation it to initialize the ArrayList.

How to take Duplicates from ArrayList inwards Java? (solution)
Since ArrayList is subclass of List it does non forbid y'all from adding duplicate elements but if y'all actually demand an ArrayList of unique elements in addition to then nosotros conduct maintain a got a solution for you. You volition acquire a squeamish footling flim-flam to eliminate duplicate elements from ArrayList inwards Java.

How to contrary ArrayList inwards Java? (solution)
Since List doesn't render a built-in reverse() method y'all demand to exercise that yesteryear yourself. This tutorial volition instruct y'all a unproblematic Java programme to contrary the ArrayList inwards Java.

How to Synchronize ArrayList inwards Java? (tutorial)
ArrayList is non synchronized in addition to that's why it's fast also, but if y'all conduct maintain to portion your ArrayList inwards a multi-threaded program, y'all improve synchronize the listing to avoid multi-threading problems similar deadlock, corrupted objects, race weather condition etc.

How to loop over ArrayList inwards Java? (example)
Simple Java programme to acquire how to loop over ArrayList inwards Java e.g. for loop, piece loop, advanced for loop in addition to yesteryear using Iterator.

How to sort ArryList inwards Java amongst ascending order? (example)
Remember, ArrayList is an ordered collection, which agency the lodge y'all add together elements are preserved, so if y'all are already added object inwards ascending lodge in addition to then y'all don't demand to sort again, but if y'all conduct maintain added elments inwards random lodge in addition to wants them to suit inwards ascending order, in addition to then this tutorial volition aid you.

How to piece of occupation ArrayList inwards Java? (guide)
This is the beginner's guide to piece of occupation ArrayList inwards Java. You volition acquire how to piece of occupation unlike methods from java.util.ArrayList bird e.g. add() to insert objects, remove() to delete objects, get() to retreive objects in addition to contains() to banking concern check if an object is acquaint inwards ArrayList or not.

How to convert ArrayList to String inwards Java? (tutorial)
Even though ArrayList has a toString() method it's non actually helpful other than to a greater extent than or less debugging purpsoe. If y'all desire to acquire all elemetns cast ArrayList equally comma separated String in addition to then at that spot is no method inwards Java. This tutorial volition instruct y'all how to convert an ArrayList to delimited String inwards Java.

How to acquire subList from ArrayList inwards Java? (tutorial)
H5N1 unproblematic Java programme to demonstrate how to piece of occupation subList() portion from java.util.ArrayList to acquire the exclusively to a greater extent than or less elements from ArrayList instead of all elements.

How to take elements from ArrayList inwards Java? (guide)
There are multiple ways to take objects from ArrayList but they don't piece of occupation perfectly inwards all situation, for instance y'all tin piece of occupation remove() method of java.util.ArrayList to convey out objects from ArrayList but if y'all exercise so piece iteating in addition to then y'all volition human face upwards ConcurrentModificationException, inwards that province of affairs y'all demand to piece of occupation iterator's remove() method. This tutorial volition instruct  you the right way to delete elements from ArrayList inwards Java.

How to convert ArrayList of String to Array of String? (tutorial)
One of the most mutual chore inwards hateful solar daytime to hateful solar daytime programming is covnerting Arraylist to array in addition to vice-versa. No mattter how carefully y'all pattern your software, y'all volition uncovering that doing quite often, many times due to using third-party libraries, which convey other type. I actually promise Java auto-boxing should convert array to arraylist in addition to hopefully it mightiness exercise it inwards future, till in addition to then y'all tin piece of occupation this squeamish footling trick.

How to brand an ArrayList read exclusively inwards Java? (tutorial)
Collections bird provides several utility method to exercise wrapper objects e.g a read exclusively wrapper of ArrayList, y'all tin piece of occupation Collections.unmodifiableList() method to brand the arraylist read only.

How to avoid ConcurrentModificationException piece iterating over ArrayList? (solution)
Don't piece of occupation ArrayList's remove() method piece iterating, if y'all conduct maintain to take elements during traversal piece of occupation the Iterator's remove() method to avoid CME inwards Java.

Basic examples of ArrayList inwards Java (answer)
You volition acquire to a greater extent than yesteryear looking at examples because they contains to a greater extent than details. This tutorial contains to a greater extent than or less basic examples of using ArrayList bird inwards Java.

How to sort ArrayList inwards descending lodge inwards Java? (answer)
This is the instant portion of sorting tutorial. Earlier y'all acquire how to sort the ArrayList inwards ascending lodge in addition to inwards this tutorial y'all volition acquire the other way, sorting ArrayList inwards decreasing order.

How to traverse over ArrayList inwards Java? (answer)
Simple Java programme to traverse over ArrayList using Iterator in addition to ListIterator inwards Java. You volition equally good acquire how to add together in addition to take elements piece iterating.

answer)
You cannot alter the size of array ane time created but ArrayList tin re-size itself. Also for same seat out of elements, array volition convey less retentiveness than ArrayList.

When to piece of occupation ArrayList in addition to LinkedList inwards Java? (answer)
When y'all exercise search to a greater extent than oft than add-on or removal of objects in addition to then piece of occupation ArrayList but if y'all dice on uncovering yourself adding novel elements or removing one-time elements than piece of occupation LinkedList.

The divergence betwixt ArrayList in addition to HashSet inwards Java? (answer)
ArrayList is an ordered collection in addition to allow duplicates but HashSet is a set, thus at that spot is no ordering guarantee but it doesn't allow duplicates.

The divergence betwixt Vector in addition to ArrayList inwards Java? (answer)
Vector is legacy bird which was subsequently retrofitted to implement List interface but its synchronized, thus slower, piece AraryList is non synchronized in addition to faster.

The divergence betwixt HashMap in addition to ArrayList inwards Java? (answer)
HashMap is backed yesteryear hash tabular array information construction piece ArrayList is only a dynamic array. You demand key in addition to value to piece of occupation HashMap but y'all tin access elements using index inwards ArrayList.

Difference betwixt length() of array in addition to size() of ArrayList inwards Java? (answer)
ane returns capacity other returns total seat out of elements currently acquaint inwards ArrayList.

What is CopyOnWriteArrayList inwards Java? (answer)
H5N1 concurrent collection which allows multiple threads to read the list, acquire the elements without whatever synchronization.

What is divergence betwixt synchronized in addition to CopyOnWriteArrayList inwards Java? (answer)
CopyOnWriteArrayList uses to a greater extent than sophisticated approach to gain thread-safety. It equally good doesn't lock the ArrayList during read which synchronize listing does.

What are unlike ways to take objects from ArrayList inwards Java? (answer)
There are ii ways to take objects yesteryear using remove(object) in addition to yesteryear using remove(index), but y'all should move careful if y'all are removing objects from ArrayList of integers because due to auto-boxing a telephone telephone to remove(1) dice ambiguous.

Can nosotros declare ArrayList amongst values inwards Java? (answer)
Yes y'all can, come across the respond for a unproblematic code example.


That's all on this list of Java ArrayList tutorials. Once y'all volition gone through these tutorials, y'all volition acquire almost everything most ArrayList including how it plant in addition to how to piece of occupation the correctly. These how to tutorials are equally good recepie of many hateful solar daytime to hateful solar daytime problems Java developers human face upwards piece doing Java development.

Further Learning
Java In-Depth: Become a Complete Java Engineer
Java Fundamentals: Collections
Data Structures in addition to Algorithms: Deep Dive Using Java


Saturday, November 9, 2019

Top 12 Coffee Thread, Concurrency In Addition To Multithreading Interview Questions For Experienced

Java concurrency as well as thread interview questions answers
Multithreading is an of import characteristic of Java programming language, which agency threads are too an of import purpose of whatsoever Java interview. It's truthful as well as inward fact at beginners as well as freshers bird Thread interview questions inward Java are 1 of most hard to answer. One argue for interview query related to multithreading as well as concurrency beingness hard is confusion unopen to how multiple threads plant together as well as minute is threads are really a complicated theme to empathise as well as usage correctly. Mostly thread interview questions checks Java programmers noesis on Java Thread API, Java concurrency API, issues related to multi-threading similar a race condition, thread-safety, as well as deadlock. Some fourth dimension multithreading as well as concurrency interview query too focus on parallel blueprint patterns similar solving the producer-consumer problem, implementing travel bag pattern or solving dining philosopher work inward Java. This is especially truthful spell interviewing experienced Java developers amongst iv to half-dozen years of experience.

In this article, nosotros volition withdraw maintain a expression at dissimilar kinds of multithreading as well as concurrency questions asked inward diverse interviews e.g. on telephonic or human face upward to human face upward interview, on written test, to both experienced as well as senior Java developers, as well as some tips to reply them correctly.

Questions asked on telephonic or the first circular of interviews are tend to travel easier as well as you lot must reply them to the betoken amongst a keyword, which interviewer is expecting. On the human face upward to human face upward interview, travel laid upward for dissimilar kinds of follow-up questions.




Java Interview questions on Concurrency as well as multithreading

As I said, inward this Java article, non only,  I volition percentage some of the most commonly asked thread interview questions at freshers as well as beginners level, similar upward to 2 to iv years of experience, as well as some tips as well as tricks to reply them correctly.

By the way, these thread interview questions are as useful for senior Java developers or guys amongst some Java sense inward hand. I withdraw maintain tried to percentage answers to these interview questions on the thread as good but I propose you lot do some enquiry as well as larn the theme good to reply whatsoever follow-up questions, which comes due to your response to these thread questions inward Java.

Anyway hither is my collection of Java thread interview questions as well as how to answers them inward Java :


1) What is the departure betwixt start as well as run method inward Java Thread? (answer)
This thread interview query is too inquire as if start() method eventually telephone phone run() method as well as then why do you lot demand to telephone phone start() method, why non telephone phone run() method directly. well, argue is that because start method creates a novel thread as well as telephone phone the code written within the run method on a novel thread spell calling run method executes that code on the same thread. You tin too come across the article start vs run method inward Java for to a greater extent than details.



2) Write code to avoid deadlock inward Java where due north threads are accessing due north shared resources? (answer)
This is a classic Java multithreading interview questions, which appears on almost every listing of Java thread questions. This query is based on jeopardy as well as issues faced past times parallel programs without proper synchronization or wrong synchronization. This query explores the concept of looking as well as best practices on acquiring as well as releasing the lock on shared resource. By the way, it's been covered inward many places as good as well as I propose reading  How to preclude deadlock inward Java, non exclusively for particular reply of this Java multithreading query but too to larn how to preclude deadlock inward Java.



3) Which 1 is improve to implement thread inward Java ? extending Thread degree or implementing Runnable? (answer)
Well, this is some other ofttimes asked questions on whatsoever Java thread interview. Essentially these are ii way to implement Thread inward Java, past times extending java.lang.Thread degree or past times implementing java.lang.Runnable interface.

By extending the degree you lot are using your adventure to extend 1 whatsoever exclusively 1 degree as Java does non back upward multiple inheritances, past times implementing a Runnable interface you lot tin yet extend some other class. So extending Runnable or fifty-fifty Callable is a improve choice. You tin too come across Runnable vs Thread degree inward Java for to a greater extent than answers on this questions.

Given its simplicity as well as fact-based nature, this query generally appears on either telephonic circular or initial screening rounds. Key points to mention, spell answering this query includes multiple inheritance at the degree bird as well as separation of defining a chore as well as execution of a task. Runnable exclusively stand upward for a task, spell Thread stand upward for both tasks as well as it's execution.




4) What is Busy Spinning? Why volition you lot usage Busy Spinning as hold off strategy? (answer)
This is 1 of the advanced concurrency interview questions inward Java as well as exclusively asked to experienced as well as senior Java developers, amongst lots of concurrent coding sense nether the belt. By the way, the concept of busy spinning is non new, but its usage amongst multi-core processor has risen lately (see The Art of Multiprocessor Programming).

Java concurrency as well as thread interview questions answers Top 12  Java Thread, Concurrency as well as Multithreading Interview Questions For experienced

The busy waiting is a hold off strategy, where 1 thread hold off for a status to overstep away true, but instead of calling hold off or slumber method as well as releasing CPU, it only spins. This is specially useful if the status is going to travel truthful quite chop-chop i.e. inward a millisecond or microsecond.

The wages of non releasing CPU is that all cached information as well as teaching stay unaffected, which may travel lost, had this thread is suspended on 1 heart as well as brought dorsum to some other thread. If you lot tin reply this question, that residual assure of a practiced impression.


5) What is the departure betwixt CountDownLatch and CyclicBarrier in Java? (answer)
The CountDownLatch and CyclicBarrier inward Java are ii of import concurrency utility which is added on Java v Concurrency API. Both are used to implement scenario, where 1 thread has to hold off for other thread earlier starting processing but at that spot is a departure betwixt them.

The fundamental betoken to mention, spell answering this query is that CountDownLatch is non reusable in 1 trial the count reaches to zero, spell CyclicBarrier tin travel reused fifty-fifty after the barrier is broken.

You tin too come across my previous article difference betwixt CyclicBarrier as well as CountDownLatch inward Java for a to a greater extent than detailed reply of this concurrency interview query as well as a existent life trial of where to usage these concurrency utilities.



6) What is the departure betwixt hold off as well as slumber inward Java? (method)
One to a greater extent than classic Java multithreading question from the telephonic circular of interviews. The fundamental betoken to advert spell answering this query is to advert that hold off volition release the lock as well as must travel called from the synchronized context, spell slumber volition exclusively intermission the thread for some fourth dimension as well as overstep away on the lock.

By the way, both methods throw IntrupptedException and tin travel interrupted, which tin Pb to some follow-up questions like, tin nosotros awake a sleeping or waiting for a thread inward Java? You tin too read a detailed reply on my postal service of same championship here.

Java concurrency as well as thread interview questions answers Top 12  Java Thread, Concurrency as well as Multithreading Interview Questions For experienced



7) How do you lot solve producer consumer work inward Java? (solution)
One of my favorite questions during whatsoever Java multithreading interview, Almost one-half of the concurrency problems tin travel categorized inward the producer-consumer pattern. There are basically ii ways to solve this work inward Java, One past times using hold off as well as notify method as well as other past times using BlockingQueue in Java.  later is slow to implement as well as a practiced selection if you lot are coding inward Java 5.

The fundamental points to mention, spell answering this query is thread-safety and blocking nature of BlockingQueue as well as how that helps, spell writing concurrent code. You tin too expression lots of follow-up questions including, what give off if you lot withdraw maintain multiple producer or multiple consumers, what volition give off if a producer is faster than consumer thread or vice-versa. You tin too come across this link for trial of how to code producer-consumer blueprint inward Java using blocking queue



8) Why is ConcurrentHashMap faster than Hashtable inward Java? (answer)
ConcurrentHashMap is introduced as an alternative of Hashtable inward Java 5, it is faster because of its design. ConcurrentHashMap divides the whole map into dissimilar segments as well as exclusively lock a particular segment during the update operation, instead of Hashtable, which locks whole Map.

The ConcurrentHashMap also provides lock-free read, which is non possible inward Hashtable, because of this as well as lock striping, ConcurrentHashMap is faster than Hashtable, especially when a number of the reader is to a greater extent than than the number of writers.

In lodge to improve reply this pop Java concurrency interview questions, I propose reading my postal service almost the internal working of ConcurrentHashMap inward Java.




9) What is the departure betwixt submit() as well as execute() method of Executor as well as ExecutorService inward Java? (answer)
The primary departure betwixt submit as well as execute method from ExecutorService interface is that one-time render a termination inward the shape of a Future object, spell afterward doesn't render a result. By the way, both are used to submit a chore to thread puddle inward Java but 1 is defined inward Executor interface,while other is added into ExecutorService interface. This multithreading interview query is too asked inward the commencement circular of Java interviews.


10) How do you lot percentage information betwixt ii threads inward Java? (answer)
One to a greater extent than Java multithreading query from the telephonic circular of interview. You tin percentage information betwixt thread past times using shared object or shared information structures similar Queue. Depending upon, what you lot are using, you lot demand to render the thread-safety guarantee, as well as 1 way of providing thread-safety is using synchronized keyword.

If you lot usage concurrent collection classes from Java v e.g. BlockingQueue, you lot tin easily percentage information without beingness bothered almost thread security as well as inter-thread communication. I similar this thread question, because of it's simplicity as well as effectiveness. This too leads farther follow-up questions on issues which arise due to sharing information betwixt threads e.g. race conditions.



11) What is ReentrantLock inward Java? Have you lot used it before? (answer)
ReentrantLock is an alternative of synchronized keyword inward Java, it is introduced to handgrip some of the limitations of synchronized keywords. Many concurrency utility classes as well as concurrent collection classes from Java 5, including ConcurrentHashMap uses ReentrantLock, to leverage optimization.

The ReentrantLock generally uses an atomic variable as well as faster CAS functioning to provides improve performance. Key points to advert are the difference betwixt ReentrantLock as well as synchronized keyword inward Java, which includes the mightiness to acquire lock interruptibly, timeout characteristic spell waiting for lock etc. ReentrantLock too gives the alternative to do fair lock inward Java.Once in 1 trial to a greater extent than a rattling practiced Java concurrency interview query for experienced Java programmers.
Books similar Java Programming Interview exposed too helps you lot to laid upward improve as well as reply to the point.

Java concurrency as well as thread interview questions answers Top 12  Java Thread, Concurrency as well as Multithreading Interview Questions For experienced



12) What is ReadWriteLock inward Java? What is the do goodness of using ReadWriteLock inward Java?(answer)
This is ordinarily a follow-up query of previous Java concurrency questions. The  ReadWriteLock is in 1 trial to a greater extent than based upon the concept of lock striping, 1 of the advance thread-safety machinery which advocates separating locks for reading as well as writing operations (see Java Concurrency inward Practice Bundle past times Heinz Kabutz for to a greater extent than details).

If you lot withdraw maintain noticed before, reading functioning tin travel done without locking if at that spot is no author as well as that tin hugely improve the performance of whatsoever application. The ReadWriteLock leverage this thought as well as render policies to allow maximum concurrency level. Java Concurrency API too provides an implementation of this concept as ReentrantReadWriteLock.

Depending upon Interviewer as well as sense of the candidate, you lot tin fifty-fifty expression to render your ain implementation of ReadWriteLock, thence travel laid upward for that as well.

Here is a prissy diagram which clearly explains working of read-write lock inward Java:

Java concurrency as well as thread interview questions answers Top 12  Java Thread, Concurrency as well as Multithreading Interview Questions For experienced



These were some of my favorite interview questions based on multithreading as well as concurrent inward Java. Threading as well as Concurrency is a big theme inward Java as well as has lots of interesting, tricky as well as tough question but for starters as well as freshers, these questions sure aid to clear whatsoever thread interview inward Java.

As I said, mentioning the fundamental points are rattling of import spell answering questions on multithreading as well as concurrency.  I too propose farther reading Java Concurrency inward Practice to larn to a greater extent than almost locking, synchronization, concurrent collections as well as concurrency utility classes to do good inward heart Java as well as multithreading interviews.

Further Learning
Multithreading as well as Parallel Computing inward Java
15 Technical Core Java Questions asked to Experienced Programmer on Interviews
Good Questions on Java Collection as well as Concurrent Collection amongst answers
Top 10 Java Design Pattern Questions as well as How to reply them
10 Spring MVC Interview Questions for Java Programmers
10 Java Enum Interview Questions Answers for beginners
Top 10 JDBC Interview Questions for Experienced Programmers
Top 10 RESTful Web Service Interview Questions as well as Answers