Eclipse IDE Tips and Tricks

I wish I had know about these a couple weeks ago, but anyway here are a few tips and tricks I found for using the Eclipse IDE with Java:

// Eclipse tips and tricks
1. Quickly add main method by typing “main” followed by ctrl+space and then enter
2. Quickly format your source code by typing ctrl+shift+f or right click->source->Format
3. Type sysout then ctrl+space, then enter, to generate System.out.println();
4. F11 runs your application in debug mode – if no breakpoints, it will run normally
5. Hit ctrl+shift+o for organize imports. This will give you list of possible imports and then
add or the import to/from the top of the source file.
6. Type syserr and then ctrl+space to quickly type out System.err.println();.
7. to rename a variable, select the variable, right click, choose refactor -> rename, and all
of the instances where that variable name has been used will be changed.
8. You can rename a class as well by right-clicking on the .java file in the Package Explorer
pane, then -> refactor -> Rename.
9. When you highlight a line or block of code and push Ctrl + Alt together,
and the down arrow, it clones the line or block. (You may have to disable your intel
graphics card drivers or your screen will flip.)
10. Use Ctrl+Shift+/ to comment blocks of code and Ctrl + Shift + to uncomment them again.
11. If you want to find all the places a variable is used, right-click on the variable, choose
references -> workspace (or project, hierarchy). This will find all of the variables of
that name even in other classes/java files.
12. In order to find where a variable is declared, click on it, then press F3. This also works
for finding where other classes are declared in other files.
13. To remove/delete whole lines, click anywhere in the line and hit Ctrl+d.
14. Many methods, objects, arrays, etc will autocomplete. For example an array, type the
letter “A” then ctrl+space.
15. For new private fields, you can generate Getters and Setters automatically by right clicking
->Source ->Generate Getters & Setters. The same works for creating Constructors with the
correct parameters.
16. If you want to override methods in a superclass, right click -> source -> Override/Implement
methods…

I’m sure these will help me develop a little faster. Just formatting and adjusting my brackets to make things prettier has taken up a lot of time. Not to mention finding where variables are declared. I’m not familiar with what Getters & Setters or Overriding methods are used for at this time but apparently they are just busy work that is unnecessary to write out every time.

Android App Development with Eclipse, the Android SDK, and more Java

So my foray into Android App development has begun and I’m happy that I have eclipse up and running with the Android SDK. I have a virtual NexusOne up and running my first Hello World App. The only real snag I encountered was being unable to build an .apk and run my first few test apps because of the error: SDK does not have any Build Tools installed. I went to C:UsersJasonandroid-sdks and found that the Build Tools directory was empty (despite running the SDK manager and re-installing the Build-Tools component.) This was resolved by re-downloading the SDK, extracting the zipped files to C:Downloadsadt-bundle-windows-x86_64-20130522 and then manually copied the contents of the Build Tools folder from the unzipped location to my c:users directory.

HelloWorld

I’ve also progressed in my Java studies to become better at understanding and looking for what code will compile and which code will produce a compiler error. Also I’m becoming more comfortable with string arrays, getting java to find out how many words are in each list, generate random numbers that are constrained to a random number within the array, and building a string phrase using words within the arrays. For example:

String[] cats = {“Tricksie”, “Gunner”, “Bear”, “Apache”, “Esmeralda”};

int x = cats.length;

int rand1 = (int) (Math.random() * x);

String phrase = cats[rand1] ;

System.out.println(phrase + ” is a name for a cat.”);

– The first output could be: Bear is a name for a cat.

– The second output would probably be a different name and so on.

The logic of while and if methods can get tricky when creating an application that will output results when checking on conditions of your variables. For example,

class Test {

public static void main(String [] args) {

int x = 0;

int y = 0;

while ( x < 5 ) {

x = x + 1;

y = y + x;

System.out.print(x + “” + y +” “);

x = x + 1;

}

}

}

In this instance, the output would be:

11 34 59

If x starts out as a 0, then it passes the condition of being < 5 so it continues. x is added to 1 so it’s value = 0 + 1 = 1. It is told to print out it’s value as 1 and then add another 1 onto itself, and so on until it’s value is greater than 5, at which time the output ceases due to while condition no longer being true.

While, do-while, and for loops always has to pass a conditional test, or an expression that results in a boolean value; either true or false.