Thales Android Interview

Android

1) Difference between Service and Aysnc Task.
2) What is Broadcast Receiver and when to use one.
3) What is fragment
4) Tell the activity lifecycle
5) Why do we use DDMS
6) adb commands used by you

 

Java
1) What is static method
2) What values can be accessed from a static method in java


Git

1) Git command to add a file

2) Difference between git pull rebase vs git pull merge
https://www.atlassian.com/git/tutorials/merging-vs-rebasing

SQL
1) Difference between inner join and full join


Network

1) How to send a file from computer to server
2) What is ssh command

Linux
1) List the top 10 process which are taking most CPU.

Advertisements

Rounding off double to specified number of digits

You can’t set the precision of a double (or Double) to a specified number of decimal digits, because floating-point values don’t have decimal digits. They have binary digits.

You will have to convert into a decimal radix, either via BigDecimal or DecimalFormat, depending on what you want to do with the value later.

DecimalFormat df = new DecimalFormat("#.####");
df.setRoundingMode(RoundingMode.CEILING);
for (Number n : Arrays.asList(12, 123.12345, 0.23, 0.1, 2341234.212431324)) {
    Double d = n.doubleValue();
    System.out.println(df.format(d));
}
You can try BIGDECIMAL for this purpose

Double toBeTruncated = new Double("3.5789055");

Double truncatedDouble = new BigDecimal(toBeTruncated)
    .setScale(3, BigDecimal.ROUND_HALF_UP)
    .doubleValue();

CS General Concepts

1) What is POSIX?

The Portable Operating System Interface (POSIX)[1] is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines the application programming interface (API), along with command line shells and utility interfaces, for software compatibility with variants of Unix and other operating systems.