HTML

Can we overload static method in Java Program - Example

Overloading static method In Java
Yes, we can overload static method in Java. In terms of method overloading static method are just like normal methods and in order to overload static method you need to provide another static method with same name but different method signature. Static overloaded method are resolved using Static Binding during compile time. Overloading method in Java is completely different than overriding method and as discussed in our last article we can not override static method in Java but we can certainly overload static method in Java. Here is an example which confirms that we can overload static method in Java:

Can we override private method in Java - Example program

No, We can not override private method in Java, just like we can not override static method in Java. Like static methods, private method in Java is also bonded during compile time using static binding by Type information and doesn't depends on what kind of object a particular reference variable is holding. Since method overriding works on dynamic binding, its not possible to override private method in Java. private methods are not even visible to Child class, they are only visible and accessible in the class on which they are declared. private keyword provides highest level of Encapsulation in Java. Though you can hide private method in Java by declaring another private method with same name and different method signature.

Top 10 Java HashMap Interview Questions and Answers

The java.util.HashMap is one of the workhorses of JDK. Along with ArrayList, it is one of the most used classes from Java's collection framework. There is hardly a real world Java project, where I haven't seen the use of HashMap. It is an implementation of hash table data structure and it's not a surprise that HashMap is so useful, as someone has rightly said, "if you could have just one data structure, make it a hash table". The hash table data structure allows you to search for a value in O(1) time if you have key. In Java, there are several implementations of hash table data structure exists e.g. Hashtable, ConcurrentHashMap, LinkedHashMap etc but HashMap is your general purpose map. Though, if you have a special need you can use other hash table implementations available in JDK.

What is transient variable in Java - Serialization Example

What is transient variable in Java
transient variable in Java is a variable whose value is not serialized during Serialization and which is initialized by its default value during de-serialization, for example for object transient variable it would be null. this behavior can be customized by using Custom Serialized form or by using Externalizable interface. transient variable is used to prevent any object from being serialized and you can make any variable transient by using transient keyword. By the way difference between transient and volatile variable in Java is a famous Java interview question but transient variable is completely different than volatile variable which we have discussed in our post What is volatile variable in Java. In next section we will see complete example of serialization where we will first serialize an instance of Book class which implements Serializable and than de-serialize to see What is the value of transient variable after deserialization.

What is Volatile Variable in Java - When to use in Thread? Example

What is Volatile variable in Java
volatile variable in Java is a special variable which is used to signal threads, a compiler that this particular variables value are going to be updated by multiple threads inside Java application. By making a variable volatile using the volatile keyword in Java, application programmer ensures that its value should always be read from main memory and thread should not use cached value of that variable from their own stack. With the introduction of Java memory model from Java 5 onwards along with introduction of CountDownLatch, CyclicBarrier, Semaphore and ConcurrentHashMap, volatile variable also guarantees "happens-before" relationship, which means not only another thread has visibility of latest value of volatile variable but also all the variable is seen by the thread which has updated value of volatile variable before these threads sees it. What is volatile variable and when to use it is always a popular Java threading question.

Difference between HashSet and HashMap in Java

HashSet and HashMap in Java
HashSet vs HashMap is a classical Java Collection interview question which focuses on What are differences between HashSet and HashMap in terms of features, usage, and performance. If you are in Java programming even for a year or so, you are likely to be familiar with What is HashSet in Java and What is HashMap in Java, these two are most popular collection classes. Despite being hash based collection HashSet and HashMap are different to each other because the underlying interface is different. HashSet implements Set interface via extending AbstractSetclass and HashMap implements Map interface. Before seeing differences between let's see what is common between HashSet and HashMap in Java:

5 difference between Hashtable and HashMap in Java

Hashtable vs HashMap in Java
Hashtable and HashMap are two hash based collection in Java and used to store objects as key value pair. Despite being hash based and similar in functionality there are a significant difference between Hashtable and HashMap and without understanding those difference if you use Hashtable in place of HashMap than you may run into series of subtle programs which is hard to find and debug.Unlike Difference between ArrayList and HashMap,  Difference between Hashtable and HashMap are more subtle because both are similar kind of collection. Before seeing difference between HashMap and Hashtable let's see some common things between HashMap and Hashtable in Java.

Top 12 Java Thread, Concurrency and Multithreading Interview Questions For experienced

