Category: Programming

What happens if you write something like a = a++ in Java?

I often happened to see discussions about this topic. Basically, here is the question. If you have such a code:

   
int a = 0;
a = a++;
System.out.println(a);

What does it print?

More than 50% of the programmers will answer 1, some of the remaining will say “I don’t know” and the others will say 0. Well “the others” are right!

Provided that such a code MUST NEVER BE WRITTEN, let’s try to understand, for academic purposes, why it prints 0.

Read more...

Using dynamic SQL statements from PL/SQL

Sometimes you need to execute dynamic SQL statements. Starting from Oracle8i you can accomplish this task using the EXECUTE IMMEDIATE statement. Here are three examples of how you can take advantage of this great statement.

    
sql_select := 'SELECT * FROM your_table WHERE field1 = :1';
EXECUTE IMMEDIATE sql_select
INTO your_cursor
USING your_parameter_for_field1;

In this first example I showed how you can use EXECUTE IMMEDIATE to execute the query and put the result into a cursor. The USING your_parameter_for_field1 part replaces the :1 bind variable with the value contained in the your_parameter_for_field1 parameter.

Read more...

How to hide/show an HTML form element depending on a combo box choice

This is an example of how you can show/hide an HTML form element depending on a combo box choice.

Put the following JavaScript code between your <head></head> section (or within a .js file if you prefer).

  
<script language="javascript" type="text/javascript">
  function hide() {
    var text = document.formName.textBox;
    if(document.formName.combo.value == "hide") {
      text.style.visibility = "hidden";
    }
    else {
      text.style.visibility = "visible";
    }
  }
</script>

The following snippet of code instead is the HTML code to use to call the hide function.

Read more...

POJO (Plain Old Java Object): The simpler...the better.

A POJO is simply an object built using a Java class that does not implement any special interfaces such as those defined by the EJB 2 framework. An example of a POJO is a class composed by only:

  1. Properties, representing the object’s state.
  2. Getter and setter methods for the properties.
  3. Business methods, representing behaviour.

Some properties can represent associations with other POJOs. Here is an example of implementation of the Person entity using a POJO:

Read more...