JAVA

HashSet | Java

Introduction HashSet is implementation of Set interface. Important points about HashSet class are: Stores the elements using hashing. It doesn’t maintain any order, the elements would be returned in any random order. It doesn’t allow duplicates. If you try to add a duplicate element in HashSet, the old value would [...]

2019-11-27T16:18:31+05:30Categories: Programming|Tags: |

HashMap with Example in Java

Introduction HashMap in Java is a Map based collection class that is used for storing Key & value pairs, it is denoted as HashMap<K, V>. It is similar to the Hashtable class except that it is unsynchronized and permits nulls (null values and null key). It is not an ordered [...]

2020-05-11T16:16:49+05:30Categories: Programming|Tags: , |

Abstract class | Java

Abstract Class An abstract class can have abstract method without body and it can have methods with implementation also. abstract keyword is used to create a abstract class and method. Abstract class can’t be instantiated. It is mostly used to provide base for subclasses to extend and implement the abstract [...]

2019-01-27T20:14:08+05:30Categories: Programming|Tags: |

Java Synchronized Blocks

Synchronized blocks in Java are marked with the synchronized keyword. All synchronized blocks synchronized on the same object can only have one thread executing inside them at the same time. All other threads attempting to enter the synchronized block are blocked until the thread inside the synchronized block exits the block. [...]

2019-08-16T15:53:44+05:30Categories: Programming|Tags: |

Volatile Keyword | Java

Introduction Volatile keyword is used to mark a variable as "being stored in main memory". Every read of a volatile variable will be read from the computer's main memory, and not from the CPU cache, and that every write to a volatile variable will be written to main memory. In [...]

2019-11-22T22:44:24+05:30Categories: Programming|Tags: |

Arbitrary number of arguments | Java

Varargs (short name for variable arguments) is used to pass an arbitrary number of values to a method. You use varargs when you don't know how many of a particular type of argument will be passed to the method. To use varargs, follow the type of the last parameter by [...]

2019-02-23T16:53:29+05:30Categories: Programming|Tags: |

Write int to text file using BufferedWriter

BufferedWriter.write(int) is meant to write a single charecter, not a integer. public void write(int c) throws IOException Writes a single character. Overrides: write in class Writer Parameters:c - int specifying a character to be written Throws:IOException - If an I/O error occurs So to write integer in file, use one of the following wr.write("123"); wr.write(new [...]

2017-07-30T20:26:56+05:30Categories: Programming|Tags: |

Write to File | Java

FileWriter, BufferedWriter, Files and FileOutputStream can be used to write file. FileWriter: FileWriter is the simplest way to write a file in java, it provides overloaded write method to write int, byte array and String to the File. You can also write part of the String or byte array using [...]

2019-11-22T22:29:33+05:30Categories: Programming|Tags: |

Two dimensional array | Java

Introduction An array of more than one dimension is known as multi-dimensional array. Two dimensional array is actually an array of one dimensional array. This is unlike languages like C, Java array to have rows of varying length i.e. a multidimensional array can have 2 columns in one row and [...]

2019-11-27T18:09:06+05:30Categories: Programming|Tags: |

HashMap vs HashTable | Java

HashMap and Hashtable both are used to store data in key and value form. Both are using hashing technique to store unique keys. Differences between HashMap and Hashtable: Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized [...]

2019-11-27T18:04:21+05:30Categories: Programming|Tags: , , |
Go to Top