Category Archives: Java

Encapsulation in Java

Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates.Other way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield. Technically in encapsulation, the variables… Read More »

Basic Operators in Java

Java provides a rich operator environment. We can classify the basic operators in java in following groups: Arithmetic Operators Relational Operators Bitwise Operators Assignment Operators Logical Operators Let us now learn about each of these operators in details. Arithmetic Operators: Arithmetic operators are used to perform arithmetic/mathematical operations on operands. Addition (‘+’) :  Adds two… Read More »

Method and Block Synchronization in Java

Threads communicate primarily by sharing access to fields and the objects reference fields refer to. This form of communication is extremely efficient, but makes two kinds of errors possible: thread interference and memory consistency errors. Some synchronization constructs are needed to prevent these errors. Following example shows a situation where we need synchronization. Need of… Read More »

Access Modifiers in Java

As the name suggests access modifiers in Java helps to restrict the scope of a class, constructor , variable , method or data member. There are four types of access modifiers available in java: Default – No keyword required Private Protected Public Default: When no access modifier is specified for a class , method or… Read More »

Classes and Objects in Java

Classes and Objects are basic concepts of Object Oriented Programming which revolve around the real life entities. Class A class is a user defined blueprint or prototype from which objects are created.  It represents the set of properties or methods that are common to all objects of one type. In general, class declarations can include… Read More »

Beginning Java programming with Hello World Example

The process of Java programming can be simplified in three steps: Create the program by typing it into a text editor and saving it to a file – HelloWorld.java. Compile it by typing “javac HelloWorld.java” in the terminal window. Execute (or run) it by typing “java HelloWorld” in the terminal window. Below given  program is… Read More »

Java.io.ObjectInputStream Class in Java | Set 2

Java.io.ObjectInputStream Class in Java | Set 1 Note : Java codes mentioned in this article won’t run on Online IDE as the file used in the code doesn’t exists online. So, to verify the working of the codes, you can copy them to your System and can run it over there. More Methods of ObjectInputStream… Read More »

Setting up the environment in Java

Java is a general-purpose computer programming language that is concurrent, class-based, object-oriented etc. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.The latest version is Java 8. Below are the environment settings for both Linux and Windows. JVM, JRE and JDK  all three are platform… Read More »

Variables in Java

A variable is the name given to a memory location. It is the basic unit of storage in a program. The value stored in a variable can be changed during program execution. A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. In… Read More »

Custom ArrayList in Java

Prerequisite – ArrayList in Java ArrayList in Java (equivalent to vector in C++) having dynamic size. It can be shrinked or expanded based on size. ArrayList is a part of collection framework and is present in java.util package. An ArrayList: ArrayList <E> list = new ArrayList <> (); E here represents an object datatype e.g.… Read More »

Java.io.ObjectInputStream Class in Java | Set 1

ObjectInputStream Class deserializes the primitive data and objects previously written by ObjectOutputStream. Both ObjectOutputStream and ObjectInputStream are used as it provides storage for graphs of object. It ensures that the object it is working for, matches the classes of JVM i.e Java Virtual Machine. Only those Object can be read from the streams that supports… Read More »