Search For Android .apk files in Google

April 9, 2011

To search for all apk files, in Google, type-

-inurl:htm -inurl:html intitle:”index of” apk

To search for games-

-inurl:htm -inurl:html intitle:”index of” apk games

To search for a specific app-

-inurl:htm -inurl:html intitle:”index of” apk AngryBirds

Have fun!

App Inventor: No Need For Signing Up. Open to All

December 19, 2010

App Inventor no longer requires signing up for access. Got a gmail account? So what are you waiting for? Visit the link and start developing for your android phones.  You are not much of a developer? Don’t like writing code? With App Inventor, you don’t need to. Visit and see what Google got for you!

Job Board – Flash Developer | Work from Home

April 5, 2010

Good at Adobe Flash? Wanna work from home? Hit the link below. If you think I know you in person, leave a message. I will see if I can recommend you. Good luck!

http://www.itpinoy.com/job/1826/flash-developers-home-based-at-id-leaders-three19/

Let’s Try to be a Good Programmer

February 6, 2010

I have been told that it is simple. Really it is. You got to have fun while programming. If it doesn’t interest you, this field is not yours. And yes, it applies to any other fields. Learn to go deep. Your learning curve should be full of challenegs and fun. It should be exciting to you like when you play a game, you want to finish strong. When you solve a problem, that’s not the end. Try to find other ways to solve the same problem. Try to foresee the future. Learn the difference between a solution and a good implementaion. A solution doesn’t make everything alright. How many ways can a problem be solved? Which one should you implement? Does it affect any phase of the development cycle? Think out of the box.

It is simple.. in a complex way. Go deep and yes, deeper. How far can you dig? Are you having fun while digging? Let’s try again.

Some Java Features You May Not Know Of

January 1, 2010

Caution: A long post ahead!

Some of the features listed here may appear obvious to some of you. Many programmers I know who are not aware of all these features. If you have read the language specification of Java or you studied for SCJP exam, none of these would appear anything new to you. This is sad that not all of us care to read the language specification or the virtual machine specification of Java. Some of us don’t even have a clear idea on the API.

Instance Initializers

Consider the following class:


public class SomeClass {

    public SomeClass () {
       System.out.println("Constructor Invoked");
    }

    static {
       System.out.println("Static Initializer Invoked");
    }

    {
       System.out.println("Instance Initializer Invoked");
    }

    public static void main(String... args){
       new SomeClass();
    }
}

Output:


Static Initializer Invoked
Instance Initializer Invoked
Constructor Invoked

Note that static block gets executed first and it gets executed once. If you try to call SomeClass() several times, only the first call of SomeClass will execute that static block. So, if you call-


new SomeClass();
new SomeClass();

It will print-


Static Initializer Invoked
Instance Initializer Invoked
Constructor Invoked
Instance Initializer Invoked
Constructor Invoked

Static block is pretty good if in the beginning of the class, you want to load some default resources like drivers. Instance initializer is better than using an init() method since it can initialize final fields.

Anonymous Class with Initializer Block

This is also called Double-brace Initialization. It’s a fancy way of referring to this feature. This feature creates an anonymous inner class and then creates an initializer block inside it, which lets you execute methods from a static context at any time. Note that since it actually creates an anonymous subclass of the object, or in other words, you implicitly hold a reference to the outer object, it can cause some unexpected memory leaks. This example is taken from the link provided. Take a look.

To pass a set to a method:


	Set validCodes = new HashSet();

	validCodes.add("XZ13s");
	validCodes.add("AB21/X");
	validCodes.add("YYLEX");
	validCodes.add("AR2D");

	removeProductsWithCodeIn(validCodes);

Or, to initialize a set of constants:


private static final Set VALID_CODES = new HashSet();
   static {
      validCodes.add("XZ13s");
      validCodes.add("AB21/X");
      validCodes.add("YYLEX");
      validCodes.add("AR2D");
   }

You can create and initialize a new collection as an expression by using the “double-brace” syntax:


private static final Set VALID_CODES = new HashSet() {{
    add("XZ13s");
    add("AB21/X");
    add("YYLEX");
    add("AR2D");
}};

Or:


removeProductsWithCodeIn(new HashSet() {{
   add("XZ13s");
   add("AB21/X");
   add("YYLEX");
   add("AR5E");
}});

Labeled Blocks

This is surprising to me that many Java developers are not aware of this feature or some think it can only only be used with a loop. Take a look at the following snippet-


private String setSomehing(final List codesInFile) {
    setCodeDesc: {
       if (codesInFile.contains("PA")) {
          break setCodeDesc;
       }
       if (codesInFile.contains("CA")) {
          break setCodeDesc;
       }
       return "No Charge";
    }
    return "Invalid Code";
}

Or you can use continue-


private void continueLabel(){
   someLabel:
      for (int i = 0; i < 2; i++) {
         for (int j = 0; j < 2; j++) {
            System.out.println(i + " " + j);
            if (i == j) {
               continue someLabel;
            }
         }
      }
}

