Java

Home » Java (374)

When to use interface
Java Interface are great ways to define abstraction in Java. By using interface in java you can write flexible and maintainable code which can adapt future changes. many design pattern uses Java interface beautifully.

Find current directory with Example
You can get current directory in Java by using system properties provided by JDK e.g. "user.dir". Current directory in Java is the directory from where "java" command has ran.

What is private access modifier in Java? Can we make class private
Private keyword in java gives highest form of encapsulation and its coding best practice to make variable private in Java and also make methods private until you have a good reason of not doing so.

Java Program to compare String
Simple Example of comparing two Strings in Java. There are 4 ways you can compare two Strings in Java e.g. equals, equalsIgnoreCase, compareTo and compareToIgnoreCase. you can even write comparator to compare Strings in java.

Java Program to loop ArrayList
Simple Example of Iterating or looping over ArrayList in java. There are multiple ways you can loop ArrayList, most common of them is using for loop, Iterator and while loop.

What is difference on start and run method
Why call start method if it calls run() is common doubt among Java programmer. Though there is difference between Start() and run() method. when you call start(), JVM creates a new thread to execute code inside run() method and allows parallel execution which is not the case if you call run() directly.

SimpleDateFormat and thread-safety issues
SimpleDateFormat in Java is used to convert String to Date and Date to String but main issue with SimpleDateFormat Java class is that it is not thread safe and one thread can see the result of other thread because of design flaw on format() and parse() method.

What are differences between transient and volatile variable
Difference between transient and volatile keyword in Java is one of classic interview question. transient is used in Serialization while volatile is used in multi-threading to ensure visibility of variable among multiple threads.

Spring Security Example to limit user session
While writing secure Java web application you may need to limit number of concurrent user session to 1. Spring security example clearly provides out of box session management facility.

Difference between daemon and user thread
Daemon thread in Java are used for background task. main difference between daemon and user thread is that JVM exits once all user thread finish execution. JVM does not wait for daemon thread to complete.

Fixing java.lang.NoClassDefFoundError error
java.lang.NoClassDefFoundError is one of the frustration error used to get in java projects. i have documented the detailed steps to fix or resolve NoClassDefFoundError in java

throw vs. throws in Exception handling
Main difference between throw and throws keyword in java is there usage. throws is used to declare Exception thrown by any method while throw is used to actually throw Exception in Java.

JSTL set tag or <c:set> examples in JSP
JSTL Core Set tag Examples are collections of different examples like creating variable in session scope, removing variable using set tag, setting bean properties using set tag etc.

Race Condition in multi-threading
Race conditions in java are those hard to find multithreading bugs which occurs in concurrent environment on random basis because of multiple thread not seeing each others action.

Setting up JAVA_HOME environment in Linux, Unix and Windows
JAVA_HOME in Java is an environment variable which represents JDK installation directory and used by many Java tools, library.

Why non-static variable cannot be referenced from a static context
non static variable cannot be access in static context is common compiler error in Java which comes when we use any non static variable, method, this or super keyword inside any static method in java like main method.

Producer Consumer Design Pattern with Blocking Queue
Consumer design pattern is based on problem of Producer consumer in multi-threading. BlockingQueue in Java5 Solved this effectively without any hassle.

How to encode decode String in Java base64 Encoding
Converting String into Base64 Encoding is quite easy in Java when you use Apache Common Codec Library. Other alternatives of converting byte array to base64 encoded string is MimeUtil or Base64Encoder in Sun.

Difference between LinkedList and ArrayList
Main difference between Linked List and Array List in Java is there underlying implementation.Array List is based in Array while LinkedList is implemented using Doubly Linked List in Java.

Java String class or object
Strigns are sequence of characters in any language. For java, sequence of characters are stored in the form of java.lang.String object.
Strings are immutable objects, meaning once created, the contents of the string, can not be modified in memory that means string objects are readonly.

Home » Java (374)