Java

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 »

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 »

Java is pass by value

Is Java pass by value (or) pass by reference is often a topic of confusion. This article clarifies with simple examples. Java is always pass by value. Primitive data type arguments like int or double are passed into methods by value. Any changes to the value of the parameters is limited to the scope of …

Java is pass by value Read More »

Java Interview Questions

This article contains common java interview questions and answers and is essential to have a clear understanding of these before taking up any java interview. What is autoboxing and auto-unboxing? Autoboxing is the process of automatically encapsulating a primitive data type into its equivalent wrapper object avoiding the need for explicit construction. e.g.) Here we …

Java Interview Questions Read More »

Approaches to write files in Java

This article describes some of the common approaches to write files in Java. Using OutputStreamWriter with a BufferedReader Refer the example function below. FileOutputStream is the byte stream here capable of writing raw bytes to the file. OutputStreamWriter is a bridge which converts characters into raw bytes using the specified charset. The OutputStreamWriter is a …

Approaches to write files in Java Read More »

JDBC Quick Start

This article provides a quick introduction to JDBC (Java Database Connectivity) API. The JDBC API enables a Java application to connect to a database, send queries to the database and process the results received in a database query. For the purpose of this tutorial let us use PostgreSQL database. PostgreSQL is an open source object-relational …

JDBC Quick Start Read More »

Java 7 try-with-resources

Java 7 has introduced try-with-resources statement which ensures that resources (files or socket handles) declared in the statement are closed at the end of the statement. All objects implementing java.lang.AutoCloseable (AutoCloseable) can be used as a resource. Usage of try-with-resources ensures release of resources which otherwise would cause resource exhaustion and exceptions. Prior to Java …

Java 7 try-with-resources Read More »

Using Regular Expression in Java

This article provides an introduction to usage of regular expressions in Java with some examples.Regular Expression or Regex in the computing terms refers to a sequence of symbols and characters expressing a string or pattern to be searched within a longer piece of text. There is a different syntax to regular expressions beyond the Java …

Using Regular Expression in Java Read More »

Approaches to read files in Java

This article describes some of the common approaches to read files in Java. Using InputStreamReader with a BufferedReader Refer the example function below. FileInputStream is the byte stream here reading raw bytes from the file. InputStreamReader is a bridge which converts the raw bytes into characters using the specified charset. The InputStreamReader is a unbuffered …

Approaches to read files in Java Read More »