Friday, January 14, 2011

Java Introduction / Cheat Sheet

› I will continue to add to this article over the coming weeks.
Setup:
You'll need to download and install two things to get started coding:
  • Java SE 6 JDK (Java Platform, Standard Edition 6 Development Kit)
    - Choose your operating system and platform and download the JDK version, not the JRE (only the runtime environment)
  • Eclipse IDE (Integrated Development Environment)
    This is the interface through which you will be programming, compiling, and running and testing code


Hello world:
This simple program will output the text, "Hello, World!" (without quotes).

The program is composed of a class definition named HelloWorld.  The HelloWorld class runs from the first opening brace ({) to the last closing brace (}).  All Java programs use class definitions.

The next portion of code sets up the main method.  Methods define the operations that an object or program will perform.  The code in a method lives inside another set of braces ({}) In this case, the program is simply printing a line that says "Hello, World!" using the println (print line) method of the out object, which is stored in Java's predefined System class.
public class HelloWorld
{
    public static void main (String[] args)
    }
      System.out.println ("Hello, World!");
    }
}
That's it! This Java program contains just three simple steps:
  • Define a class named HelloWorld.  Its code is included between two braces
  • Define a method named main that has a few settings that aren't really important to know about yet, but can be explained a bit further in this Java tutorial.  The code between the method's braces will be instructions to be performed by the program
  • Call the println method from the System class's out object to write "Hello, World!" as output.  This instruction is ended with a semicolon (;)

Comments:
Comments are an efficient and important way to provide documentation and insight as to what your program is doing at any given point in the code.  Be sure to include detailed descriptions to help you or another programmer when returning to review or revise the code at a later time.


// Single-line comment

// This can be attached after some code on a line.
// Anything after these slashes on the same line 
//   will be omitted

/* A comment spanning several lines:
EVERYTHING between these comment marks will
be omitted by the Java interpreter */


Variables & Constants:
Variables and constants are places in code to store information for the program to use and reference.  Variables are dynamic; in that once they are created they can remain blank or equal to zero, or they can hold text or numeric information or be set to true or false.  Examples include any kind user provided data, an e-mail address, age, phone number, number of stars given on a restaurant or movie review, a program iteration number, amount of records in a database, etc.  Further, they can be changed at any time, or erased and set back to their original "blank" or "null" state.

Constants, on the other hand, can also hold data, though these will be set once when the program begins and will remain the same throughout the program's life.  Examples include the number pi, thresholds (1 millionth customer at a store, the upper limit of $1.00 on the Price is Right Showcase Showdown), freezing/boiling points of water in °F/°C/°K, etc.

Identifiers: are variables, constants, reserve words, etc.
  • Alphanumeric, underscores (_),  and dollar signs ($)
  • Case sensitive
  • Can be any length
  • Must not begin with a number
Acceptable:
int_Value, String3, $LakeSize, _StreamSize, $100, a_very_long_stupid_string_that_should_be_shortened

Unacceptable:
int-Value, 3rdString, Lake Size, _Stream#Size...


Escape Sequences:
This is a list of special characters that can be used in a program which would otherwise cause a compile-time, run-time, or logic error if entered directly.  For instance, entering """ (a string containing a double quote character) will cause a compile-time error because the the middle quotation mark will be interpreted as the end of a blank string.  Instead the code would need to be entered as "\"".

SequenceOutput
\bbackspace
\ttab
\nnewline
\rcarriage return
\"double quote
\'single quote
\\backslash

Conditional Operators:

Equality / Relational
OperatorValue
==equal to
!=not equal to
<less than
<=less than or equal to
>greater than
>=greater than or equal to


Logical
OperatorValueUse
!NOT! a
&&ANDx && y
||ORx || y




Resources:
Java Foundations, 2nd Edition
John Lewis, et. al



Monday, January 3, 2011

Remove Cryptic Folders in XP


I've seen a lot of these weird, cryptic folders appearing on the root of my Windows XP machine for a while but never knew what to do with them.  I had data "Ghosted" over from a previous hard drive that had a mechanical failure, and most of these appeared after the recovery.  These are all seemingly random combinations of letters and numbers between 20 and 30 characters long on the root of my master hard drive (C:\).

Reading a few forums/technical documents gave me the impression that these are temporary directories and files that are left over from updates that have occurred in the past.  These should have been automatically removed, but they are often left behind.  Other users in my office have a couple of such folders laying around, and my computers at home have one or two as well, although my work machine has a couple dozen, which take up almost 3 GB of hard drive space!  As far as I can tell, these left over, benign files can and should be removed.

Attempting to delete any of these folders simply return security/access errors, so I tried to delete them using Windows Explorer in Safe Mode.  No luck.  I then tried using a del command in Safe Mode's Command Prompt.  No luck either.

The trick is to set Delete permissions for the administrator/user.  It may help to be in Safe Mode, but I was able to delete some without being in Safe Mode.  My account also has Administrative privileges, so that is more likely necessary.

The following are two methods for removing these data.  "Individually" contains the method that illustrates how to access the specific setting that is restricting these files/directories from being deleted.  "En masse" is a faster method to delete all of these folders at once.

Remove Individually:
  •  Right click on a folder or a file and select Properties
  • Navigate to the Security tab and click the Advanced button toward the bottom of the dialog box
  • Highlight one entry at a time, starting with Administrators, and choose Edit (or just double click an entry to edit its permissions)
  • Scroll down and check the box to Allow this entity Delete permissions.  Remove any Deny permissions if that happens to be selected, but these boxes should be blank.  Click OK once to return to the "Advanced Security Settings for [Folder Name]" dialog
  • Repeat the previous two steps for teach additional entry in this list.  Others may include SYSTEM, CREATOR OWNER, Users [...], etc.
  • Now deleting the folder or file should not return any errors and the data can be deleted normally
Remove En Masse:
  • Select all cryptic folders.  Be sure not to include system/necessary program folders in this selection (see the graphic at the top of this article)
  • Right click and select Properties to open the properties for all directories
  • Click on the the Security tab.  You will be prompted with a Security warning
  • When prompted, choose Yes to reset security permissions for all selected folders
  • All permissions will now be reset to "Allow," specifically the Delete process
  • Now deleting the folders or files should not return any errors and the data can be deleted normally
Additional resources:
 - How to take ownership of a file or a folder in Windows XP