How to Find IP address of Localhost, Server or Your Machine

In today's Java programming tutorial, we will learn some networking basics by exploring package. One of the simple Java network programming exercise, yet very useful, is to write a program to find IP address of the local host in Java. Sometimes this question also asked as find IP address of Server on which your Java program is running or find IP address of your machine using Java etc. In short, they all refer to localhost. For those who are entirely new in networking space, there are two things to identify a machine in a network, which could be LAN, WAN or The Internet. First thing is DNS name and the second thing is IP address. In Local Area Network, DNS is more generally replaced by hostname, which could be as simple as ReportingServer to or something else.

7 Common Socket Errors and Exception in Java Application [Solved]

In this blog, I plan to talk about some common exceptions and errors that arise while using sockets. Quite often, these socket issues arise out of application bugs, system settings or system load. It might be an unnecessary delay to go to product teams, only to discover that the issue can be resolved by tuning/configuring your local settings. Understanding these messages will not only help resolve the issues but also make a conscious effort in avoiding these scenarios while developing applications.

How to Compare String by their length in Java?

One of the common programming tasks is to compare String, sometimes by their value and sometimes by their length. The natural way to compare String is the lexicographic way, which is implemented in the compareTo() method of String class, but sometimes you need to compare String by their length. You cannot use the default compareTo() method for that task, you need to write your own custom Comparator, which can compare String by length. Don't worry, It's easy to compare multiple String by their length, all you need to do is write a Comparator implementation which calculates their length using the length() method and compares them.

Difference between include directive, include action and JSTL import tag in JSP?

There are three main ways to include the content of one JSP into another:

include directive

JSP include action

and JSTL import tag

The include directive provides static inclusion. It ads content of the resource specified by its file attribute, which could be HTML, JSP or any other resource at translation time.

Any change you make in the file to be included after JSP is translated will not be picked up by include directive.

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 database from Java and get some result back by executing some SELECT queries. In this Java program, we will learn How to connect to MySQL database from Java program and execute a query against it. I choose MySQL database because it's free and easy to install and setup. 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. Another advantage of using MySQL database is that it provides type 4 JDBC driver bundled in mysql-connector-java-5.1.17-bin.jar which is easy to use. By the way, if you are using Oracle database then you can check Java program to connect Oracle database, to connect and run SQL queries against Oracle DB.