If the above method gets executed, it would print-


0 0

1 0

1 1

Note that, you can only continue or break a label from within its scope. You cannot do this-


if (i ==0) {
   continue someLabel;
} else {
   //do something
}

someLabel: {
  //do something
}

Arrays.asList


   List<Integer> someList = Arrays.asList(12, 14, 18);

It’s a good combination of generic methods and autoboxing. Note that you cannot extend the size of this list. You cannot do someList.add(22); since the size is backed by the array as it is documented in the API. If you still want to add dynamically, you can wrap it with a constructor like-


   List<Integer>  someList = new ArrayList<Integer>(Arrays.asList(12, 14, 18));

Concurrency Tools

Concurrency tools have been introduced since JDK 1.5 which are cleverly implemented and robust, beyond just locks. You can find those in java.util.concurrent. A specifically interesting example is the java.util.concurrent.atomic subpackage that contains thread-safe primitives that implement the compare-and-swap operation and can map to actual native hardware-supported versions of these operations. Instead of using synchronized keyword, you can use Lock.lock() and Lock.unlock(). Instead of using wait() and notify() in the critical section use await() and signal() on condition variables. Take a look at the links provided. In DelayQueue, elements are made available after a specified delay. Also java.util.concurrent.TimeUnit is useful when converting between nanoseconds, microseconds, milliseconds and seconds.

Object Validation


String someString = null;

if( someString != null && someString instanceof String){
	System.out.println("true");
} else {
	System.out.println("false");
}

You can change if( someString != null && someString instanceof String) to if(someString instanceof String). The method instanceof checks for null automatically. The above code will print false.

Dynamic Proxy

Dynamic Proxy classes allow you to define a new type at runtime that conforms to an interface. It is handy to use a simple Class.forName(SomeClass).newInstance() where the class type is configurable.

VisualVM

If you are using JConsole, you might try /bin/jvisualvm.exe in your java installation directory. It is a new tool added to JDK 1.6_07+.

Enumeration

Enums are so object oriented that you can add methods and constructors to it. You can even use enums to implement an interface.

Examples:

public enum Color {

	WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);

	private int code;

	private Color(int c) {
		code = c;

	}

	public int getCode() {
		return code;
	}

Enum can implement any interfaces. All enum types implicitly implements java.io.Serializable, and java.lang.Comparable.


public enum Color implements Runnable {

	WHITE, BLACK, RED, YELLOW, BLUE;

	public void run() {
		System.out.println("name()=" + name() +
					", toString()=" + toString());
	}

	public static void main(String... args){
        for(Color c : Color.values()) {
               c.run();
        }
	}
}

..and some stuff (not features) you may want to know about

The finally Block

As I mentioned in my earlier post, you should not use return statement in a finally block-


public static void someMethod() {
    try {
         throw new RuntimeException();
    } finally {
         return;
    }
}

This RunTimeException will be lost because of the return statement in finally block.

Local Classes

A local class is a nested class that is not a member of any class and that has a name.


public class ClassInsideMethod {
	public String someMethod(){
		class Person {
			private String getPerson(){
				return "John";
			}
		}
		return new Person().getPerson();
	}

	public static void main(String... args){
		System.out.println(new ClassInsideMethod().someMethod());
	}
}

Comparator and TreeSet

Comparator can change the Set semantics-


import java.util.*;

public class ComparatorSet {

	public static void main(String[] args) {
		Set set = new TreeSet(new ChangeSemantics());
		set.add("Apple");
		set.add("Bannana");
		System.out.println(set);
	}

	public static class ChangeSemantics implements Comparator {
		public int compare(String left, String right) {
			return 0;
		}
	}
}

This will print- [Apple] Try changing the return value to 1 or -1 and see the result if you are confused. Note that TreeSet relies on Comparator to define equality. For instance, if you add System.out.println(set.contains(“Orange”)); in the main method, it will print true since you are returning 0 in compare(). If you return 1, it will print false obviously.

Integer.getInteger

The getInteger method confuses some developers. I ask this often to applicants during interviews. What would the following statement print-


System.err.println(Integer.getInteger("500"));

And no, it’s not gonna print 500! Check the API link provided.

Tricky

And this one (Taken from Joshua Bloch’s Effective Java), what would happen when the following snippet gets executed? I even get answer like – internet explorer would get launched?


System.out.print("iexplore:");

http://www.techhangout.com;

System.out.println(":maximize");

Highlight the text below to read the explanation if you haven’t figured it out.

JVM doesn’t see that as a url. It sees the colon after http which makes it think that it’s a label block followed by a comment because of //.

The Scripting API

With the Java Scripting API, it is possible to write customizable/extendable applications in the Java language and leave the customization scripting language choice to the end user.


System.out.println(new ScriptEngineManager().getEngineByName("JavaScript").eval("  5 + 5"));

Note that the space before 5 was intentionally placed as it behaves like JavaScript. It will print 10.0.

