Disclosure: This article may contain affiliate links. When you purchase, we may earn a small commission.
Hello guys, if you are writing test for your your Spring Boot application
then Sooner or later, you'll come across @Mock and @MockBean annotations
while testing your Spring Boot application. Both annotations generate fake
or Mock objects, but for different reasons and its important for Java
and Spring Boot developer to know the correct difference and when to use
@Mock and @MockBean while writing tests. It's possible that this will seem
perplexing at first, in face I was confused for a long time until I did my
research and cleared it up. But, you don't need to scan through internet, In
this blog article, I'll clear up any misunderstandings and clarify the
difference between @Mock and @MockBean when testing Spring Boot apps.
Hello guys, if you re preparing for DevOps Engineer interviews and looking
for frequently asked DevOps Interview questions then you have come to the
right place. Earlier, I have shared the DevOps RoadMap, best DevOps Courses, and DevOps books and in this article, I will share the frequently asked DevOps
Interview Questions and their Answers. But, before we get to the most
frequently asked DevOps interview questions, let me tell you what DevOps
actually is. DevOps is basically a way of thinking or a collective approach to all the
tasks that a company's application development and IT operation teams
perform but it has taken the IT software development world by storm.
Hello guys, if you are preparing for Developer and DevOps interview and
looking for Linux questions for interviews then you have come to the right
place. Earlier, I have shared popular
UNIX Interview questions
and
DevOps Interview Questions
and in this article, I am going to share 20 common Linux questions from
interviews with Answers. These questions covers essential Linux commands like
Linux file system, permission model, Linux commands, shell and kernels etc. If
you have worked in Linux then you can easily answer these questions but if you
have forgot them then you can always join these
best Linux courses
to learn and revise key Linux concepts before interviews.
Hello guys, if you are wondering what is difference between State and Strategy pattern in Java then you are at the right place. In order to make proper use of State and Strategy design Patterns in any Java application, it's important for a Java developer to clearly understand the difference between them. Though both State and Strategy design patterns have a similar structure, and both of them are based upon the
Open closed design principle, which represents 'O' from
SOLID design principles, they are totally different on their
intent. The strategy design pattern in Java is used to encapsulate a related set of algorithms to provide runtime flexibility to the client.
Hello guys, if you want to learn about Decorator design pattern in Java then you are at the right place. I was thinking to write on decorator design pattern in Java when I first wrote 10 interview questions on Singleton Pattern in Java. Since design patterns are quite important while building software and it’s equally important on any Core Java Interview, It’s always good to have a clear understanding of various design patterns in Java. In this article, we will explore and learn the Decorator Design pattern in Java which is a prominent core Java design pattern and you can see a lot of its examples in JDK itself.
Data Access Object or DAO design pattern is a popular design pattern to implement the persistence layer of Java application. DAO pattern is based on
abstraction and
encapsulation design principles and shields the rest of the application from any change in the persistence layer e.g. change of database from
Oracle to
MySQL, change of persistence technology e.g. from File System to Database. For example, if you are authenticating the user using a relational database and later your company wants to use
LDAP to perform authentication. If you are using the
DAO design pattern to access the database, it would be relatively safe as you only need to make a change on Data Access Layer. DAO design pattern also keeps the coupling low between different parts of an application.
If you know how to use for loop in bash shell or Linux, you can speed up a
lot of task, saving precious time while doing support or troubleshooting in
Linux. One of my favorite use of for loop is repeating same task among
multiple host. For example, If I have to clean up some files from 10 hosts
in the network, instead of manually going and removing files from individual
host, you can use for loop and
ssh command
to automatically remove old log files from all the host, without manually
logging into them. This is a tremendous time saving trick if you are working
for an application which is running on more than one host. It's a life-saver
if your application is running on 30 to 40 hosts.
Hello guys, if you are wondering how to convert a Map like HashMap or TreeMap to a List like ArrayList or LinkedList in Java then you are at the right place. Earlier, I have shared 10 examples of converting a List to Map in Java and this article, I am going to share my tip to convert a given Map to a List in Java. Map and List are two common data structures available in Java and in this article, we will see how can we convert Map values or Map keys into List in Java. The primary difference between Map (HashMap, ConcurrentHashMap, or TreeMap) and List is that Map holds two objects key and value while List just holds one object which itself is a value.
Hello guys, it's been a long since I shared object-oriented design and
system design questions in this blog. It was almost 7 to 8 years when I last
blogged about
how to solve vending machine design problems in Java. Actually, I had ideas for lots of such design questions at that time, but
because of the lengthy nature of these kinds of posts and the amount of time
they take, they just sit on my list of drafts. I thought to take them out
and publish then slowly improve on them instead of publishing the perfect
post for the first time, and today, I am excited to share one of such
problems,
how to design a trade position aggregator in Java. This
program is like portfolio management software that monitors your risk and
exposure in real-time based on trades.
Hello guys, if you are preparing for DevOps Engineer interview or a Developer
interview, knowledge of
Kubernetes is very important given the rise of Cloud
computing and cloud native development. If you are looking for frequently
asked Kubernetes interview questions to quickly revise key Kubernetes concepts
then you have come to the right place. Earlier, I have shared
20 Docker Interview Questions
and in this article, I am going to share frequently asked Kubernetes Interview
questions with Answers. But, before we get to the 20 most important Kubernetes
interview questions, let me tell you more about Kubernetes. In the most simple
terms,
Kubernetes is actually a bundle of software solutions that allow
developers and engineers to scale and service server setups.
Hello guys, if you are wondering how to add an element at the start and at the end of a linked list in Java then you are at the right place. LinkedList is an implementation of
linked list data structure in Java and whenever you need a linked list you can use this. It also provides convenient methods to add elements like
addFirst() to add any element at the fist position and
addLast() to add element at the last position or tail of the linked list. Since LinkedList also implement List and Queue interface in Java, you can also use the common methods defined in the List and Queue interface to interact with LinkedList object in Java. In the past, I have also shared
how to sort a LinkedList in Java and in this article, I will teach how you can use LinkedList in Java and how you can add object at the head and tail position of a linked list in Java.
Hello guys, you might have read many articles about popular Linux commands on the internet but this article is a bit different. In this article, I am going to share some
lesser-known options of essential Linux commands like
find,
grep,
mkdir, etc, which many Linux users, including programmers, don't know, even after using the command for quite some time. For example,
cp -p is an option that I discovered quite late but ever since I discovered it I have been using it regularly as it preserve timestamp and I can see when this file was originally created. I am going to share
10 such Linux command examples in this post, which I am sure you will love it and if you already know them, then there is a good chance that you have something similar to share with us in the comments section.
The find command is one of the most versatile commands in UNIX and Linux, and I used it a lot in my day-to-day work. I believe having a good knowledge of find command in UNIX and understanding of its different options and usage will increase your productivity a lot in UNIX based operating systems, e.g. Redhat Linux or Solaris. If you are a QA, support personnel, and your works involve lots of searching text on Linux machine or if you are a Java or C++ programmer and your code resides in UNIX, find command can significantly help you to look for any word inside your source file in the absence of an IDE.
One of the most common tasks in any Linux is creating directories, and most of us spend a lot of time creating complex directory structures in UNIX and Linux. I am sure you know about the
mkdir command, we have been using this command in almost every operating system like DOS, Windows,
Linux, OS/2, Solaris, or any other *NIX operating system. It is one of the basic commands but as important as
find,
grep or
chmod.
mkdir stands for "make directory" and this command is literally used to create
directories. Suppose, you need to create a directory tree-like
/opt/software/java/app/config, how are you going to create these directories? One by one right? Well, yes you can use
mkdir and command to create these directories one by one as shown in below example :
One of my favorite Linux Interview questions is about
how to convert hostname to IP address in Linux? These questions not just test the candidate's basic Linux command skills but also shows his understanding of
how name resolution works in UNIX or Linux? Many developers, software engineers, and support professionals don't really know how Linux
converts a hostname into IP address or what happens when they type
http://www.amazon.com in their browser in UNIX? They are not really familiar with how the name
amazon.com is resolved to an IP address.
Deleting
empty file and directory in Unix
Hello guys, if you are wondering how to find and remove all empty files and directories from a Linux host then you are at the right place. Earlier, I have shared Linux command to free disk space by removing big files and directories and in this article, I will share find command you can use to remove empty files and directories. Many times we need to find and delete empty files or directories in UNIX/Linux.
Since there is no single command in Unix/Linux which allows you to remove empty
files or empty directories rather we need to rely on find
command and xargs
command.
Hello guys, 100% full disk space is a common problem and as a programmer or Linux user, you often need to free disk space by deleting biggest files and directories. In order to do that, you need to know some Linux find command examples to list and delete some biggest files and directories and that's what you will learn in this tutorial. As a
Java developer, you also need to also support your application, most of which mostly run on Linux machines. Though production is monitored by the dedicated support teams and they receive regular alerts on the status of file system space, they often come running to you or the developer responsible about what to do when disk space is almost full or reaching 100%.
The array was there in Java before the Collection framework makes its entry in JDK 1.4, hence, you will find several legacy codes, which accept an array then the
Collection or
Set. Due to this, we often need to convert an array to different types of collection e.g.
List or
Set. Earlier, I have told you the
trick to convert an array to a list and today I'll teach you how to
convert an array to HashSet by using the same technique. The concept you need to know is that Collection provides a
copy constructor i.e. you can pass a collection to create another collection. We'll leverage the same fact and to create a
HashSet, we'll pass an
ArrayList.
Hello guys, this is my first article in Java 9 features on this blog, and today you'll learn about my favorite feature
"factory methods for collection", which is introduced as part of JEP 269. The JEP stands for the JDK enhancement proposal. If you have worked in
Groovy or
Kotlin then you know that how easy is to create the list with elements using collection literals e.g. to create a list of 1, 2, 3 you can simply write
val items = listOf(1, 2, 3). Unfortunately, Java doesn't support that yet but things have been improved with the factory methods for collection in JDK 9 and it's almost like that. JDK has added
static factory methods like
of() on to basic Collection interfaces which you can use to create a list of items.
Hello guys, if you are wondering what is difference between HashMap, TreeMap, and LinkedHashMap in Java and when to use them then you are at the right place. In past, I have shared frequently asked
HashMap Interview questions and
ConcurrentHashMAp Interview questions and today, I Will answer this question in detail. The
java.util.Map is one of the most important interfaces from the Java Collection Framework. It provides hash table data structure functionality by its implementations like
HashMap,
Hashtable, LinkedHashMap, and a little bit of sorting with the
TreeMap. So if you are
looking to store key-value pairs in the Java program, you have a wide range of choices available depending upon your requirement. The main difference between LinkedHashMap, TreeMap, and HashMap comes in their internal implementation and specific features, which a Java programmer should know to use them effectively.
Hello Java programmers, if you are wondering how and when to use use the
@RequestBody and @ResponseBody annotation in Java then you are at the right
place. Earlier, I have shared
how to create RESTful Web Service using Spring Boot
and today I will teach you how and when to use these two crucial annotations
@RequestBody and @ResponseBody.
While developing client server Java application using Spring Framework you
may need to connect the HTTP request and response body with the domain
object while working on the REST API. The annotations @RequestBody and
@ResponseBody in Spring were used
to bind these HTTP requests and responses. In simple words, these are teh
annotations which converts JSON to your Java object and your data to JSON
while sending to client. Let's look at these two Spring annotations in more
detail.
There are multiple ways to iterate, traverse or loop through Map, HashMap, or TreeMap in Java and we are all familiar with either all of those or some of those. But to my surprise, one of my friends was asked in his interview (he has more than 6 years of experience in Java programming) to write code for getting values from HashMap, Hashtable, ConcurrentHashMap, or TreeMap in Java in at least 4 ways. Just like me he was also surprised by this question but written it. I don't know why exactly someone asks this kind of java interview question to a relatively senior java programmer. Though my closest guess is to verify that whether he is still hands-on with coding in java.
Hello guys, one of the common problems many Java developers working with HashMap face is
how to check if the Map contains a particular key or value? You can use this to check duplicate keys or just to ensure that you are not overriding the current value because if you insert a key that already exists in the HashMap, then you end up overriding its value. Since
HashMap also allows duplicate values, it's also possible that the same value may be paired against multiple keys, so just removing a mapping may not be enough to remove that particular value. Not paying attention to these details has actually caused issues in the Java applications.
It's not easy to get key from the value in Hashtable or HashMap, as compared to getting value from key because HashMap or Hashtable doesn't enforce one to one mapping between key and value inside Map in Java. in fact, Map allows the same value to be mapped to multiple keys inside HashMap, Hashtable, or any other Map implementation. What you have in your kitty is Hashtable.containsValue(String value) or Hashtable.containsKey(String key) to check whether key or value exists in HashMap or not, but sometimes we want to retrieve a value from Map corresponding to any key and there is no API method to do in Map.
HashSet in Java is a collection that implements the Set interface and is backed by a HashMap. Since HashSet uses HashMap internally it provides constant-time performance for operations like add, remove, contains and size give HashMap has distributed elements properly among the buckets. Java HashSet does not guarantee any insertion orders of the set but it allows null elements. HashSet can be used in place of ArrayList to store the object if you require no duplicate and don't care about insertion order.
Hello guys, if you are wondering what is differnece between an HashMap and IdentiyHashMap in Java then you are at right place. IdentityHashMap in Java was added in Java 1.4 but still, it's one of those lesser-known classes in Java. The main difference between IdentityHashMap and HashMap in Java is that IdentityHashMap is a special implementation of Map interface which doesn't use equals() and hashCode() method for comparing objects unlike other implementations of Map e.g. HashMap. Instead, IdentityHashMap uses the equality operator "==" to compare keys and values in Java which makes it faster compared to HashMap and suitable where you need reference equality check and instead of logical equality.
Java beginners often ask the same type of questions, and of them is
what is the difference between & and && operator in Java or the
difference between | and || operators? The standard answer to this question is well, the main difference between & and && is that the former is a
bitwise operator, and && is a
logical operator in Java. That's academic until you clearly explain the difference in working of & and && or | and ||. For absolute beginners, & is used to represent AND logic operation in Java and | is used to represent OR logic operation.
Hello guys, if you are wondering what is NavigableMap and why should Java developer know about it you are at right place. NavigableMap in Java is an extension of SortedMap like TreeMap
which provides convenient navigation methods like lowerKey, floorKey, ceilingKey, and higherKey. NavigableMap is added
on Java 1.6 and along with these popular navigation methods it also provides ways
to create a Sub Map from existing Map in
Java, like headMap whose keys are less than the specified key, tailMap whose keys are greater than
specified key and a subMap which strictly contains keys
that falls between toKey and fromKey.
One of the first question a graduate C or C++ programmer, who has just started learning Java ask is, whether Java is a compiled language or an interpreted one? On academic courses or during college, students learn a lot of languages like VB,
C,
C++ and they happily categories them as either compiled or interpreted, but with Java it's tricky. It's not clear whether Java is compiled or interpreted, because it neither generates machine language code after compiling a source file, neither interpreted source file to execute instruction line by line.
Serialization and SerialVersionUID always remain a puzzle for many Java developers. I often see questions like what is this SerialVersionUID, or what will happen if I don't declare SerialVersionUID in my
Serializable class? Apart from the complexity involved and rare use, one more reason for these questions is Eclipse IDE's warning against the absence of SerialVersionUID e.g.
"The Serializable class Customer does not declare a static final SerialVersionUID field of type long". In this article, you will not only learn the basics of Java SerialVersionUID but also its effect during the serialization and de-serialization process.
This is one of the interesting core Java questions which was asked to one of my readers recently during a
telephonic interview for a Java developer job interview. Even though he knows that you
cannot make an abstract class final in Java, he got confused by the wording of the methods. The answer is simple, No, it's not possible to have an abstract method in a final class in Java. Why? because as soon as you declare an abstract method in a Java class, the class automatically becomes an abstract class and you
cannot make an abstract class final in Java as discussed before, hence it's not possible to have an abstract method in a final class in Java.
Hello guys, ConcurrentLinkedDeque is another amazing class from Java's concurrent collection package which can be used as high-performance, thread-safe and non-blocking data structure. As the name suggest, its a Deque which means its allows you to operate at both ends of queue. You can insert at one end and consume from other end. It's also concurrent and thread-safe which means multiple threads can operate on same queue at the same time. You can have multiple producer threads which are inserting data into the queue and multiple consumer threads which are consuming data from this data structure.
I remember when I was doing my engineering, the OOPS concept was in the first semester. Back then it looks like some alien things to me, because I have never done programming and even the smallest program we get to write like checking whether the number is palindrome or not, or printing the Fibonacci series, we never really needed to use OOPS. When needed, I just memorize things and write them down in exams :). That worked, I passed the exam but effectively I didn't learn OOP or Object Oriented Programming on those days.
There are a lot of
differences between instance variable, class variable, and local variable in Java, and knowing them will help you to write correct and bug-free Java programs. Java is a full-featured programming language and provides different kinds of variables like
static variables also called
Class variable since it belongs to whole Class,
non-static also called
instance variable and
local variables which vary in scope and value. Thank god Java doesn't have any register variable or auto scope like
C Programming language, otherwise it would have so much detail to remember. static variables are a common source of error in may multi-threaded
java program and does require a bit of carefulness while using it. On the other hand instance, the variable and the local variable have less sharing visibility than a static variable.
OOP Interview questions or Object-oriented programming and design interview question are an integral part of any programming job interviews like
Java,
C++, or
C#. Since Java is an Object-oriented programming language, it's expected from Java developers that he is good at Object-oriented analysis and design and familiar with essential OOP concepts like
Abstraction,
Encapsulation, and
Polymorphism. Object-Oriented Programming Interview question in Java is mainly based around fundamental OOP concept and how those are implemented in Java, like Abstraction OOP concept is implemented using an interface and abstract class, Encapsulation is using private keyword, etc.
Both Stack and Queue are two of the crucial data structure which is very
useful in solving a lot of problems. They are not as fundamental data
structures as an
array or linked lists but they offer some unique advantages in terms of how you store and access
elements.
Stack is commonly known as
LIFO data structure because the last element you put is the first one
to come out while
Queue is known as
FIFO data structure. The
elements are retrieved from the queue in the order they were inserted. Both
of these data structure has several usages and are used to solve many common
problems and to implement algorithms.
Hibernate Interview Questions are asked on Java J2EE Interviews, mostly for web-based enterprise application development roles. The success and acceptability of Hibernate framework on the Java world have made it one of the most popular Objects Relational Mapping (ORM) solutions in the Java technology stack. Hibernate frees you from database-specific coding and allows you to focus more on utilizing powerful object-oriented design principles to implement core business logic. By using Hibernate you can switch between databases rather easily and also take advantage of out-of-box caching facilities provided by Hibernate, in terms of second-level cache and query cache.
Checked and Unchecked Exception is two types of Exception exist in Java. Though there is no difference in functionality and you can very achieve the same thing with either checked Exception or Unchecked Exception, there is some difference on exception handling part. In this Java tutorial we will see what is checked and Unchecked Exception in Java, Examples of Checked and Unchecked Exception and most importantly we will learn when to use Checked Exception and when to use Unchecked Exception in Java and lastly we will see the difference between checked and unchecked exception to understand things better.
"java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path" error comes when you try to connect to Oracle 11g database using OCI (thick) driver by using tns name, but the
ocijdbc11.dll file is not available in PATH or
java.library.path environment variable. ocijdbc11.dll is a native library and if you know Java searches native library in PATH or a location specified by
java.library.path system property, if it doesn't find the dll, then it throws
java.lang.unsatisfiedlinkerror no ocijdbc11 in java.library.path error. This dll is usually found in
C:\Programs\Oracle\ora11g\bin\ocijdbc11.dll, but it could vary depending upon your Oracle installation.
Spring Boot has a lot many
annotations within its framework that a person can use. If you are searching for one, you have come to the right place. Needless to say, these annotations are essential for building a Spring Boot web application. Today we will look at an annotation that is widely used for transaction management in spring. So, what's the wait?! Let's start! But, before jumping into the sea of spring, let's first understand what a transaction means in spring and what it signifies. A transaction is used in
Spring JPA which communicates to the database. we all know what a transaction represents on a database level. If not, no worries! let us all recall.
Virtual box is a great tool for Java developer to run Docker and Linux on Windows Machine, especiall for them who need to develop and debug Java program in Linux environment. I use Oracle's virtual machine, VirtualBox to run the Linux operating system from my Windows machine. It's the most simple way to have two operating systems on your laptop or PC. Since I run most of the Java programs in Linux, VirtualBox gives me a nice interface to run UNIX commands right from the Windows box. This blog post is about the mounting of a shared folder failed error in Oracle's Virtualbox VM. It was working fine the day before yesterday and now, after I restarted my virtual box and tried to mount my shared folder, I was greeted by this error: "/sbin/mount.vboxsf: mounting failed with the error: Protocol error".
How to fix Bad version number in the .class file
"java.lang.UnsupportedClassVersionError: Bad version number in .class file" is a common error in Java programming language which comes when you try to run a Java class file which was compiled by different version of Java compiler than then JRE version you are using to run it. In our last article, we discussed that how to resolve Java.lang.UnSupportedClassVersionError and found that it comes when a major and minor version of the class is not supported by Java virtual machine or JRE running the program. Though "java.lang.UnsupportedClassVersionError: Bad version number in .class file" is a little different than that of its manifestation and Cause, both are related to the mismatch in compiler javac and runtime java version.
One of the annoying error while overriding Java method in Eclipse IDE is must
override a superclass method error, This error is quite frequent when
importing Java projects and after so long, still I
haven't seen any permanent solution to it. Must override a superclass method the error comes in Eclipse if you have Java Class that implements
interface and overrides a method from
interface and uses @Override annotation.
Unfortunately, Eclipse defaults to Java 1.5, which only recognize @Override annotation
for the overriding method from the superclass and not from the interface.
If you are like many Java developer who uses Maven and Eclipse to build Java project using
M2Eclipse plugin, you might have seen this error before. I ran into it recently when I ran the Maven Install command for one of the Java projects, configured as Maven project, only to realize that Maven builds failed after throwing this error. The main reason for this error is that Maven is not able to find
javac (the Java compiler) which is required to compile Java source files. If you remember, the
javac command comes in the bin directory of JDK, hence, you need a JDK installation in your local machine to compile the Java project.
"java.sql.SQLException: Invalid column index" is a frequent error while working in Java Database Connectivity (JDBC). As the name suggests "Invalid column index" its related to accessing or setting column in your SQL Query using prepared statement in Java. I have seen "java.sql.SQLException: Invalid column index" coming mostly due to two reason:
1) Setting column data using setXXXX(int coloumIndex) e.g. setInt(0) setString(0)
2) Getting column data using getXXX(int columnIndex) e.g. getInt(0) getString(0)
The most common cause of "java.sql.SQLException: Invalid column index" is a misconception that column index started with "0" like array or String index but that's not true instead column index starts with "1" so whenever you try to get or Set column data with column index "0" you will get "java.sql.SQLException: Invalid column index".
In this blog post of the FIX protocol tutorial series I would like to share my experience with connectivity issues around Fix Engines. to exchange messages or say to trade electronically clients connect to the broker using FIX protocol and for that, they use FIX Engine. In FIX protocol connection between two FIX Engines is refereed as FIX Session and we normally say whether FIX Session is connected or not connected. FIX Session normally has their start time, end time, and EOD time (End of day time) also called TradingSession start time, Trading Session End Time, and Trading Session EOD time.
The error message clearly says that the Java runtime is not able to find a class called
ServletContainer for the Jersey library. This is the Servlet class you have specified in the deployment descriptor of your application. It's similar to
DispatcherServlet of Spring MVC and this error is similar to the
error you get when DisplayServlet was not in the classpath.
Anyway,
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer comes when you are trying to use Jersey but have not added required dependency on your classpath e.g. those JAR files which contain the class "com.sun.jersey.spi.container.servlet.ServletContainer".
You might have seen the
java.net.SocketException: Failed to read from SocketChannel: Connection reset by peer error while working with
Java NIO based server which is using SocketChannel instead of InputStream for reading data from the network. In general, this can come at both client and server end of a client-server Java application which is using TCP/IP to connect each other. Though this exception usually comes at the server end and the client was complaining that they are not able to connect.
Hello guys, if you are getting java.lang.OutOfMemoryError: GC overhead limit exceeded Error in your Java application and wondering how to solve this then read on. As suggested by Java virtual machine, java.lang.OutOfMemoryError: GC overhead limit exceeded error comes when JVM breached GG overhead limit; which means your application is spending too much of garbage collection time without freeing any meaningful space. Currently Java's HotSpot virtual machine throws "java.lang.OutOfMemoryError: GC overhead limit exceeded" when 98% of total time is spent in the garbage collection and less than 2% of heap memory is recovered. Now let's find out what are symptoms of this error? Before this out of memory error comes you will see very slow or hung Java application with high CPU usage, because your application is only doing GC.
Most of the Java interview questions on ArrayList asked freshers or Java developers with 1 to 2 years experience is just simply how to do tasks like how to sort ArrayList in Java,
How to sort ArrayList in ascending and descending order, how to sort ArrayList on reverse order, how to search elements, how to remove an element using iterator etc. Since, I have written lots of Java tutorials on ArrayList, covering many general-purpose tasks like how to create an object of ArrayList and initialize to how to sort ArrayList in ascending and descending order, etc.
Many times we want to reset an ArrayList for the reusing purpose, by resetting we mean clearing it or removing all elements. There are two ways to
reset an ArrayList in Java, by using the
clear() method or calling
removeAll(). If your ArrayList is small enough like it contains only 10 or 100 elements then you can use any of these two methods without worrying too much, but, if you have a huge list of lots of objects like an ArrayList containing 10M entries, then the choice of
clear() vs
removeAll() can make a huge difference in the performance of your Java application.
Looping ArrayList in Java or Iteration over ArrayList is very similar to a looping Map in Java. In order to loop ArrayList in Java, we can use either foreach loop, simple for loop, or Java Iterator from ArrayList. We have already touched iterating ArrayList in 10 Example of ArrayList in Java and we will see here in detail. We are going to see examples of all three approaches in this ArrayList tutorial and find out which one is clean and the best method of looping ArrayList in Java. Before start writing an example for loop in ArrayList let's think about why do we need to iterate, traverse or loop an ArrayList if it’s based on the index and backed by Array.
Hello guys, if you want to become a frontend or backend developer in 2022 and looking for a well structured, reputed, and completely online program then
Meta's Frontend and Backend developer certificates on Coursera are great place to start with. The Certifications will come from Meta, parent company of Facebook (similar to how the Certificates come from Google in the Google Professional Certificates) and they are t
aught by expert Software engineers of Meta. This means you will not only learn the latest tech skills which are highly looked after by employers but also you will get a chance to learn from best people in the world. But, what separate this professional certificate on Coursera form others is the access to
Meta Job board.
Hello there, if you are wondering what is the difference between a list and an array, or particularly an ArrayList and an Array in Java then you have come to the right place. Earlier, I have shared the
best data structure and algorithm courses and in this article, I will explain to you the differences and similarities between a list and an array in Java. Both array and ArrayList are two important data structures in Java and frequently used in Java programs. Even though
ArrayList is internally backed by an array, knowing the
difference between an array and an ArrayList in Java is critical for becoming a good Java developer. If you know the similarity and differences, you can judiciously decide
when to use an array over an ArrayList or vice-versa.