Wednesday, September 5, 2012

Comparing String using the .equals method


Two String objects may be compared for equality by using the .equals function.

The equals method returns True or False (boolean).


String one = "Apples";
String two = "Oranges";

if (one.equals(two)) {
System.out.println("The strings match.");
}
else {

System.out.println("The strings DO NOT match.");
}



In this example, the equals method would return false, causing the statement "The strings DO NOT match" to be printed to screen.

The .equals function is available in all objects and Strings.

If you need to compare two primitive types such as int, read here....


Sunday, August 19, 2012

Your Sunday Cat


Customising Eclipse - Changing font size / appearance

Having trouble reading the code editor? You can customise the appearance (good for tired eyes!).


To customise the font appearance in Eclipse:
(Note: These screenshots have been created on a Mac)

Step 1
Locate Preferences
  • Mac: Eclipse > Preferences
  • PC: File > Preferences (from memory)

Locate the preferences menu

Step 2
  1. Go to General > Appearance > Colors and Fonts
  2. Select Java Editor Text Font from the list
  3. Click Change
  4. Select your desired settings and click OK


Changing font appearance settings




Customising Eclipse - Content Assist feature

Content Assist is a feature in Eclipse that provides context sensitive information about what you are typing. It can be particularly helpful for reminding you of the name of fields and methods.

By default, Content Assist is set to trigger when you type the period (.) character. This is useful, however in this guide I will show you how to get it to trigger at the beginning of a statement as well.

To customise how Content Assist works in Eclipse:

Step 1
Locate Preferences

  • Mac: Eclipse > Preferences
  • PC: File > Preferences (from memory)


Locate the Preferences in Eclipse

Step 2
Select Java > Content Assist
In the Auto Activation settings:
  1. set Auto activation delay to 0
  2. set Auto activation triggers for Java to a single space followed by a comma (,), followed by a period (.). (by clearing the textbox & typing)



Content Assist settings in Preferences



Changing the Auto activation triggers for Java


Step 3

Apply > OK

Try it

  1. type a single space in your code file to see that Content Assist pops up immediately
  2. type a character to see that Content Assist filters the list to names starting with that character
  3. use the arrow keys to move through the list and hit enter to insert the name
  4. place a period after the inserted name to see that Content Assist pops up immediately
Type a space at the beginning of a statement to activate Content Assist.


Type a period after a name to activate Content Assist.


Thursday, August 9, 2012

Naming a package


"Naming a Package (The Java™ Tutorials > Learning the Java Language > Packages)" ( http://bit.ly/N7Y70U )

Tuesday, August 7, 2012

equals


"Java: ==, .equals(), compareTo(), and compare()" ( http://bit.ly/Nygeae )

"Java Practices -> Implementing equals" ( http://bit.ly/MZN7Tb )

"Object equality - JavaWorld" ( http://bit.ly/MZNpJC )

FlowLayout


"FlowLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)" ( http://bit.ly/MZHggI )