Difference between transient vs volatile variable or modifier in Java

transient vs volatile modifier in Java
What is difference between transient and volatile variable or modifier in Java is one of the most common Serialization Interview Question in Java. Though volatile variables are not related to Serialization at all, this question is mostly asked in conjunction with other Serialization question. Both transient and volatile modifiers are completely different to each other. In fact this question is as popular as Serializable vs Externalizable in Java. Main difference between transient vs volatile variable is that transient variables are not serialized during Serialization process in Java while volatile variables are used to provide alternative synchronization in Java. By using volatile keyword or modifier on fields, signals compiler that this variable is accessed by multiple thread and any reordering or optimization by compiler should be avoided. In this Java article we will see some difference between transient and volatile variable by learning each of them and When to use transient and volatile variable in Java.

10 points about Static in Java

What is static in Java
Static in Java is related to class, if a field is static means it belongs to class, similarly static method belongs to classes and you can access both static method and field using class name e.g. if count field is static in Counter class than you can access it as Counter.count, of course subject to restriction applied by access modifier e.g. private fields are only accessible in class on which they are declared, protected fields are accessible to all classes in same package but only accessible in sub class outside package. See private vs protected vs public for complete details on access modifier. Similarly if you have a static method increment() in Counter class which increment counter than you can call it as Counter.increment(). There is no need to create an object of Counter class to access either static method or static field, this is main difference between static and non static members.

How to read file in Java using Scanner Example - text files

Reading file with Scanner
From Java 5 onwards java.util.Scanner class can be used to read file in Java. Earlier we have seen example of reading file in Java using FileInputStream and reading file line by line using BufferedInputStream and in this Java tutorial we will See How can we use Scanner to read files in Java. Scanner is a utility class in java.util package and provides several convenient method to read int, long, String, double etc from source which can be an InputStream, a file or a String itself. As noted on How to get input from User, Scanner is also an easy way to read user input using System.in (InputStream) as source.Main advantage of using Scanner for reading file is that it allows you to change delimiter using useDelimiter() method, So you can use any other delimiter like comma, pipe instead of white space.

Difference between method and constructor in Java

What is difference between method and constructor in Java is very common questions on beginner level Java interviews with 2 to 3 year experience. Since constructor is kind of special and it has it's own properties which separates it from any normal Java method, this question make sense. Main difference between Constructor and Method is that, you need to call method explicitly but constructor is called implicitly by Java programming language during object instantiation. It doesn't mean you can not call Constructor; if you have overloaded constructor than you can call them using  this keyword as this() constructor, you can even call super class constructor using super() keyword, in-fact that is done automatically by Java compiler if no explicitly constructor is called and that is known as constructor chaining in Java. Like many other beginner level questions e.g. Vector vs ArrayList, We will see difference between method and constructor in Java in point form to understand important properties of each of them clearly.

What is difference between View and Materialized View in Database or SQL?

Difference between View and Materialized view is one of the popular SQL interview question, much like truncate vs delete,  correlated vs noncorrelated subquery or primary key vs unique key.  This is one of the classic question which keeps appearing in SQL interview now and then and you simply can’t afford not to learn about them. Doesn’t matter if you are a programmer, developer or DBA, this SQL questions is common to all. Views are concept which not every programmer familiar of, it simply not in the category of CRUD operation or database transactions or SELECT query, its little advanced concept for average programmer. Views allows a level of separation than original table in terms of access rights but it always fetch updated data. Let’s see What is View in database, What is materialized View and difference between view and materialized view in database.

Difference between == and equals() method in Java - String Object

What is the difference between == and equals() method for comparing Objects in Java is one of the classical Interview Questions which appears now and then in many interviews. This question is mostly asked in conjunction with String because comparing String using == and equals() method returns different results. I have often seen as along with other popular String  question e.g. StringBuffer vs StringBuilder, Why String is final etc.  Java is a pure object-oriented language and every object has one state and location in the memory and equals () and == are related to the state and location of the object, now in this article will try to understand this concept and difference between == and equals method in Java.

Java ArrayList Examples For Programmers

ArrayList Example in Java
In this Java ArrayList Example we will see how to add elements in ArrayList, how to remove elements from ArrayList, ArrayList contains Example and several other ArrayList functions which we use daily. ArrayList is one of the most popular class from Java Collection framework along with HashSet and HashMap and a good understanding of ArrayList class and methods is imperative for Java developers. ArrayList is an implementation of List Collection which is ordered and allow duplicates.  ArrayList is alos index based and provides constant time performance for common methods e.g. get().Apart from very popular among Java programmers, ArrayList is also a very popular interview topic. Questions like Difference between Vector and ArrayList and LinkedList vs ArrayList is hugely popular on various Java interview specially with 2 to 3 years of experience. Along with Vector this is one of the first collection class many Java programmer use. By the way e have already seen some ArrayList tutorial e.g. ArrayList sorting example,  converting Array to ArrayList,  looping through ArrayList which is good to understand ArrayList in Java.

Java Enum Example with Constructor

Java Enum with Constructor
Java Enum can have Constructor to pass data while creating Enum constants. One example of passing arguments to enum Constructor is our TrafficLight Enum where we pass action to each Enum instance e.g. GREEN is associate with go, RED is associate with stop and ORANGE is associated with slow down. You can also provide one or more constructor to your Enum as it also support constructor overloading. Just note that modifier public and protected are not allowed to Enum constructor, it will result in compile time error. By the way We have covered see some enum examples in our previous posts e.g. Java Enum Switch Example, Java Enum valueOf Example and Enum to String Exmaple in Java, which is good to learn enum in Java.