How to Fix with java.net.SocketException: Connection reset Exception in Java? Examples

Hello guys, for the past few months, I have been writing about different socket-related errors on Java applications, and today I am going to talk about another common socket-related exception in Java -  java.net.SocketException: Connection reset Exception. There is no difference between exceptions thrown by the client and server. This is also very similar to the java.net.SocketException: Failed to read from SocketChannel: Connection reset by a peer but there is some subtle difference. The difference between connection reset and connection reset by peer is that the first means that your side reset the connection, the second means the peer did it. Nothing to do with clients and servers whatsoever

Top 5 Java EE Mistakes Java Web Developers should Avoid - Example

Hello guys, if you are working in Java EE and creating web applications and enterprise applications then you know that it's not as easy as it looks. You need to know some internal quirks so that your application can work properly in Production. Earlier, I have shared the free courses to learn full-stack Java development, and today, I am going to talk about some coding practices that you should avoid while creating Java web applications or Java EE applications. This will save you a lot of headaches when your application will go live and run in production. 

How to Convert a LinkedList to an Array in Java? Example

You can convert a LinkedList to an array in Java by using the toArray() method of the java.util.LinkedList class. The toArray() method accepts an array of relevant type to store contents of LinkedList. It stores the elements in the array in the same order they are currently inside the LinkedList. By using the toArray() method you can convert any type of LinkedList e.g. Integer, String or Float to any type of Array, only catch is this you cannot convert a LinkedList to an array of primitives i.e. a LinkedList of Integer cannot be converted into an array of ints by using toArray() method, but you can convert it to an array of Integer objects, that's perfectly Ok.

How to convert int array to ArrayList of Integer in Java 8? [Example/Tutorial]

I once asked this question to one of the Java developers during an Interview and like many others, he answered that Arrays.asList() can convert an array of primitive integer values to ArrayList<Integer> in Java, which was actually wrong. Even though, Arrays.asList() is the go-to method to convert an Array to ArrayList in Java when it comes to converting a primitive array to ArrayList, this method is not useful. The Arrays.asList() method does not deal with boxing and it will just create a List<int[]> which is not what you want. In fact, there was no shortcut to convert an int[] to ArrayList<Integer> or long[] to ArrayList<Long> till Java 8.

How to use Callable Statement in Java to call Stored Procedure? JDBC Example

The CallableStatement of JDBC API is used to call a stored procedure from Java Program. Calling a stored procedure follows the same pattern as creating PreparedStatment and then executing it. You first need to create a database connection by supplying all the relevant details e.g. database URL, which comprise JDBC protocol and hostname, username, and password. Make sure your JDBC URL is acceptable by the JDBC driver you are using to connect to the database. Every database vendor uses a different JDBC URL and they have different driver JAR which must be in your classpath before you can run the stored procedure from Java Program.

JDBC - How to connect MySQL database from Java program with Example

When you start learning JDBC in Java, the first program you want to execute is connected to a database from Java and get some results back by executing some SELECT queries. In this Java program, we will learn How to connect to the MySQL database from the Java program and execute a query against it. I choose the MySQL database because it's free and easy to install and set up. If you are using Netbeans IDE then you can connect MySQL Server directly from Netbeans, Which means in one window you could be writing Java code, and other you can write SQL queries.

JDBC - How to connect Eclipse to Oracle Database - Step by Step Guide Example

Though I prefer Toad or Oracle SQL Developer tool to connect Oracle database, sometimes it's useful to directly connect Eclipse to Oracle using JDBC using its Data Source Explorer view. This means you can view data, run SQL queries to the Oracle database right from your Eclipse window. This will save a lot of time wasted during switching between Toad and Eclipse or Oracle SQL Developer and Eclipse. Eclipse also allows you to view the Execution plan in both text and Graphical mode, which you can use to troubleshoot the performance of your SQL queries.

How to Convert Hostname to IP Address in Java - InetAddress Example

Hello guys, today, I am going to teach you about one interesting class from java.net package, the InetAddress. If you have never used this class before, let me tell you that it's an abstraction to represent an Internet address and it encapsulates both hostname and IP address. Since converting an IP address to hostname or hostname to IP address is a very common requirement, Java developers should know about this class, and, in general about java.net package, which contains many other useful class for networking and client-server applications. So, what is the best way to learn new APIs like java.net? Well, by writing small programs like this, which has a small focus and let you explore things. They are super useful and that's how I have learned the majority of Java API.

How to Run External Program, Command Prompt, and Batch files from Eclipse Console ? Example Tips

Hello guys, have you ever thought about how much time a Java developer spends on Eclipse, IntelliJ IDEA, or his favorite IDE? I guess most of his time, isn't it would be great to do as much as work possible from Eclipse itself, without switching to another application. Since switching between applications or programs requires some time, which is generally gone waste, I like to use Eclipse as much as possible, starting from coding in Java, executing Java programs to exploring XML files, and now even running the batch command from Eclipse. 