I wanted to include a lot more but this is really getting too long. Enjoy coding in Java!

System Design – Can I Borrow a Middle Name?

December 22, 2009

Last week I applied for an EON Cyber Account (a bank account for online transactions only) with a local Union Bank branch here in the Philippines. I got a call from them just a while ago saying that they cannot proceed with my application because their online system requires me to have a middle name! Yeah, wtf! I asked them if I could use any letter as my middle name since I don’t have one. They contacted their IT support and the main branch which confirmed- it’s simply not possible.

I needed this account quite badly as my other credit card applications were denied because of the fact that I’m a foreigner. That was frustrating and I was desperate.  I made several calls to find someone in Union Bank who I could ask – who designed your effing system?

Geez! Get a middle name!!!

When You Should NOT Follow your Role Models

December 16, 2009

 

Jeff Atwood

 

Jeff Atwood is one of the most popular bloggers in Software Development community today. He has been blogging since 2004. If you are a developer, you might have heard of him. It’s truly a sad thing that the server to which his blog Coding Horror is hosted on recently suffered a catastrophic data loss.

But that is not the whole story! The data was never backed up by the hosting provider. Even worse, Jeff doesn’t have backups of his own blog. Yes, you read it right! Did no one ever tell you how important it is to back up your data? Well, Jeff once did – here. He should have just subscribed to his own rss feed and store the data?

It’s like you are very concern about security when registering to a website, but you use a plain word as your password! For the love of God, haven’t you at least heard of Dictionary Attacks? Did Jeff ever get his password hacked? O yeah, he certainly did!

So, do you think some of your role models are just saying stuff to sound smart? Well, some do.

pi.es. I have learned many things from Coding Horror.. and it’s quite frustrating that hundreds of thousands treat him as a solid programming guy who does what he says!

Tricky try..catch..finally of Java

December 2, 2009

In Java, we all know that the finally block always gets executed unless System.exit() is called prior to that or if the JVM crashes first. So, let’s take a look in the following methods and figure out what would be the result after their executions-

private boolean testTryCatchFinally(){
 String value = null;
 try{
 // Throws null pointer exception
 int s = value.length();
 System.out.println("null");
 } finally {
 System.out.println("finally");
 return false;
 }
}

Highlight the white space below to see the result.
Output:
finally
The value w
ill be returned: false
Since a NULL doesn’t have a length, we gonna get a NullPointerException. Hence, jvm will proceed with the finally block.

Here’s another one with a slight modification-

private boolean testTryCatchFinally(){
 String value = null;
 try{
 // Throws null pointer exception
 int s = value.length();
 } catch (NullPointerException nullEx){
 return true;
 } finally {
 System.out.println("finally");
 }
 return false;
}

Highlight the white space below to see the result.
Output:
finally
The value will be returned: true
Just like
before we’ll get a NullPointerException. However, here we caught the exception, so catch block is supposed to get executed first and then finally block. But catch block has a return statement, jvm will see that and will proceed with the finally first. When it is done with finally, it will execute the return statement of catch block.

Now, here’s the tricky one. What will be returned if the following method gets executed?

private boolean testTryCatchFinally(){
 String value = null;
 try{
 // Throws null pointer exception
 int s = value.length();
 } catch (NullPointerException nullEx){
 System.out.println("catch");
 return true;
 } finally {
 System.out.println("finally");
 return false;
 }
}

Confused? It would print catch and finally both and would return false. Using return statement in a finally block is a bad practice.

How Can “while (i == i) ;” be a Non-infinite Loop in Java?

November 27, 2009

Before you see the answer, try to think for a second.  Threading is not an  issue here since the program is using only one thread.

The answer is below in white text. Highlight to read.

double i = Double.NaN;
while(i == i) ;
System.out.println("Not Infinite!");

NaN stands for Not a Number like in JavaScript.
Mathematically speaking, you cannot equate something
that is not a number with another.
Read the API.

Premature Optimization is the Root of All Evil

November 12, 2009

In Donald Knuth‘s paper “Structured Programming With Go To Statements“, he wrote: “Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

Have you seen a similar comment in any source code-

//
// Dear maintainer:
//
// Once you are done trying to 'optimize' this routine,
// and have realized what a terrible mistake that was,
// please increment the following counter as a warning
// to the next guy:
//
// total_hours_wasted_here = 16
//

I am not gonna write anything new on this topic as you can google it and find tons of research papers explaining the reason behind it.

Things to consider:

You might wanna right a cute algorithm, compress hundreds of lines of code into only a hundred lines, do you think it will be easy to understand, easy to debug, easy to maintain?

Do you think the optimization matters in the particular area of your program or you just want to make it look smart? If you are not sure, don’t optimize. 

Do you understand how memory and cpu work? If not, then don’t try to optimize a routine that deals with memory and cpu management unless it’s “obvious”.

You sure your optimization would not make the development more expensive? If not, then don’t.


Follow

Get every new post delivered to your Inbox.