Heap dump and Thread dump to analyze the memory and threads

Thread dump

A thread dump is the sum of the information about the stacks (stack traces) of all the threads in an application. We call obtaining that information as “thread dumping” (or dumping in general) and we refer to the information itself as a a
thread dump. More generally storing any information can be refereed to as […]

Basic ANT build file and important elements of an ANT build file

Anatomy of an ant build file

Apache ant is a java build tool. If familiar with build tools in other languages then you may think of ant as a similar tool as make, rake, cmake etc. Other build tools in Java are maven or gradle.

A build tool or is a software tool that automates some process […]

Synchronized collections versus concurrent collections in Java

The `java.util.Collections` class provides methods of creating synchronized collections the methods are:

*
*
*
*
*
*

But what’s a synchronized collection? Well like the name says it’s a collection that is synchronized – all read and write access is synchronized as you would synchronize on some lock.

This comes with two small caveats.

Firstly, […]

Invoke Unix shell or Windows command line commands using Java program

Starting shell programs from Java.

While not many people use this feature sometimes it is sometimes useful to launch other programs from a Java program. In particular in this article we will focus on shell programs – how to start them, how to get their output and return status code.

Note: while normally programming in Java you […]

Best practices to define constants in Java application

In this article we will cover contents. Constants are values which cannot change over time. This is useful when we wish to declare something that has no right to change (physical or mathematical constants) or things that we wish to ensure won’t change.

Constants in Java come in two flavors static and non static.

Static constants

Static constants […]

How would you accept input from the user from console?

The easiest way of accepting user input is using the `java.util.Scanner` class. `Scanner` was introduced in Java 1.5 for the exact purpose of reading character streams. Before Java 1.5 programmers had to make do reading byte streams and converting bytes to characters.

We use `Scanner`s to parse character data: strings to numbers, scanning lines, bytes, doubles […]

What are enums? Can you write the code to create an enum?

An enum also called an enumeration (not to be confused with `java.util.Enumeration`) or an enumerated type, is a type that can take any of the predefined values (and only them, and well `null`). Commonly this is used to represent some discrete data type like suits of cards, directions on the compass, days of week etc.

Sometimes […]

Why have stop and suspend method been deprecated in java?

While browsing through the javadoc of the `java.lang.Thread` class you may have seen the `stop` and `suspend` methods. Maybe you have been tempted to use them even though they’re marked as deprecated. Hopefully this article will convince you that this is a bad idea and you’re better of staying away from those methods!

Thread.stop

The stop method […]

How to check if a particular lock has been acquired by a Thread in Java?

The `java.util.concurrent.locks.Lock` provides one method that can be used to find whether this thread owns this lock and that method is `tryLock` in particular the timed variant. Let’s see this in an example.

Running the program yields:

main: Acquired lock
Lock not available… waiting
Lock not available… waiting
Lock not available… waiting
Lock not available… waiting
Lock not available… waiting
main: Releasing lock
Do […]

How does polymorphism work with arrays?

Arrays in Java are covariant. We say that some type is covariant when it is generic and if some other type let’s say `Dog` is of subtype `Animal` then is a subtype of . In general we talk about variance when we want to talk about complex relationships between types.

Reiteraiting what we said above […]

x

Enter your email address:

Delivered by FeedBurner

Java ExperienceA place for all type of Java web tutorials2014