Skip to content

Tag: java

Java8 Lambdas vs Anonymous classes

Since Java8 has been recently released and its brand new lambda expressions looks to be really cool, I was wondering if this means the demise of the Anonymous classes that we were so used to. I’ve been researching a bit about this and found some cool examples about how Lambda expressions will systematic…

Is there a unique boot session id or count on an android device?

The app I’m writing needs to know if a ‘boot session’, for want of a better term, has changed but it doesn’t need to actually start at boot and I would prefer if possible not to have to use the RECEIVE_BOOT_COMPLETED permission. So I was wondering if there is any device-wide boot sessi…

dd/mm/yyyy vs dd/MM/yyyy?

Result is todays date i.e 23/03/2014 But when i do result can be 23/05/2014, 23/05/2014, 23/06/2014 and son with each run of prgram. Why so? Answer It’s because mm is for minutes, not months. More in the documentation.

How to trim out an array of integers in Java?

Let’s that I have a number N. N will be the size of the array. However, the contents of the array will hold every other number from 1 to positive N. This means that the entire size N array will not be full after that for loop. So after the for loop, I want to trim (or resize) the array

Understanding getInputStream and getOutputStream

Here is a code I have marked the statements that I have problems understanding. I do not understand what OutputStream object out will hold when it is assigned s.getOutputStream() and what is the need of passing buf to out by out.write(buf). I have learned Input and Output Streams using files but I do not unde…

Different Java Scanner for input of different types

Imagine the following scanario: I have a program which ask for an integer input, followed by a String input. With the aobe codes, I was not given a chance to enter the name. So normally I will declare 2 scanner objects as follows: My question is: Is it necessary to declare multiple scanner objects to accept i…