Java concurrency and thread interview questions answers
Multithreading is an important feature of Java programming language, which means threads are also an important part of any Java interview. It's true and in fact at beginners and freshers level Thread interview questions in Java are one of most difficult to answer. One reason for interview question related to multithreading and concurrency being difficult is confusion around how multiple threads works together and second is threads are genuinely a complicated topic to understand and use correctly. Mostly thread interview questions checks Java programmers knowledge on Java Thread API, Java concurrency API, issues related to multi-threading like a race condition, thread-safety, and deadlock. Some time multithreading and concurrency interview question also focus on parallel design patterns like solving the producer-consumer problem, implementing work steal pattern or solving dining philosopher problem in Java. This is especially true while interviewing experienced Java developers with 4 to 6 years of experience.

Top 10 Java Programming Coding Interview Questions Answers for programmers

Java coding interview questions answers
Java coding interview questions are mostly some programming exercises which is asked to be solved in java programming language in limited time during any core Java or J2EE interview. No matter whether you have 2 years of experience or 4 years of experience, There is always some coding interview question in Java programming job you are applying. Actually questions related to Java Coding are increasingly getting popular on Java interviews for two reasons, first its difficult to crack Java coding interview questions than answering fact based questions like Why String is immutable in Java or Why main is static in Java; Second reason of popularity of Coding question in Java interviews is read need of good developers who are required to do lot of coding in projects rather than doing some maintenance works.

10 Advanced core Java interview questions for senior and experienced programmer

Java interview questions for Senior and Experienced programmer
Java is very big and there is no way to prepare completely for any core java interview but there is a level of question depends upon your experience, if you are fresher than questions asked in Java interview are mostly based on fundamentals like Iterator vs Enumeration in Java, Why main is public static and void or may be ArrayList vs LinkedList in Java. Things changes when you apply for senior developer, Technical lead or Team Lead Java positions, questions asked on that level are more advanced and less popular among Java circles, you may be asked questions from design pattern, questions from multi-threading, Collections and even asked to write code, design classes and prepare JUnit tests. In this Java article I will share some advanced Core Java interview questions which is appear in Senior level interviews mostly on 4 to 6 years and 6 to 8 years of experience. One important thing to note is that you can not clear interview by just mugging answers of these question because interviewer is most likely asked you follow-up question based upon your response and only way to get through it is to understand the topic well.

What is PATH and CLASSPATH in Java - Path vs ClassPath

What is PATH and CLASSPATH in Java
The PATH and CLASSPATH are two most important environment variables of Java environment which is used to find the JDK binaries used to compile and run Java in windows and Linux and class files which are compiled Java bytecodes. From my personal experience I can say that PATH and CLASSPATH are two most problematic thing for beginners in Java programming language due to two reasons; first because in most of Java courses nobody tell details of what is a PATH and CLASSPATH, What do PATH and CLASSPATH do, What is meaning of setting PATH and CLASSPATH, What happens if we do not set them, Difference between PATH vs CLASSPATH in Java or simply How Classpath works in Java etc. These basic question which answers most of the details about PATH and CLASSPATH in Java are mostly not answered until Java programmer itself acquire these knowledge, Things may be changed nowadays but important of PATH and CLASSPATH is still high. Most common cause of dreaded error like java.lang.NoClassDefFoundError and java.lang.ClassNotFoundException is either incorrect or misconfigured CLASSPATH in Java.

5 Free SQL Books For Beginners and Experienced - Download PDF or Read Online

There is no doubt that SQL is one of the most important skills for both programmers and business analyst. Since many Enterprise applications use the relational database at their backend e.g. Oracle, Microsoft SQL Server, MySQL, it's important to know SQL to work with data resided on those databases. SQL has been around for many years and it will be around for many more coming years. It is also one of the matured technology, hence there are a lot of free resources e.g. books, articles, tutorials are available online.   I have been sharing some free eBooks on different technologies e.g. Java, Python, and jQuery and today I'll share some of the free SQL books for online and offline reading.

What is main method in Java ? Why main is public static and void

What is main method in Java
main method in Java is an standard method which is used by JVM to start execution of any Java program. main method is referred as entry point of Java application which is true in case of core java application but in case of container managed environment like Servlet, EJB or MIDlet this is not true as these Java programs have there own life-cycle methods like init(), service() or destory() for Servlet's which is used by container. main method in Java is run by main thread which is a non daemon thread and Java program runs until main method finishes or any other user thread is running. When we start JVM by running java command we also provide name of class which contains main method, which is later invoked by JVM to start Java program execution. for example in below command :

Default Methods in Interface, Multiple Inheritance and Diamond Problem in Java 8

