Vikyath Ram has Published 151 Articles

Flow control in a try catch finally in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:57:44

6K+ Views

A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following −Syntaxtry { ... Read More

final local variable in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:41:03

2K+ Views

Local VariableLocal variables are declared in methods, constructors, or blocks.Local variables are created when the method, constructor or block is entered and the variable will be destroyed once it exits the method, constructor, or block.Access modifiers cannot be used for local variables.Local variables are visible only within the declared method, ... Read More

Final static variables in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:39:59

5K+ Views

Final Static VariablesClass variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.There would only be one copy of each class variable per class, regardless of how many objects are created from it.Static variables are normally declared ... Read More

Find free disk space using Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:37:34

597 Views

java.io.File class provides following useful methods to figure out the free disk space available.Sr.No.Method & Description1public long getFreeSpace()Returns the number of unallocated bytes in the partition named by this abstract path name.2public long getTotalSpace()Returns the size of the partition named by this abstract pathname.3public long getUsableSpace()Returns the number of bytes ... Read More

Factory method to create Immutable List in Java SE 9

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:03:37

148 Views

With Java 9, new factory methods are added to List interface to create immutable instances. These factory methods are convenience factory methods to create a collection in less verbose and in concise way.Old way to create collectionsExampleimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class Tester {    public static ... Read More

Factory method to create Immutable Map in Java SE 9

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 14:01:01

121 Views

With Java 9, new factory methods are added to Map interface to create immutable instances. These factory methods are convenience factory methods to create a collection in less verbose and in concise way.Old way to create collectionsExampleimport java.util.Collections; import java.util.HashMap; import java.util.Map; public class Tester {    public static ... Read More

Externalizable Interface in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 13:49:30

856 Views

Externalization is used whenever we need to customize serialization mechanism. If a class implements an Externalizable interface then, object serialization will be done using writeExternal() method. Whereas at receiver's end when an Externalizable object is a reconstructed instance will be created using no argument constructor and then the readExternal() method ... Read More

Download webpage in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 13:16:19

2K+ Views

We can download a web page using its URL in Java. Following are the steps needed.Create URL object using url string.Download webpage in JavaCreate a BufferReader object using url.openStream() method.BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));Create a BufferWriter object to write to a file.BufferedWriter writer = new BufferedWriter(new FileWriter("page.html"));Read each line ... Read More

Difference between super() and this() in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 12:42:48

6K+ Views

Following are the notable differences between super() and this() methods in Java. super()this()Definitionsuper() - refers immediate parent class instance.this() - refers current class instance.InvokeCan be used to invoke immediate parent class method.Can be used to invoke current class method.Constructorsuper() acts as immediate parent class constructor and should be first line in ... Read More

Difference between ArrayList and CopyOnWriteArrayList in Java

Vikyath Ram

Vikyath Ram

Updated on 21-Jun-2020 12:23:44

2K+ Views

Following are the notable differences between ArrayList and CopyOnWriteArrayList classes in Java. ArrayListCopyOnWriteArrayListSynchronizedArrayList is not synchronized.CopyOnWriteArrayList is synchronized.Thread SafeArrayList is not thread safe.CopyOnWriteArrayList is thread safe.Iterator typeArrayList iterator is fail-fast and ArrayList throws ConcurrentModificationException if concurrent modification happens during iteration.CopyOnWriteArrayList is fail-safe and it will never throw ConcurrentModificationException during iteration. The ... Read More

Advertisements