View RSS Feed

All Blog Entries

  1. Enabling Debugging

    by , 10-25-2011 at 08:08 PM (My Java Tips)
    There are different ways to enable debugging in Glassfish. Let's start with enabling debugging using administration console.



    To enable debugging follow the following after each server restart:

    - Login to the Administration Console using web browser:
    http://host:port/asadmin
    For example:http://localhost:4848/asadmin

    - Go to the Application Server page.

    - Select the JVM Settings tab and the General option.
    ...
    Categories
    Glassfish
  2. Working with XML data

    by , 10-25-2011 at 07:59 PM (My Java Tips)
    Hibernate allows us to work with persistent XML data same as POJOs. A parsed XML tree is actually a representation of relational data at the object level, instead of POJOs.




    Hibernate uses dom4j API for manipulating XML trees. We can write queries that retrieve dom4j trees from the database and then all modifications to the tree automatically are synchronized to the database.

    One can take an XML document, parse it using dom4j, and write it to the database ...
    Categories
    Hibernate
  3. Hibernate - Fetching strategies

    by , 10-25-2011 at 07:49 PM (My Java Tips)
    Hibernate uses fetching strategy for retrieving associated objects when an application needs to navigate the association. Fetch strategies are declared in the object relational mapping metadata, or over-ridden by a particular HQL or Criteria query.




    Hibernate defines following fetching strategies:

    - Join fetching is used to retrieve the associated instance or collection in the same SELECT, using an OUTER JOIN.

    - Select fetching is used ...
    Categories
    Hibernate
  4. Hibernate Filters

    by , 10-21-2011 at 08:40 PM (My Java Tips)
    A Hibernate filter is a global, named, parameterized filter that may be enabled or disabled for a particular Hibernate session. Filters can be used like database views.




    Filters were introduced in Hibernate3. Using filters, you can define filter criteria and attach those filters at class and a collection level. A filter criteria is actually defining a restriction clause. This is same as "where" attribute available on the class and various collection elements. ...
    Categories
    Hibernate , XML
  5. "Hello world with Java"

    by , 10-21-2011 at 05:53 AM
    Hello,
    This is my first blog on the internet EVER lol

    I have just started to read the book Thinking in Java 3rd edition, its starting out to be very helpful talking about object in memory and where this all fits in with object oriented programming. I still have not yet done any work with the Stack data structure but I am hopeful by the end of the month that is shall!

    If anyone out there reads this and wanted to talk more about object oriented programming or Java ...
    Tags: java Add / Edit Tags
    Categories
    Uncategorized
  6. Breakout Tutorial

    by , 10-21-2011 at 01:32 AM
    The first step in designing something is to think it through. What pieces should it have and how should they work together? What methods, and instance variables should a class have? Let’s start by naming the classes we will need for brick breaker (or breakout/whatever you want to name it).

    We will need a paddle which the player controls, a ball which moves around the screen, and the bricks which are meant to be broken. There will also be a canvas class which everything is drawn upon. ...
    Categories
    Uncategorized
  7. Setting JWindow or JFrame Opacity

    by , 10-17-2011 at 10:37 PM
    Ever wanted to try and set the transparency level of some JWindow's or JFrames? Here is another snippet of code to keep close by that might come in handy.

    Java Code:
    try {
    	Class<?> awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
    	Method method = awtUtilitiesClass.getMethod("setWindowOpacity", Window.class, float.class);	
    		
    	method.invoke(null, /*JFrame or JWindow here*/, /*The opacity level in float value from 0.0 to 1*/);
    ...

    Updated 10-19-2011 at 10:41 AM by DuvanSlabbert

    Categories
    AWT and Swing
  8. Setting JWindow or JFrame Opaque

    by , 10-17-2011 at 10:31 PM
    Ever tried setting the visibility of a rootpane on your JWindow or JFrame without loosing visibility of the components on that JWindow or JFrame???

    Here is a little snippet of code to keep close by as it might come in handy

    Java Code:
    try {
    	Class<?> awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
    	Method method = awtUtilitiesClass.getMethod("setWindowOpaque", Window.class, boolean.class);
    	method.invoke(null, /*JFrame
    ...

    Updated 10-19-2011 at 10:34 AM by DuvanSlabbert

    Categories
    AWT and Swing
  9. Adding "Global" KeyListener

    by , 10-17-2011 at 07:00 PM
    Want to add a so called "Global" Keylistener to your Java application even if it is a JWindow or JFrame without having focus on it. Just download the file in the link and extract, add the jhook.jar file to your project library and use this demo code to get the keys pressed.

    Java Code:
    Keyboard kb=new Keyboard();
            kb.addListener(new KeyboardListener() {
                public void keyPressed(boolean keydown, int vk){
                    System.out.println(vk);
    ...

    Updated 10-19-2011 at 09:33 AM by DuvanSlabbert

    Categories
    AWT and Swing
  10. Packages, accessibility/visibility, synthetic access and protected constructors

    by , 08-12-2011 at 08:21 PM
    In Java it is common to use packages, especially for libraries.
    Two common packages, that are built in to Java, are java.io and java.util.
    (Another, even more common is java.lang, but that one is imported automatically.)

    Before you can use a package [without using the reflection classes] you most import it in
    the file (not class) that uses it. To import the package java.io, you add the line
    Java Code:
    import java.io.*;
    just below your package line (if any; otherwise ...
    Categories
    Java's syntax
  11. Linux terminal magick, part 2

    by , 08-12-2011 at 06:05 AM
    In the previous part if ”Linux terminal magick” we show how to let use user use ^C and ^\ in the terminal, that was the last part of creating a graphical terminal user interface. The parts are [almost] not ordered!

    For this part we add two more functions:
    Java Code:
    /**
     * Sets the the value of the ECHO flag; iff on the input to the terminal will be echoed back while typing.
     * This can be used to hide what the user is type, for example when a password is requested.
    ...

    Updated 08-12-2011 at 06:42 AM by Hibernate

    Categories
    Terminal cues , Linux
  12. The Multiton pattern

    by , 08-12-2011 at 05:39 AM
    The Multiton pattern is a pattern missing from ”the pattern bible”. It is extensive to dual layer (and beyond), but that is left for you to use intuitively when needed, it is not too difficult to do so.

    The Multiton pattern is an extension of Singleton pattern.
    Multiton lets you create and get any number of instances, they are distinguished by keys,
    so if you want instance "a" it creates it for you the first time, and returned the created instance the next ...

    Updated 08-12-2011 at 07:16 PM by Hibernate

    Categories
    Patterns
  13. The Singleton pattern

    by , 08-12-2011 at 05:29 AM
    In mathematics a singleton (not to be confused with a simpleton) is a set with exactly one element.
    In computer science Singleton is a pattern which enforces the existence of only up to one instance of a class.

    Singleton is sometimes considered an anti-pattern, and it's famous for being considered unnecessary in the world of Python (where you duck type).
    Singleton is however useful, it is a nice and clean why to restrict the number of instances, to only one.
    In ...

    Updated 08-12-2011 at 07:13 PM by Hibernate (typo)

    Categories
    Patterns
  14. Linux terminal magick, part 1

    by , 08-12-2011 at 02:15 AM
    Are you a hardcore GNU/Linux user like me?
    Then you are probably sick of Java (natively) not letting you print in the terminal with colours.
    In a series of Web logs, I will describe how to, in GNU/Linux, print in the terminal with colours and other stuff.
    Keep in mind that you need a TTY (e.g. gnome-terminal, xterm, Linux VT (linux)), Eclipse's built in console will not do.

    We will begin with letting Java accept ^C and ^\ (also know as ^4) from the terminal. ...

    Updated 08-12-2011 at 06:42 AM by Hibernate

    Categories
    Linux , Terminal cues
  15. Variadic functions (varargs)

    by , 08-12-2011 at 01:47 AM
    Ever heard of variadic functions of varargs.
    It is my favourite synthetic sugar (although I must admit i prefer cane sugar).

    Variadic functions have undefine arity (the parameter is called a "vararg" (variadic argument)), meaning
    that it lets you use any amount of parameters when invoking it.

    For example:
    Java Code:
    public class MyClass
    {
        private static void print(final String prefix, final int... lines)
        {
    ...

    Updated 08-12-2011 at 06:44 AM by Hibernate

    Categories
    Java's syntax
  16. Unusual members, part 2

    by , 08-12-2011 at 01:22 AM
    Just like there is a static, otherwise headless, method, the class initialiser, this is an object initialiser (or just initialiser), that is a non-static and completely headless.

    Java Code:
    public class MyClass
    {
        public static class Subclass extends MyClass
        {
            {
                System.out.println("Subclass Initialiser 1");
            }
            public Subclass()
            {
                System.out.println("Subclass
    ...

    Updated 08-12-2011 at 06:45 AM by Hibernate

    Categories
    Java's syntax
  17. Unusual members, part 1

    by , 08-12-2011 at 01:09 AM
    Did you ever want to run something the first, and only first, time a class was being used.
    Perhaps wanted to do some complex calculations and assign it to a constant.

    One way to do this is by writing, for example:
    Java Code:
    public class YourClass
    {
        public static final int YOUR_CONSTANT = constantValue();
    
        private static int constantValue()
        {
            int value1 = 0, value2 = 1;
            int value = 0;
            for
    ...

    Updated 08-12-2011 at 06:45 AM by Hibernate

    Categories
    Java's syntax
  18. Legal forward reference assignment weirdness on declarations

    by , 08-12-2011 at 12:38 AM
    Observer the glorious code by your's truly Hibernate:

    Java Code:
    public class YetAnotherClass
    {
        //public static final int YET_ANOTHER_CONSTANT = YET_ANOTHER_CONSTANT; //Compile-time error: illegal forward reference
        public static final int ANOTHER_CONSTANT = YetAnotherClass.ANOTHER_CONSTANT; //OK!
    
        //public int yetAnotherVariable = yetAnotherVariable; //Compile-time error: illegal forward reference
        public int anotherVariable = this.anotherVariable
    ...

    Updated 08-12-2011 at 06:46 AM by Hibernate

    Categories
    Java's syntax
  19. The Decorator pattern

    by , 07-23-2011 at 03:42 PM (JosAH's blog)
    Greetings,

    the previous blog article talked a bit about the Visitor design pattern. This article talks a bit about additional functionality that is sometimes wanted, i.e. the functionality is optional. Assume there is a lot of optional functionality that people want.

    This article discusses the Decorator (or 'Wrapper') pattern. For the sake of the example we'll use array manipulation. People always fiddle diddle with arrays, i.e. they copy values from one array to another, ...

    Updated 07-23-2011 at 03:45 PM by JosAH

    Categories
    Uncategorized
  20. The Visitor pattern

    by , 07-23-2011 at 03:35 PM (JosAH's blog)
    Greetings,

    Java claims to support OO, so why not use it? In this article we're going to talk a bit about when and why to apply certain patterns. We'll start with the Visitor pattern. The pattern is also named 'double dispatch' which will become clear near the end of this little article. Here's the story:

    Suppose some time ago you wrote a bunch of beautiful, efficient classes; they're real gems. For the sake of this article let's use the following classes:
    ...
    Categories
    Uncategorized
  21. Java ArrayList : Generics & Sorting

    by , 07-21-2011 at 07:20 AM


    Abstract

    Java ArrayList (ArrayList (Java 2 Platform SE 5.0)) class is a fastest and easiest way to represent one-dimensional array. ArrayList not synchronized, that is cross thread access may cause problems. It holds an ordered item sequence of items (objects) like an array, but there are differences:

    • Size of an ArrayList could change dynamically, by adding or removing elements
    • An ArrayList can hold only object references, not primitives

    ...
    Attached Thumbnails Attached Files
  22. Compilers

    by , 07-16-2011 at 05:41 PM (JosAH's blog)
    Greetings,

    Frequently a question pops up in this forum (or other forums for that matter) where the OP wants to implement a calculator or wants to compile an expression given in text (String) form. Often they get lost in tokenizers or regular expressions or whatever. This article describes how a compiler (for expressions) can be designed and implemented. The attachment contains a zip file with all the sources for a complete compiler.

    Top level architecture
    ...

    Updated 07-18-2011 at 06:18 PM by JosAH

    Categories
    Uncategorized
    Attached Thumbnails Attached Files
  23. jmap - jdk provided heap observation utility

    by , 06-25-2011 at 02: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 ...
    Categories
    Uncategorized
  24. Sudoku

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

    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 04:52 PM by JosAH

    Categories
    Uncategorized
  25. Book Recommendations

    by , 06-20-2011 at 10: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?
    ...
    Categories
    Uncategorized
  26. Recursion

    by , 06-20-2011 at 05:39 AM
    Recursion:


    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 05:48 AM by sunde887

    Categories
    Uncategorized
  27. Script Engines

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

    Introduction

    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 11:10 AM by JosAH

    Categories
    Uncategorized
  28. Heap Sort II

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

    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 05:30 PM by JosAH

    Categories
    Uncategorized
  29. Heap Sort I

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

    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

    Categories
    Uncategorized
  30. Lazy associations

    by , 06-02-2011 at 08: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 ...
Page 46 of 48 FirstFirst ... 364445464748 LastLast