Friday, 31 October 2014

What is difference between ClassNotFoundException and NoClassDefFoundError?


 A ClassNotFoundException is thrown when the reported class is not found by the ClassLoader in the CLASSPATH. It could also mean that the class in question is trying to be loaded from another class which was loaded in a parent classloader and hence the class from the child classloader is not visible.
Consider if NoClassDefFoundError occurs which is something like
java.lang.NoClassDefFoundError
src/com/ClassA
does not mean that the ClassA  class is not in the "CLASSPATH". 
It means that the class ClassA was found by the ClassLoader however when trying to load the class, it ran into an error reading the class definition. 
This typically happens when the class in question has static blocks or members which use a Class that's not found by the ClassLoader. 
So to find the culprit, view the source of the class in question (TestClass in this case) and look for code using static blocks or static members

Tuesday, 28 October 2014

Java Class Loaders

        Class loaders are hierarchical. Classes are introduced into the JVM as they are referenced by name in a class that is already running in the JVM. So how is the very first class loaded? The very first class is specially loaded with the help of static main() method declared in your class. All the subsequently loaded classes are loaded by the classes, which are already loaded and running. A class loader creates a namespace. All JVMs include at least one class loader that is embedded within the JVM called the primordial (or bootstrap) class loader. Now let’s look at non-primordial class loaders. The JVM has hooks in it to allow user defined class loaders to be used in place of primordial class loader. Let us look at the class loaders created by the JVM.



Classloaders and their explaination -  
  • Bootstrap (primordial) - No Loads JDK internal classes, java.* packages. (as defined in the  sun.boot.class.path system property, typically loads rt.jar and i18n.jar). Classes loaded by Bootstrap  class loader have no visibility into classes loaded by its descendants (i.e. Extensions and Systems  class loaders).

  • Extensions - Loads jar files from JDK extensions directory (as defined in the java.ext.dirs system property – usually lib/ext directory of the JRE)
  • System - No Loads classes from system classpath (as defined by the java.class.path property, which is set by the CLASSPATH environment variable or –classpath or –cp command line options). The classes loaded by system class loader have visibility into classes loaded by its parents (ie Extensions and Bootstrap class loaders).


Tuesday, 21 October 2014

File System Overview - Linux

File System Overview - Linux




  1. bin : This folder contains all the executable binary programs (file) required during booting, repairing, files required to run into single-user-mode, and other important, basic commands cat, du, df, tar, rpm, wc, history, etc.
  2. /boot : Holds important files during boot-up process, including Linux Kernel.
  3. /dev : Contains device files for all the hardware devices on the machine e.g., cdrom, cpu, etc
  4. /etc : Contains Application’s configuration files, startup, shutdown, start, stop script for every individual program.
  5. /home : Home directory of the users. Every time a new user is created, a directory in the name of user is created within home directory which contains other directories like Desktop, Downloads, Documents, etc.
  6. /lib : The Lib directory contains kernel modules and shared library images required to boot the system and run commands in root file system.
  7. /lost+found : This Directory is installed during installation of Linux, useful for recovering files which may be broken due to unexpected shut-down.
  8. /media : Temporary mount directory is created for removable devices viz., media/cdrom.
  9. /mnt : Temporary mount directory for mounting file system.
  10. /opt : Optional is abbreviated as opt. Contains third party application software. Viz., Java, etc.
  11. /proc : A virtual and pseudo file-system which contains information about running process with a particular Process-id aka pid.
  12. /root : This is the home directory of root user and should never be confused with ‘/
  13. /run : This directory is the only clean solution for early-runtime-dir problem.
  14. /sbin : Contains binary executable programs, required by System Administrator, for Maintenance. Viz., iptables, fdisk, ifconfig, swapon, reboot, etc.
  15. /srv : Service is abbreviated as ‘srv‘. This directory contains server specific and service related files.
  16. /sys : Modern Linux distributions include a /sys directory as a virtual filesystem, which stores and allows modification of the devices connected to the system.
  17. /tmp :System’s Temporary Directory, Accessible by users and root. Stores temporary files for user and system, till next boot.
  18. /usr : Contains executable binaries, documentation, source code, libraries for second level program.
  19. /var : Stands for variable. The contents of this file is expected to grow. This directory contains log, lock, spool, mail and temp files.

Monday, 13 October 2014

Setting Up Tomcat For Remote Debugging Windows

Debugging a J2EE application is one of the most basic needs of a developer. We can debug a standalone application easily by adding one breakpoint and running the debugger.However debugging a remotely hosted application needs to have a certain application server specific settings

For this you need to configure JPDA (Java Platform Debugger Architecture) in your tomcat.

Add the following two lines in the first line of tomcat's "startup.bat"


set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

Your startup.bat may now be like - 

set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
if "%OS%" == "Windows_NT" setlocal
and so on 

Replace the line 
call "%EXECUTABLE%" start %CMD_LINE_ARGS%

with 

call "%EXECUTABLE%" jpda start %CMD_LINE_ARGS%

Restart the server. 
Your tomcat is setup for remote debugging.