Ever since Java 8 introduced default and static methods in JDK 8, it's become possible to define non-abstract methods in interfaces and since in Java one class can implement multiple interfaces and because there can be concrete methods in interfaces, the diamond problem surfaced again. What will happen if two interface has methods o the same name and a Java class inherit from it? Many Java programmer also asks me the question that, is Java 8 is also supporting multiple inheritances of classes, as it seems because interface with methods is similar to abstract class or in that any class. Well, it’s not.

Java 8 Default Methods On Interface : What, Why and Example

Whenever someone talks about Java 8, the first thing he speaks about is lambda expression and How lambda expression will change the way you use Collections API today. In truth, lambda expression would not be that useful had language not been enhanced to support default methods on Java Interface. Also known as a virtual extension or defender methods, they allow you to declare a non-abstract method inside Java interface. Which means, finally you can add new methods without breaking all classes, which implements a certain interface. This opens a new path for enhancing and evolving existing Collection API to take advantage of lambda expressions. For example, now you can iterate over all elements of Collection in just one line, as opposed to four lines it requires you to do prior to Java 8.

7 Free 1Z0-803 and 1Z0-804 Sample Questions - OCAJP 7 and OCPJP 7 Mock Exams (Oracle Certified Associate Java SE 7 Programmer 1 and 2 )

In this article, I am going to share some OCAJP 7 or 1Z0-803 exam and OCPJP 7 or 1Z0-804 certification sample questions and mock exam for practice which are completely free and available online. The sample questions are not good enough for thorough practice but you can use these mock tests to get an idea of what to expect in the actual exam. Many of the free mock questions are actually the samples questions provided by professional certification exam simulator provided e.g. Whizlabs, Enthuware, MyExamCloud etc, which are samples of their full-length exam simulators. As I have said many times in this blog that in order to succeed and do well on Java certification you must need a good study guide and a good exam simulator to practice well.

How to backup and load crontab from a file in Linux and UNIX

If you have been using Linux for some time then you might know about cron jobs. They are the scheduler which is used to automatically start processes in a Linux box. I have worked in many projects which use cron jobs to start the environment daily or weekly. They are similar to Autosys when it comes to scheduling job but cron is a Linux command as opposed to Autosys which is separate application altogether. In Linux, crontab command is used for loading cron jobs from a file, listing existing cron entries, and editing them. It manages the cron table that is used by the cron daemon in Linux to execute the cron jobs. Though there are comments to view cron jobs, edit cron jobs and upload cron jobs from a file there is no command to backup existing cron jobs, but don't worry, I'll show you a trick to backup your cron job before editing them or loading a new set of cron jobs.

Top 10 Java Date, Time and Calendar Interview Questions Answers

The Date and Time API is very important one for day to day Java development work but many interviewers don't ask enough questions on this topic. Most of the questions are based on either Java Collection framework e.g. HashMap, ConcurrentHashMap or ArrayList, or on multi-threading concepts e.g. volatile, synchronized and atomic variables. This is not good and I think many interviewers have realized that a good understanding of date and time API is also important for a good Java developer. That's the main reason of increasing number of date, time and calendar based Java interview questions in recent time, particularly in 2017.

How to determine if a string has all unique characters in Java?

This is one of the common string based coding problem from programming job interviews. You need to write a program to determine if a given string has all unique characters or not. For example input= "Java" then your function should return false because all characters are not unique, and if the input is "Python" then your program should return true because all characters in Python are unique. For the purpose of this problem, you can assume the given String only contains ASCII printable characters, though you should always verify that with the interviewer. You can also assume that your solution needs to case-sensitive i.e. "P" and "p" will be considered two different characters and a string containing a letter in both capital and the small case will be considered unique. You are also free to solve the problem in place of using any additional data structure.

Top 17 SQL and UNIX Interview Questions for Software Support Engineers

The SQL and UNIX are two of the most essential skill for any support or development job. It doesn't matter whether you are applying for Java developer or C++ developer, Python developer or Ruby programmer, SQL and UNIX always have some role to play. Hence, it's imperative for any programmer to prepare both SQL and UNIX well before going for any job interview. This becomes even more important if you are going for a support engineer role. Since the main job of support professional is to look after production environment, which often runs on Linux, it's must for them to have a good knowledge of both Linux operating system and command line. They should know what they are doing because an incorrect grep or rm command can bring down the whole production system. That's why they are extensively questioned and tested in their UNIX skill.