Posts

Generate Heap Dump in Unix

Image
Heap dump provides the insight into the JVM - shows live objects on the heap (reachable and unreachable) along with their types and values. In addition it also provides no of objects and their size as %age of total heap size.We have many ways to get the heap dump in Windows. Some are as follows:- jconsole jVisual VM Eclipse MAT ....and it goes on Out of above , i like jVisualVM the most due to its monitoring capability, interactive display, and easy to use. But the problem comes with the unix. Even though we can monitor the application remotely  but we cannot see the live objects, their size and number i.e we cannot get the heap dump remotely. To get the heap dump on Unix machine, we can use j map.  To use jmap , we need the process id of java application. At times, we have lot many java process running in unix and its difficult to identify. Java provides jps tool which list the JVM with the process Id which it got the...

Why Time gets truncated with ResutSet getDate() function.

Recently I stuck in an issue on populating date from stored procedure. I am reading a date from a resultset using rs.getDate(), storing in a java.util.Date instance variable and displaying on the screen. Java.util.Date  mydate = rs.getDate(1); Output is only date while time is truncated.  But why …! That confused me a lot. So I google it. Spending lot of time in reading blogs, oracle docs and trying different things on oracle server like checking  NLS_DATE_FORMAT, I am not able to get the time. Next I come across a Timestamp thing in Resultset class. Rs.getTimestamp (int colIndex) When I use it, I immediately get the time.  Now, the important question, why the resultset function getDate() does not return the Time. Now my search is preety narrow. What I found is :- In java, we have java.util.Date for java.sq.Date . So functionalities available in sql.Date are also available in util.Date. But there is one difference, sql.Date stores only Date and not Time ...

Where to declare Constants in Java

Its been an topic of debate where should constants be declared. Let look at approaches :- Declared in an Interface. Declared in a Class. Enums Going through google, i found number of explanation for both of these. Each have their pros and cons. I'll try to summarise and share my thoughts on it. Lets start with interface . In Java, Interfaces are used as abstract type, that contain method signatures, constants and nested types as  according to Oracle . We can use interfaces to defined a contract or for communication  as explained in my previous article . If we define constants here, we can have the following consequences:- We cannot stop a class to not implement an interface.So a Global constant interface can be used for subtype which is not advisable. We cannot give define constants depend on certain state condition. All the constants would stay in memory all the time. Although, we can define constants in interfaces, we have the above constraints. Lets...

More About Java Arrays

With the addition of Collections in Java, the use of primitives and primitive arrays decreases day by day. But at the API level or framework design level, primitives are highly used even today as they are fast and does’t include method chaining.  Arrays class in Java, provides the basic to advanced functionality to arrays. Java 6 adds a couple of more functions to this class. They are   copyOf ( T[ ] original, int newLength  ) copyOfRange( int[ ] original, int from, int to  )  CopyOf copies the array and allows to explicitly defined the size of new array, padding with zeroes (in case of int, float, double, short), null (in case of char) and false (in case of boolean). Its similar to System.arraycopy() but  doesnt allows to specify the size of output array. Simple but useful functionality.   Lets understand with the example:- public class Test { public static void main(String[] args) { int[] orig={1,2...

Pay Packets of BIG IT Giants

What Apple is paying for a Software developer..? How much is facebook, Twitter, linkedin paying to Analysts? Mentioned above are few Big Tech IT Companies where everybody likes to work. Well few of us got an opportunity. But at least everybody likes to know what they are paying....! Few days back, I come across a  website http://techcompanypay.com/  ,which shows the average salary of IT companies as per their designation. The company claims that it had collected the information publicily available on the internet, so no comment on the authenticity. But at least one can have the idea... Do check it out.

Learning JDK 7 Features Part 3: Try With Resource

Today we follow some standard coding conventions so that code should easy to read and maintainable or   i can say " Code should look beautiful  ". But there are some cases where we find our code is cluttered or duplicated. Its more often with Exception Handlers , Streams and JDBC  calls i.e. opening and closing streams/connections and multiple catch handlers. Java 7 comes to rescue us from this duplication and is succeeded in it. Before Java 7, to cloase a resource, we write a final block and close every resource in it. but some times the finally block become large and cluttered. Take a look at the code below:- finally { try { if (resultSet != null) resultSet.close(); } catch(Exception e) {} finally { try { if (statement != null) statement.close(); } ...

Why java supports Multiple Interface Inheritance

Java does not support multiple class inheritance i.e. we cannot extend multiple classes at one time in a class. But we can implememt multiple interfaces in a class. Lets start with the benefits of inheritance. Interfaces are user for two reasons :- 1) Contract 2) Communication Contract ,is an aggrement between the interface and the implementing class, that the class will provide the implementation of the methods of the interface's. On has to adhere to the contract. Collections in java has many interfaces like Set, List, Map. These interfaces provide the basic set of methods for the class depending on its interface type.We have their implementation classes like HashSet for Set, ArrayList for List and HashMap for Map. Communication , is used to communicate certain functionality of a class to the outside world. This is very usefull when you want to expose a class but we dont want that one should know all the methods , variables and other class informa...