20+ JMS Interview Questions and Answers for Java Programmers

Java Messaging Service or JMS interview questions is one of the important parts of any Core Java or J2EE interview as messaging is a key aspect of enterprise Java development. JMS is a popular open-source Messaging API and various vendors like Apache Active MQ, Websphere MQ, Sonic MQ provide an implementation of Java messaging API or JMS. Any Java messaging services or JMS interview can be divided into two parts where the first part focuses on fundamentals of JMS API and messaging concepts like What is a topic, What is Queue, publish-subscribe or point to point model, etc, While the second part is related to JMS experience with particular JMS provider.

How to Fix java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver [Solved]

Scenario : Your Java program, either standalone or Java web application is trying to connect to Oracle database using type 4 JDBC thin driver "oracle.jdbc.driver.oracledriver", JVM is not able to find this class at runtime. This JAR comes in ojdbc6.jar or ojdbc6_g.jar which is most probably not available in classpath.

Cause : When you connect to Oracle database from Java program, your program loads the implementation of Driver interface provided by the database vendor using class.forName() method, which throws ClassNotFoundException when driver class is not found in classpath. In case of Oracle the driver implementation is oracle.jdbc.driver.oracledriver and "java.lang.classnotfoundexception oracle.jdbc.driver.oracledriver" error indicate that this class is  not available in classpath. Since this class is bundled into ojdbc6.jar, its usually the case of this JAR not present in Classpath

How to Set Specific Java Version for Maven in Windows? Example Steps

Maven is a great build tool and most of the Java developer uses Maven to build their projects, but like any other tool, there are some intricacies which you need to know while using it. One of them is that Maven uses the Java version from the JAVA_HOME environment variable and not the PATH environment variable. If you have multiple JDK installed on your machine and getting an Unsupported major.minor version 51.0 or Unsupported major.minor version 52.0 error while building your project but have right Java version in PATH then you may need to check the JAVA_HOME and update it. If you don't have access to do it then you can still change JAVA_HOME using the set command in your local shell and run the Maven's mvn command to build the project

Difference between WHERE and HAVING clause in SQL? Example

The main difference between the WHERE and HAVING clauses comes when used together with the GROUP BY clause. In that case, WHERE is used to filter rows before grouping, and HAVING is used to exclude records after grouping. This is the most important difference, and if you remember this, it will help you write better SQL queries. This is also one of the important SQL concepts to understand, not just from an interview perspective but also from a day-to-day use perspective. I am sure you have used the WHERE clause because it's one of the most common clauses in SQL along with SELECT and used to specify filtering criteria or conditions.

Google Data Analytics Professional Certificate Review

 Data analysis is almost the same as data science. Still, it deals less with machine learning and artificial intelligence and focuses more on generating insight into the company data by connecting patterns and trends with the company goal. The concept of data analysis is not actually new, and people are using this science hundred of years ago, but the concept becomes famous when computers come to life in the last decade.

Data analytics helps marketers and companies understand their customer’s behavior, so they can decide what’s good offers to drive to them and transform the education, healthcare industry, and many more, to name a few. Learning data science is not that hard since you will not understand many programming languages or deal with artificial intelligence.

Hence, if you plan to have these skills in under six months, you should probably take this program called Google Data Analytics Professional Certificate offered by Google through the Coursera platform.

1. The Instructors Review

This specialization offers by an initiative called Grow With Google, which last collaborates with different schools, universities, and organizations to launch courses that teach people digital skills such as programming, marketing, data analysis, and more. They have gained millions of students worldwide since 2017, which is the year this initiative has come to live.

2. Course Content

2.1. Foundations: Data, Data, Everywhere

This first section will teach you how data analysis uses data analytics to make decisions for their companies and how analytical thinking can drive decision-making. Later you will learn about the data phases and tools used by data analytics and exploring some of the tools used by data analytics, such as SQL and spreadsheets. Finally, learn the specific job that these people do for their businesses.

2.2. Ask Questions to Make Data-Driven Decisions

Before you analyze your data, you have to ask some questions that you have to answer by analyzing your data to learn the common analysis challenges and how to address them. Next, you will explore all kinds of data you will face during your journey in the data analysis and share this through reports and dashboards and explore how data analysis uses spreadsheets in their daily routine.

2.3. Prepare Data for Exploration

You will start by learning how people generate their data and how you, as a data analyst, will decide which data to collect for your analysis. You will also learn how to identify the different bases in your data and extract data from the database. Finally, you will learn how the organization keeps the data safe and secure.

2.4. Process Data from Dirty to Clean

You will learn why data integrity is so important for successful decision-making and discovering the different data structures. Before you start analyzing data, you have to clean it first, so this section will teach you the different tools used to clean the data, such as using SQL language. Finally, you will find out the process of verifying and reporting data cleaning.

