Archive for January, 2009

Download Free Legal Microsoft Software

Microsoft has in the past offered their software to college/university students free of charge. The key was you needed to be an active student and find the download from the university/college website. Now, there is a website called Dreamspark where all the free software can be found! Some of the software available include:

  1. Microsoft Visual Studio 2008 Professional Edition
  2. Microsoft Visual Studio 2005 Professional Edition
  3. Microsoft Visual Studio 2005 Express
  4. Microsoft Expressions Studio 2
  5. Microsoft Sql Server 2008 Developer
  6. Microsoft Sql Server Express
  7. Windows Server 2008 Standard
  8. Windows Server 2003
  9. XNA Game Studio 2.0
  10. Microsoft Visual C# 2008 Express Edition
  11. Microsoft Visual Basic 2008 Express Edition
  12. Microsoft Visual C++ 2008 Expression Edition
  13. Microsoft Visual Web Developer  2008 Express Edition
  14. Microsoft Virtual PC

All software either comes embedded with a serial key or can be obtained through the website. All that is required is an email address of the college in which you attended. A copy of the software can be downloaded directly from Dreamspark.

New to the site is free download for high school students. All you need is to get your High School administrator to register on the Dreamspark and you can get your free legal copy. Visit Dreamspark to find more information.

Comparisons in Java

When comparing objects, it is useful to know the difference between  == and the equals() method.

The == comparsion is used to compare the values of two objects to see if they refer to the same object.  Note there are 8 primitives in Java:  boolean, byte, char, double, float, int, long, and short. In the example below, you will see why a String comparison will not work for the == comparison. This is because the == comparison is used as an equality operator to compare two like primitive values.

Ex 1:

if( a == "abc")  // FALSE

Ex 2:

String a = "abc";
String b = "abc";
if(a == b) // FALSE because they are two separate String objects

Ex 3:

int i = 1;
int j = 1;
if( i == j)  // TRUE

The equals() method is used to compare two object values to see if they are identical. This method is not used on primitive values.

For example,

String name = "abc";
if(name.equals("abc")) // TRUE

How to Hide/Show Html Elements

An HTML website contains mainly text, images, and link controls. A common way of organizing all the controls is by placing the elements into a <div> control. With a <div> control, you can manipulate everything from the font to placement in an HTML page using CSS (cascading style sheets). Note that although the CSS code for manipulation is beyond the scope of this tutorial, we will be using CSS to state whether or not to display a div box.

We begin with an example of a <div> control. At this point, the code does nothing special.

<body>
  <div id="myDivBox">
    <h2>My Title</h2>
    <p>This is some sample text</p>
  </div>
</body>

Next, we add CSS that controls whether or not to display the content of the <div> control. The CSS attribute is the keyword ‘display’. The ‘display’ keyword accepts the values ‘block‘, ‘none‘, ‘list-item‘, and ‘inline‘. Our example will utilize ‘none’ that hides the <div> control and ‘block‘ that will display it (as a block as opposed to inline). Our <div> control will intially begin hidden, so let’s add a style attribute to the <div> control as shown below.

<body>
  <div id="myDivBox" style="display:none;">
    <h2>My Title</h2>
    <p>This is some sample text</p>
  </div>
</body>

Next, we will add javascript method to control the CSS attributes of our <div> control. As with all javascript, the script belongs in the head. The method is called toggleDiv and accepts no inputs. What the script is doing is checking if the <div> control is in a ‘block‘ or ‘none‘ state. Whichever state is found, we set the opposite.

<head>
  <script type="text/javascript">
    function toggleDiv()
    {
      if (document.getElementById("myDivBox").style.display == "block")
      {
        document.getElementById("myDivBox").style.display = "none";
      }
      else
      {
        document.getElementById("myDivBox").style.display = "block";
      }
    }
  </script>
</head>

Finally, we will add an input button that will toggle whether or not to display the <div> control. The input button will call the javascript method via an onClick action.

<body>
  <input type="button" value="Toggle" onclick="toggleDiv()">
  <div id="myDivBox" style="display:none;">
    <h2>My Title</h2>
    <p>This is some sample text</p>
  </div>
</body>

Here is a working example:

A complete HTML example is listed below. To run this, simply copy the code into a file with an html extension.

<html>
  <head>
    <script type="text/javascript">
      function toggleDiv()
      {
        if (document.getElementById("myDivBox").style.display == "block")
        {
          document.getElementById("myDivBox").style.display = "none";
        }
        else
        {
          document.getElementById("myDivBox").style.display = "block";
        }
      }
    </script>
  </head>
  <body>
    <input type="button" value="Toggle" onclick="toggleDiv()">
    <div id="myDivBox" style="display:none;">
      <h2>My Title</h2>
      <p>This is some sample text</p>
    </div>
  </body>
</html>