View RSS Feed

All Blog Entries

  1. jmap - jdk provided heap observation utility

    by , 06-25-2011 at 01:15 PM
    jmap is one of the lesser known jdk provided utilities, which are worth mentioning. Very oftenly we feel the need to peek into the jvm and see which thread is taking how much of heap space - jmap is jdk’s answer to this.

    This utility was introduced in jdk1.5 and is as an experimental utility (oracle may discontinue to ship this utility with future releases)

    Some of the notable features of jmap are:

    1. can print shared object memory maps or heap memory ...
  2. Sudoku

    by , 06-23-2011 at 01:32 PM (JosAH's blog)

    a couple of years ago a large part of the world went totally mad. Not because of global climate changes, not because of terrible wars that were started in the Middle East, nor because of global famine, nor because of large investment banks going bankrupt and nor because of Tsunamis, but because of a puzzle: Sudoku.

    This is what Sudoku is all about:

    Java Code:
    	| . . . | . . . | . . . | 
    	| . . . | . .

    Updated 06-23-2011 at 03:52 PM by JosAH

  3. Book Recommendations

    by , 06-20-2011 at 09:34 PM
    In this article I plan to create a quick, easy to locate post about good books that I have encountered. Feel free to comment and add your book recommendations. I plan to include more than just Java books in this post. I will start with Java, moving onto c++, and other languages. The end of the post with books I have on my short list. These books will be finished shortly and I will put them here, and update my thoughts as the books are finished.

    Starting out - Which book to get?
  4. Recursion

    by , 06-20-2011 at 04:39 AM

    Recursion is defined as:
    1. the act or process of returning or running back
    2. logic, maths the application of a function to its own values to generate an infinite sequence of values. The recursion formula or clause of a definition specifies the progression from one term to the next, as given the base clause f (0) = 0, f ( n + 1) = f ( n ) + 3 specifies the successive terms of the sequence f ( n ) = 3 n

    In this article, I hope to make ...

    Updated 06-20-2011 at 04:48 AM by sunde887

  5. Script Engines

    by , 06-12-2011 at 10:07 AM (JosAH's blog)


    Java is not Javascript and most of the times when questions end up in the wrong forum, they're moved to another forum as soon as possible. Accidentally this article talks about Javascript a bit but it belongs in this Java section.

    Since version 1.6 of Java a script engine comes packaged with the core classes. A script engine is an abstract little framework that offers support for other languages, scripting languages to be exact, ...

    Updated 06-12-2011 at 10:10 AM by JosAH

  6. Heap Sort II

    by , 06-12-2011 at 09:54 AM (JosAH's blog)

    This is the second part of the Heap Sort article (that dumb forum software only allows 10000 characters per article part. Here's the second part:

    The first part of this article explained a bit about the heap sort algorithm itself. Now let's get back to our original problem: given the two arrays:

    Java Code:
    String[] first= { "Fred", "Barney", "Wilma", "Betty", "Bambam", "Pebbles" };

    Updated 06-12-2011 at 04:30 PM by JosAH

  7. Heap Sort I

    by , 06-12-2011 at 09:52 AM (JosAH's blog)

    A lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data.

    Examples of two main problem scenarios are like this:

    1) an array containing a first name and another array containing a last name and possibly a third array containing the age of a person; how to sort the arrays according to, say, the first name.

    2) a List of objects where each object contains a first name, ...

    Updated 11-18-2013 at 09:46 AM by JosAH

  8. Lazy associations

    by , 06-02-2011 at 07:26 PM (My Java Tips)
    Hibernate uses lazy select fetching by default for collections and lazy proxy fetching for single-valued associations. This default behavior makes sense for almost all associations in almost all applications.

    Hibernate will use the batch fetch optimization for lazy fetching if hibernate.default_batch_fetch_size parameter is set. This optimization may also be enabled at a more granular level.

    Lazy fetching introduces a problem that should be taken care of. Remember that ...
  9. Criteria instance

    by , 06-02-2011 at 07:22 PM (My Java Tips)
    Hibernate provides an interface org.hibernate.Criteria, which represents a query against a particular persistent class.

    Review the following example:

    Java Code:
    Criteria crit = session.createCriteria(Student.class);
    List students = crit.list();
    Resultset can be narrowed according to requirement. The class org.hibernate.criterion.Restrictions defines factory methods for obtaining certain built-in Criterion types. ...
  10. one-to-many, sql

    by , 06-02-2011 at 07:20 PM (My Java Tips)
    Let me presnet a simple <one-to-many> association from Parent to Child.

    XML Code:
    <set name="children">
    <key column="parent_id"/>
    <one-to-many class="Child"/>
    Assume that we wish to execute the following code:

    Java Code:
    Parent p = .....;
    Child c = new Child();
    Tags: one-to-many Add / Edit Tags
  11. Svn revert

    by , 06-02-2011 at 07:16 PM (My Java Tips)
    You must have used SVN while working in a team on a Java project. In this post, Ill write about 'revert' command.

    Let me present a scenario. You made some changes in a class and now you realize that the changes are not required/not correct. You wish to discard your changes. You have to use svn revert to discard your changes.

    Java Code:
    $ svn revert
    Following switches are available:

    Java Code:
    Tags: revert, svn Add / Edit Tags
  12. No Persistence provider for EntityManager

    by , 06-02-2011 at 07:15 PM (My Java Tips)
    You might have encountered the following exception while working with hibernate:

    Java Code:
    [java] Exception in thread "main" javax.persistence.PersistenceException: 
    No Persistence provider for EntityManager named  ****
    Make sure you have all the required jars in the class path.

    Java Code:
  13. Static/Non static methods - Example

    by , 06-02-2011 at 07:12 PM (My Java Tips)
    I will present an example to show the difference between static and non-static methods.

    Go through the example below:

    Java Code:
    public abstract class AbstractExample {
       public static void foo() {
          System.out.println("Static foo called.");
       public void bar() {
          System.out.println("Non-static bar called.");
    public class AbstractCaller extends AbstractExample {
    Java SE
  14. Factory Methods

    by , 06-02-2011 at 07:11 PM (My Java Tips)
    This post lists some facts about factory methods.

    Factory methods are static methods that return an instance of the native class. Some examples from JDK include :

    • LogManager.getLogManager
    • Pattern.compile
    • Collections.unmodifiableCollection
    • Collections.synchronizeCollection
    • Calendar.getInstance

    Factory methods do not have names like constructors and do not need to create a new object upon each invocation. Objects can be cached and reused, if ...
  15. Memory Leaks

    by , 05-25-2011 at 10:04 AM (My Java Tips)
    You are aware of the fact that garbage collection collects and removes all the unwanted objects from memory without used intervention. But sometimes, you run into memory leaks problems that demands investigation. I will shed some light on this issue in the next few posts.

    The Java GC process is a low-priority thread and it constantly searches memory for unreachable objects that are not reachable by any live thread. Different JVMs use different algorithms to determine how to collect ...
  16. Subclipse - Checkout

    by , 05-25-2011 at 10:02 AM (My Java Tips)
    Subclipse is a popular SVN plugin for Eclipse. This post is about how to do checkout using Subclipse.

    You will check out code from the trunk or branch of a project. First configure your repositories. Open the SVN Repository Perspective and then open the contents of the repository where your project is located. Locate the trunk/ or branch/ directory in the project and right-click the trunk/ directory or branch/ directory, and choose Checkout from the context-menu. You will be see a ...
  17. Committing code in Subversion

    by , 05-25-2011 at 10:00 AM (My Java Tips)
    Committing means persisting your changes. You may commit one file or multiple files at once.

    Subclipse makes committing easy and simple. When a file is modified, Subclipse displays an icon next to the file name (asterisk) which indicates that your local copy is different from what was in the repository
    when the file was checked out. This helps you know what to commit. Remember, if you create a new file, it will have a different icon(a small question-mark). The "changed" ...
    Tags: subclipse Add / Edit Tags
  18. Using interfaces in APIs

    by , 05-25-2011 at 09:59 AM (My Java Tips)
    When you are designing your API, you might want to use interface since this seems a common practice. There exist a style in Java programming where everything is expressed in terms of Java interfaces instead of classes.

    Using interfaces provides benefits but its not a good idea for an entire API to be expressed in terms of them.

    Use interface as a type if you have a good reason for it to be. Following are some important facts to be considered:

    Interfaces ...
    Tags: api, interface Add / Edit Tags
    Java SE
  19. Writing deployment descriptor

    by , 05-25-2011 at 09:57 AM (My Java Tips)
    If you writing J2EE applications, you need to deploy your application to J2EE container like JBOSS. I will shed some light on how to write simple deployment descriptors for your web applications.

    I am deploying my JSP application on JBOSS. For JBOSS, we need to put our application in WAR format in deploy folder. So deployment descriptor will have following 2 tasks:

    1. Archieve the application into WAR
    2. Copy that WAR to deploy folder of JBOSS

    Assuming ...
    Tags: j2ee, war Add / Edit Tags
    Java EE , JBoss
  20. Wrapping JDBC Objects

    by , 05-25-2011 at 09:55 AM (My Java Tips)
    In Glassfish connection pool has a property called "Wrap JDBC Objects" which can have value true or false. You may define it in domain.xml file.

    This property is defined as: "When set to true, application will get wrapped jdbc objects for Statement, PreparedStatement, CallableStatement, ResultSet, DatabaseMetaData".

    If you follow JDBC specifications, you will be see that obtaining connection using DataSource.getConnection() or other objects like ...
  21. hibernate.connection.rele ase_mode

    by , 05-25-2011 at 09:49 AM (My Java Tips)
    Hibernate JDBC/Connection's property hibernate.connection.release_mode is used to specify when Hibernate should release JDBC connections.

    A JDBC connection is held until the session is explicitly closed or disconnected by default. For a JTA datasource, one should use after_statement to aggressively release connections after every JDBC call. And for a non-JTA connection, it often makes sense to release the connection at the end of each transaction. will
  22. Hibernate Dialects

    by , 05-25-2011 at 09:46 AM (My Java Tips)
    To set SQL dialect, one has to set the hibernate.dialect property to correct org.hibernate.dialect.Dialect subclass for the database.

    Specify a dialect and then Hibernate will use defaults for some of the properties and this will save the effort of specifying them manually.

    Following dialects are supported.

    • DB2 org.hibernate.dialect.DB2Dialect
    • DB2 AS/400 org.hibernate.dialect.DB2400Dialect
    • DB2 OS390 org.hibernate.dialect.DB2390Dialect
    • PostgreSQL
  23. JSP Tags

    by , 05-25-2011 at 09:32 AM (My Java Tips)
    JSP tags are like HTML tags and they do not use <%. Instead they use < character.

    JSP tags can have a "start tag", a "tag body" and an "end tag". As you may have guessed, the start and end tag both use the tag name, enclosed in < and > characters. Just has HTNL tags, the ending JSP tag starts with a / character after the < character. The tag names have an embedded colon character : in them, the part before the colon describes the type ...
    Tags: jsp tags Add / Edit Tags
  24. XSLT Conditions

    by , 05-25-2011 at 09:30 AM (My Java Tips)
    Consider the scenario: You have xml data and you need to filter some data out. You may do that in Java but its open a good idea to keep the logic separate in XSLT filters.

    if-then-else condition is done the following way in XSLT:

    Java Code:
      <xsl:when test="...">
      <xsl:when test="...">
    Tags: xslt Add / Edit Tags
  25. Javap

    by , 05-24-2011 at 01:58 PM (My Java Tips)
    Javap is shiped with JDK and it really very useful when you want to see what your compiler is doing to your code. It generates source code from a compiled class file.

    Javap is a utility provided in Java Development Kit (JDK) that can be used to improve source code. this is done by generating source code from compiled code and seeing how our code was treated by the Compiler. Later code improvements can be made.

    A very interesting example can be to see how source code ...
  26. ArrayStoreException

    by , 05-24-2011 at 01:48 PM (My Java Tips)
    java.lang.ArrayStoreException is a runtimeException and is thrown when we try to store wrong type of object into an array of objects.


    Java Code:
    ArrayStoreException(String s)
    For example: Storing an Integer object in a Strign array will cause this exception.

    Java Code:
    Object x[] = new String[3];
    x[0] = new Integer(0);
    Since its a runtime exception, compiler won't ...
    Java SE
  27. Finalize

    by , 05-24-2011 at 01:46 PM (My Java Tips)
    All Java classes inherits the finalize() method from java.lang.Object and this method is called by the garbage collector when it determines no more references to the object exist.

    The finalize method performs no actions but it may be overridden by any class. It is overridden to clean-up non-Java resources ie closing a file, closing a connection etc. In overridding finalize() it is a good programming practice to use a try-catch-finally statement and to always call super.finalize(). ...
    Tags: finalize Add / Edit Tags
    Java SE
  28. Writing a file from JSP

    by , 05-24-2011 at 01:45 PM (My Java Tips)
    You may want to write a file from JSP page. For example, user fills a form and you want to persist the details on a text file on server. Now you need to know how to write text file from JSP.

    Remember, always give the path from root. In the given snippet, nameOfTextFile contains the file path. We will use FileOutputStream to write to the file.

    Java Code:
    <%@ page import="*"  %>
    String str = "form data goes here";
  29. Reading files from JSP

    by , 05-24-2011 at 01:44 PM (My Java Tips)
    Working in Servlets/JSP, you might have encountered The javax.servlet.ServletContext API. It provides methods to access resources in general.

    • getResource(String resource): will returns a URL for the resource in the web application.
    • getResourceAsStream(String resource): will returns an InpuStream for the resource in the web application
    • getResourcePaths(String path): will a directory-like listing of all the paths to resources within the web application.

    An example ...
  30. Using Java Beans in JSP

    by , 05-24-2011 at 01:42 PM (My Java Tips)
    JavaBeans are classes written in the Java programming language conforming to a particular convention.

    Consider the scenario: you are writing a JSP and you wish to write pure Java code in it. You may use scriptlets within JSP.

    Java Code:
    // Java code goes here
    Using scriptlets means that your JSP will contains business logic as well which is not a good design approach. Ideally you would like to keep business logic separately ...
Page 16 of 18 FirstFirst ... 61415161718 LastLast