Java TCP/IP Sockets

TCP/IP (Transmission Control Protocol/ Internet Protocol) is the protocol of the internet used to interconnect hosts. TCP/IP  provides reliable communication between 2 end points. This article provides an introduction to work with TCP/IP Sockets using Java. A Socket is an end point of communication flow and is a combination of IP address and a port …

Java TCP/IP Sockets Read More »

Java URL and URLConnection

Java Networking APIs provide a set of classes to interact with the internet. The primary classes include URL, URLConnection and HttpURLConnection. This tutorial provides examples to construct URLs and to access internet resources.  Read properties of URL URL represents the Uniform Resource Locator a resource on the world wide web.  URL url1 = new URL(“http”, …

Java URL and URLConnection Read More »

Java Annotations

Annotations is a form of meta-data to the Java code and doesn’t directly impact the behavior of the code. This article covers key concepts around annotations in Java with examples. Basic format of Annotation The at sign @ indicates start of annotation. In the example below we use an annotation @SuppressWarnings with value of “deprecation”. …

Java Annotations Read More »

JDBC handling transactions

Transaction is a set of one or more statements executed as a unit. The intent is that multiple statements which are part of a unit are executed together to make it meaningful. This article provides a quick introduction to handling transactions in JDBC. Here are some key points to remember when dealing with transactions using …

JDBC handling transactions Read More »

JDBC Database Access Examples

This article provides a list of key examples which we would commonly encounter when implementing a Java application requiring database access. For purpose of these examples the assumption is that PostgreSQL database is already setup and necessary database driver is downloaded and added to the CLASSPATH. Refer to this article JDBC Quick Start for a quick introduction …

JDBC Database Access Examples Read More »

Generics in Java

Generics is a key element in the Java programming language and a solid understanding is essential for any Java programmer. This article provides an introduction to the concepts around Generics in Java. Generics Introduction Generics provide the ability to create classes, methods and interfaces to be used with different types of data in a type-safe …

Generics in Java Read More »

Synchronization in Java

Understanding Synchronization In a multi-threaded program, when 2 or more threads try to access a common resource there needs to be a way to ensure that only one thread uses the resource at a time. The process by which this is achieved is called synchronization. Java provides language constructs to achieve using synchronized keyword. To …

Synchronization in Java Read More »

Enum Types in Java

Enum type enables a variable to be set with predefined constants. Examples include days of week, directions etc. In Java Enum type is defined using the keyword enum. In Java Enum types are treated as class types and they are more powerful than other languages. Enum types can have constructor, instance variables and methods. One …

Enum Types in Java Read More »

Approaches to create threads

There are 2 approaches to create threads in Java either using a Runnable object or to Subclass Thread. Runnable object In this approach, the class implements Runnable interface which defines a single method run. The Runnable object is passed to the thread constructor. Using the Runnable object is the most general approach because the Runnable …

Approaches to create threads Read More »

Java String introduction

This article provides a brief introduction to essential aspects of String type in Java with examples.  String class In Java, String is not implemented as character arrays as in other programming languages. Instead string is implemented as instance of String class. Strings are constants/ immutable and their values cannot be changed after they are created. …

Java String introduction Read More »