Q:

Understanding if data exists in Firebase

I am using the following to fetch a username from Firebase. But in this case, how do I get to know, if the username exists or not.
Firebase firebaseRef = new Firebase("<Firebasae_URL>/Users");
Query query=firebaseRef.orderByChild("username").equalTo("username");

A:

So in your case the code should be like this, to find an username exists in your database.
Firebase firebaseRef = new Firebase("<Firebasae_URL>/Users").child("username");
firebaseRef.addListenerForSingleValueEvent(new ValueEventListener) {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        if (dataSnapshot.exists()) {
            // User Exists
        }
    }

    @Override
    public void onCancelled(FirebaseError firebaseError) {

    }
});