2.5. Analyze Data to Answer Questions

You will begin by understanding the importance of organizing the data and how to achieve this using spreadsheet and SQL language. Next, you will also learn how to convert and format your data using SQL language. Later, you will see how to combine data from multiple database tables and perform data calculations using SQL and spreadsheets.

2.6. Share Data Through the Art of Visualization

Before you start making visualization of your data, you first learn the key concepts like design thinking that play an important role in data visualization. Also, you will start exploring Tableau for data visualization and make some simple visualization and learn how to develop presentations and slideshows.

2.7. Data Analysis with R Programming

Starting this section by discovering the R programming language that is used for data analysis and how to use its IDE called R studio. Next, you will start learning the concepts of the R language and how to use its functions and also apply these functions to data for analysis purposes. Later, you will gain some knowledge of data visualization using the R language.

2.8. Google Data Analytics Capstone

This last section will allow you to showcase your skills to your employee after completing this specialization by choosing an analytics-based scenario and asking questions about the problem you are trying to solve, preparing the data, analyzing them, and visualizing the final result.

Conclusion

Data analysis is one of the best skills to have if you will be a data scientist or even going to create your own company since this will help you understand your market size and however you are going to solve this problem.

Difference between == and === Equal Operator in JavaScript

In one of the recent JavaScript interview for a Java web development position, one of my readers was asked this questions, What is the difference between comparing variables in JavaScript using "==" and "===" operator?  My reader got shocked because he was from Java background and doesn't have great exposure to JavaScript, though he was pretty much familiar with some JavaScript function, event handling, and some jQuery tricks, he wasn't aware of subtle details of JavaScript. He did the right think, politely said that he is not aware of the difference between == and === operator. Though It did not affect his interview performance much, he was keen to know about this as soon as he finished his interview. He asked to me as well, and that's the reason of this post. 

Top 50 Servlet and Filter Interview Questions Answers for Java/JEE developers

Hello Java web developers, if you are preparing for Java Developer interviews and want to prepare Servlet, one of the cores of Java web technology and the backbone of many popular MVC frameworks in the Java world like Spring and Struts then you have come to the right place. Earlier, I have shared free Servlet and JSP courses and in this article, we'll discuss some of the frequently asked, simple, and difficult Servlet interview questions from telephonic interviews of Java web development roles. The list includes frequently asked Servlet questions on key concepts like Servlet life cycle, how Servlet works in Tomcat or a web container, Servlet 3 annotations, Filters, Listeners, and how to customize initialization of Servlet. 

How to use jQuery First time? HelloWorld Example

What is jQuery
jQuery is nothing but a JavaScript library that comes with rich functionalities. It's small and faster than many JavaScript codes written by an average web developer. By using jQuery we can write less code and do more things, it makes web developer's tasks very easy. In simple words, jQuery is a collection of several useful methods, which can be used to accomplish many common tasks in JavaScript. A couple of lines of jQuery code can do things that need too many JavaScript lines to accomplish. The true power of jQuery comes from its CSS-like selector, which allows it to select any element from DOM and modify, update or manipulate it. 

When to use notify() and notifyAll() in Java

As a programmer, you must not rely on any particular selection algorithm or treatment of priorities, at least if you are trying to write a Java program that is platform-independent. For example, because you don't know what order threads in the wait set will be chosen for resurrection by the notify command, you should use notify (as opposed to notify all) only when you are absolutely certain there will only be one thread suspended in the wait set. If there is a chance more than one thread will be suspended in the wait set at any one time, you should probably use notify all.

Otherwise, on some Java virtual machine implementations, a particular thread may be stuck in the wait set for a very long time. If a notify always selects the most recent arrival from the wait set and the wait set always contains multiple threads, some threads that have been waiting the longest may never be resurrected.

2 Ways to test Exception in JUnit : Annotation vs try-catch

Error handling is a core part of coding but most of the time it just went under the radar when it comes to unit testing. How do we write a JUnit test that verifies that an exception is thrown? With the try-catch construct, of course, except that this time, the code throwing an exception is a good thing—the expected behavior. The approach shown in the below code is a common pattern for testing exception-throwing behavior with JUnit.

3 Best books to prepare OCAJP 7 (1Z0- 803) Exam - Java SE 7 Certification

Even though the latest OCAJP exam is OCAJP8, the OCAJP7 still the most popular one, at least from the email I receive, I can say that more readers ask for OCAJP7 recommendations and preparation tips than OCAJP8. I have always said the three golden rules of success in the OCAJP exam are selecting a good book, writing programs, and doing mock exams like Whizlabs or Enthuware practice tests. In this article, you will find some good OCAJP7 books to deal with the first part. For those, who are new to the structure of Java SE 7 certification, it's now divided into two parts, the OCAJP and OCPJP. The OCAJP stands for Oracle Certified Associate Java Programmer and it's an associate-level exam.