Monday, 11 April 2016

Top 10 Android Interview Questions Answers for Java Programmers

How many interview question do you prepare before going for any Android or Java interview? not many right. In this article, we will explore some of the most frequently asked Android interview questions. Android is very hot nowadays as its one of the top operating system for Mobile and Smartphone and the close rival to Apple's iOS. Android application developer job is in demand as well. I have also seen a couple of Java questions in Android interview as well. It means it's better to prepare some Java questions as well. Following Android Interview Questions are very basic in nature but appear frequently on beginners or Intermediate programmer level on various Android interview. I have not provided answers of this question as it can easily be found by doing the google. If needed I will update this Android interview questions with answers as well. These questions are good for recap and practice before going to Android interview.



Android Interview Questions answers
Here is a couple of interview questions from Android operating system, It is collected from various telephonic and face-to-face interviews. Any Java programmer can use it to prepare for Android interview.

Question 1: What is the difference between a regular .png and a nine-patch image?
Answer: This is one of the most popular Android Interview questions, asked in several interview ranging from 1 to 2 years of experience to 5 years. The answer is, It is a resizable bitmap resource that can be used for backgrounds or other images on the device. The NinePatch class permits drawing a bitmap in nine sections. The nine patch images has extension as.9.png. It allows extension in 9 ways e.g. 4 corners that are unscaled, 4 edges that are scaled in 1 axis, and the middle one that can be scaled into both axes.


Question 2: What is an ANR notification in Android?
Answer: ANR is short for Application Not Responding. Android systems show this dialog if the application is performing too much of task on the main thread and been unresponsive for a long period of time.

Question 3: How to share content using Android Share Intent?
Share intent is an easy and convenient way of sharing content of your application with other apps.


Question 4: When does onResume() method called?
Another frequently asked android interview question. onResume() method is an activity lifecycle method. This is called when the activity comes to the foreground. You can override this method in your activity to execute code when activity is started, restarted or comes to the foreground.


Question 5:
 What is an action in Android?
A description of something that an Intent sender desires.

Question 6: What is the difference between an implicit intent and explicit intent?
There are Two types of Intent implicit and explicit intent, let see some more difference between them.

1) implicit:-
Implicit intent when you call system default intent like send email, send SMS, dial number etc
e.g.:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
sendIntent.setType("text/plain")
startactivity(sendIntent);

2) Explicit :-
Explicit intent when you call you're on application activity from one activity to another
e.g. first activity to second activity

Intent intent = new Intent(first.this, second.class);
startactivity(intent);

Question 7: What is APK format?
The APK file is compressed AndroidManifest.XML file with extension.apk, Which have application code (.dex files), resource files, and other files which are compressed into single .apk file.

Question 8: What is Dalvik Virtual Machine?
Just like Java application run on Oracle HotSpot JVM or Azul JVM,  Android application runs on the Dalvik Virtual Machine.

Question 9: How Android app runs inside Android mobile?
 (answer)
Since Android code is written in Java, they are also compiled first and then executed, but the JVM for which the bytecodes are generated is different than standard JVM. The Dalvik JVM is used to run Android app. See the answer for more detailed discussion.
Android Interview Questions and Answers


Here are some more frequently asked Android Interview questions for Java Programmers:

1.What is Android? is it an Operating System or programming language?
2.Which programming language is used to develop an application in Android?
3.Which devices have you worked on Android platform?
4.What best practices you follow to ensure that your application work on multiple Android devices of different screen size, processing power and features?
5.What is Activity and Intent in Android? What is the difference between Activity and Intent?
6.What kind of application have you developed on Android platform? Games, application
7.What is Android manifest file? Why do you need this?
8. How do you implement Internationalization and Localization in Android application?
9. How do you find IMEI and IMSI number of an Android device


If you have faced any
 interesting Android Question or looking for the answer of any tricky Java question or Android question then you can share with us as well.

Other Interview Question articles from java blog

Read More »

Top 10 Android Interview Questions Answers for Java Programmers


Read More »

10 Linux and UNIX Interview Questions and Answers asked in Wipro TCS Capegemini

 UNIX and Linux Interview Questions and Answers
Questions from various UNIX operating systems e.g. Solaris, Linux, IBM AIX or any other UNIX operating system is asked on different support and programming interviews. I have always seen few interview questions from Linux and UNIX along with SQL in almost every Java programming interviews. You just can not afford not to prepare questions from UNIX and Linux until your Job absolutely doesn't require any work in UNIX operating system. I have collected many UNIX command interview questions and already shared them but I found that except system admin jobs, many programming job interviews only focus on general UNIX commands e.g. chmod, find or grep and fundamentals like finding files and directories, managing file space, networking commands, checking process status and managing file permissions. In this article we will see such kind of frequently asked interview questions and answers from UNIX and Linux operating System. Questions are very fundamental in nature and not limited to Linux only and equally applicable to other UNIX operating systems e.g. Solaris, IBM AIX etc. Many of these UNIX questions are asked during various interviews on companies like TCS, Infosys, Citibank , Wipro, Capegemini and Tech Mahindra. But as I said they are very fundamental and can be asked in any company.

UNIX and Linux Interview questions answers

1) How to find all the links in a folder in UNIX or Linux ?
This is a tricky UNIX question as there is no specific command to find all symbolic links. Though you have ln command for creating and updating soft links but nothing which gives you all the links in a directory. You need to use ls command which list everything in directory and then you need to list all the links, as they starts with "l" as first characters, as shown in above article .

here is the actual UNIX command to find all links in a directory :

linux@nyj872:~ ls -lrt
total 2.0K
-rw-r--r--  1 Linux Domain Users  0 Dec   2011 a
drwxr-xr-x+ 1 Linux Domain Users  0 Sep 19 12:30 java/
lrwxrwxrwx  1 Linux Domain Users  4 Sep 19 12:31 version_1.0 -> java/

linux@nyj872:~ ls -lrt | grep '^l'
lrwxrwxrwx  1 Linux Domain Users  4 Sep 19 12:31 version_1.0 -> java/

2) How to find a process and kill that ?
Another classic UNIX interview questions. Answer of this question is simple if you are familiar with ps, grep and kill command. by using "ps -ef" you can get list of all process and then use grep to find your process and get the PID of that process. Once you got PID you can use kill command to kill that process as shown in this example of kill command in UNIX.


3) How to run a program in background in UNIX or Linux ?
an easy UNIX or Linux interview question, only when you know. You can use & to run any process in background and than you can use jobs to find the job id for that process and can use  fg and bg command to bring that process into foreground and background.

4) How to sort output of a command in reverse order in Linux or UNIX ?
One more Linux command interview question which checks knowledge of frequently used command. you can use sort command in UNIX to sort output of any command by using PIPE. By using -r option with sort command you can sort output of any command in reverse order. See these sort command examples for more details.

5) How to create archive file in UNIX or Linux Operating System ?
Another interview question based on knowledge of UNIX or Linux command. you can use tar command to great archives in UNIX or Linux. you can even combine tar and gzip to create a compressed archive in UNIX.

6) What is meaning of a file has 644 permission ?
To answer this UNIX or Linux interview question, you must know basics of files and directories in UNIX.  644 represents permission 110 for owner, permission 100 for group and 100 for others which means read + write for owner who create that file and read only permission for group and others. See this tutorial on UNIX file permission for more details.

7) How will you remove empty files or directories from /tmp ?
See how to delete empty directory and files in UNIX to answer this UNIX command interview questions.

8) I have read permission on a directory but I am not able to enter it why ?
One more tricky UNIX questions. In order to get into a directory you need execute permission. if your directory does not have execute permission than you can not go into that directory by using cd command. read UNIX files and directory permissions for more information.

9) How do you find all files which are modified 10 minutes before ?
This is another the Linux interview questions from frequently used command e.g. find and grep. you can use -mtime option of find command to list all the files which are modified 10 or m minutes before. see these find command examples for more details.

10) How to do you find size of directory in UNIX or Linux ?
This is another tricky and bit tough Linux interview question as popular ls command doesn't show complete size of directories in UNIX. you need to use du command to get full size of directories including all sub directories in UNIX. See How to find directory size in UNIX for exact command and detailed explanation.

These were some of the frequently asked UNIX and Linux command interview questions and answers which appear in many IT Job interview which requires knowledge of UNIX operating system, Including programming job interviews e.g. core Java and J2EE interviews. Questions from UNIX and Linux is also very popular during C and C++ programming interviews.


Read More »

keytool command examples Java - add view ssl certificate in keyStore trustStore

keytool command in Java is a tool for managing certificates intokeyStore and trustStore which is used to store certificate and requires during SSL handshake process. By using keytool command you can do many things but some of the most common operation is viewing certificate stored in keystore, importing new certificates into keyStore, delete any certificate from keystore etc. For those who are not familiar keyStore, trustStore and SSL Setup for Java application , Here is a brief overview on What is a trustStore and keyStore in Java. Both trustStore andkeyStrore is used to store certificate signed by signer authority or CA (Certificate authority), with keyStore additionally storing personal certificate for client which is used during client authentication on SSL handshake process if its enable. In this article we will see some basic example of keytool command in Java to find how many certificates we have in keyStore , viewing those certificates, adding new certificates and deleting old certificates from keyStore or trustStore in Java.


How to use keytool command in Java

Java keytool command example - add certificate list import keystore Following are some most common or frequently used example of keytool command which comes when you installed JDK. just type keytool command in your command prompt and it will show lot of command line option if your PATH is set correctly for Java. If Path is not set properly it will complain that not able to find keytool command. Don't worry you just need to add JAVA_HOME/bin directory in your path to get keytool command working.

keytool command to find how many certificates are in keyStore:
This is the first example of keytool command which will show you how many certificates are stored in trustStore or keyStore file :

test@nykdev32:/cygdrive/c/Program Files/Java/jdk1.6.0_26/jre/lib/security keytool -list -keystore jssecacerts
Enter keystore password:  changeit

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 81 entries

digicertassuredidrootca, 07/01/2008, trustedCertEntry,
Certificate fingerprint (MD5): 87:CE:0B:7B:2A:0E:49:00:E1:58:71:9B:37:A8:93:72
trustcenterclass2caii, 07/01/2008, trustedCertEntry,

above keytool command shows that default keystore jssecacerts, which comes along with JRE and present in JAVA_HOMEdirectory on path  JAVA_HOME/JRE/lib/security has 81 certificates in it and keyStore type is JKS which stands for Java Key Store. One of those certificates are from digicert

Now if you want to see details of certificates e.g. Common name (CN) and other attribute you can use following keytool command to view details of certificates stored in keyStore in Java :

keytool command to view certificate details from keyStore :

test@nykdev32:/cygdrive/c/Program Files/Java/jdk1.6.0_26/jre/lib/security keytool -list -v -keystore jssecacerts
Enter keystore password:  changeit

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 81 entries

Alias name: digicertassuredidrootca
Creation date: 07/01/2008
Entry type: trustedCertEntry

Owner: CN=DigiCert Assured ID Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Issuer: CN=DigiCert Assured ID Root CA, OU=www.digicert.com, O=DigiCert Inc, C=US
Serial number: ce7e0e517d846fe8fe560fc1bf03039
Valid from: Thu Nov 09 20:00:00 VET 2006 until: Sun Nov 09 19:30:00 VET 2031
Certificate fingerprints:
         MD5:  87:CE:0B:7B:2A:0E:49:00:E1:58:71:9B:37:A8:93:72
         SHA1: 05:63:B8:63:0D:62:D7:5A:BB:C8:AB:1E:4B:DF:B5:A8:99:B2:4D:43
         Signature algorithm name: SHA1withRSA
         Version: 3

Now if you want to import any certificate into this keystore you can use following keytool command :

keytool command for adding certificate in keystore and trustStore :

keytool -import -alias adding_certificate_keystore  -file self.cer -keystore jssecacerts

this will print certificate details and prompt you to accept the certificate, once you confirm that by typing Yes, certificate will be added into your keyStore. For verification purpose you can re run previous keytool command to get total number of certificate in keystore. For example if we run following keytool command , it should print 82 certificates in keyStore :

test@nykdev32:/cygdrive/c/Program Files/Java/jdk1.6.0_26/jre/lib/security keytool -list -keystore jssecacerts
Enter keystore password:  changeit

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 82 entries

Another useful keytool command option is -printcert which prints details of a certificate stored in .cer file :

~/ keytool -printcert -file test.cer

That's all on some basic keytool command example for viewing and adding certificates into keystore and trustStore in Java. I still prefer a GUI tool for creating keystore and managing certificates but keytool is good alternative because its comes along with JDK installation and available in most places.

Java Tutorials from java67 blog


Read More »

Top 10 Java Web Service Interview question answers

Java Web Services Questions and Answers 
Web Services interview questions are part of J2EE interviews for jobs which are looking some experience in Java web services Space. Most of the Web services questions come from two different way of implementing Web Services e.g. SOAP and REST. SOAP is an standard and mature way of calling Web Services which uses XML while REST is a new way of implementing Web Services which is based on HTTP protocol. In fact REST Web Service interview questions are getting more and more popular on web services interviews in Java, So if you are going for any Java J2EE interview which require some web service experience, be prepare with both SOAP and REST Web services questions. Following is list of Java web services interview questions which I have prepared for practice. Answers of these web services questions can be easily found in many places on Internet and I will update this list whenever I have new web services interview question. If you guys find any interesting tricky or tough Java web service question asked in Interviews then please share with us :

Frequently asked Java webservice interview questions

Java Web Service Interview Question and Answers SOAP RESTHere is my list of frequently asked interview question on Java web service in any Core Java Interview. As SOAP is an standard way of making web service call which uses XML, good knowledge of XML and Java is expected from you and Interviewer may ask some XML interview questions as well.

What is Web Service ?
What is SOAP ?
What is REST Web Service ?
What is difference between REST Web Service and SOAP web service ?
Can a Java client can talk to C++ Server using Web Service ?
What is WSDL?
What is UDDI?
Does Web Service call is synchronous or asynchronous ?
How do you handle errors in Web Service call ?
What is JAX-RPC ?
Have you worked on Spring and Web-services ?
What is WebServiceTemplate etc
What is difference between RMI and Web Services

This list is not complete and I have started collecting more and  more web services questions as part of my preparation. Will be updating this list whenever I have good web services questions from Java interviews.

Java Interview Questions from Java Blog
Read More »

How to Convert Byte array to String in Java with Example

There are multiple ways to convert a byte array to String in Java but most straight forward way is to use the String constructor which accepts a byte array i.e. new String(byte []) , but key thing to remember is character encoding. Since bytes are binary data but String is character data, its very important to know the original character encoding of the text from which byte array has created. If you use a different character encoding, you will not get the original String back. For example, if you have read that byte array from a file which was encoded in "ISO-8859-1" and you have not provided any character encoding while converting byte array to String using new String() constructor then its not guaranteed that you will get the same text back? Why? because new String() by default uses platform's default encoding (e.g. Linux machine where your JVM is running), which could be different than "ISO-8859-1". If its different you may see some garbage characters or even different characters changing the meaning of text completely and I am not saying this by reading few books, but I have faced this issue in one of my project where we are reading data from database which contains some french characters. In the absent of any specified coding, our platform was defaulted on something which is not able to convert all those special character properly, I don't remember exact encoding. That issue was solved by providing "UTF-8" as character encoding while converting byte array to String. Yes, there is another overloaded constructor in String class which accepts character encoding i.e. new String(byte[], "character encoding").

BTW, if you are new in the world of character encoding and don't understand what is UTF-8 or UTF-16, I recommend you to read my article
 difference between UTF-8, UTF-16 and UTF-32 encoding. That will not only explain difference but also give you some basic idea about character encoding. Another article, I recommend you to read is about how Java deals with default character encoding. Since many classes which performs conversion between bytes and character cache character encoding, its important to learn how to provided proper encoding at JVM level. If this interests you then here is the link to full article.





How to convert byte array to String in Java
Everything is 0 and 1 in computers world, yet we are able to see different things e.g. text, images, music files etc. The key to convert byte array to String is character encoding. In simple word, byte values are numeric values and character encoding is map which provide a character for a particular byte for example in most of character encoding scheme e.g. UTF-8, if value of byte is 65, character is A, for 66 it's B. Since ASCII character which includes, numbers, alphabets and some special characters are very popular they have same value in most of encoding scheme. But that's not true for every byte value for example -10 can be different in UTF-8 and Windows-1252 encoding scheme. Now some one can question that, since byte has 8 bits, it can only represent maximum 255 characters, which is quite less given so many languages in the world. That's why we have multi byte character encoding schemes, which can represent a lot many characters. Why we need to convert bytes to String? one real world example is to display base 64 encoded data as text. In order to do that you need to convert byte array to hex String as shown in that tutorial.




Java Byte Array to String Example
Byte array to String in Java with Example
 Now we know little bit of theory about how to convert byte array to String, let's see a working example. In order to make the example simple, I have created a byte array on the program itself and then converted that byte array into String using different character encoding e.g. cp1252, which is default character encoding in Eclipse, windows1252 another popular encoding in Windows and UTF-8, which is a default standard character encoding in world. If you run this program and look at the output you will notice that most of the characters are same in all three encoding, they are mostly ASCII characters containing alphabets in both upper and lower case and numbers, but special characters are rendered differently. This is where using incorrect character encoding can create trouble. Rest of the example is pretty straight forward as we already have a byte array and we are just using overloaded String constructor which also accepts encoding. For a more complex example, where we read content from an XML file, see this tutorial. There are also printable and non-printable characters in ASCII, which is handled differently by different character encoding.


import java.io.UnsupportedEncodingException;

public class ByteArrayToStringDemo {

    public static void main(String args[]) throws UnsupportedEncodingException {
      
        byte[] random = new byte[] { 67, 65, 70, 69, 66, 65, 66, 69, -20};
      
        String utf = new String(random, "UTF-8");
        String cp1252 = new String(random, "Cp1252");
        String windows1252 = new String(random, "Windows-1252");
    
        System.out.println("String created from byte array in UTF-8 encoding : " + utf);
        System.out.println("byte array to String in Cp1252 encoding : " + cp1252);
        System.out.println("byte array to String in Windows-1252 encoding : " + windows1252);

    }

}

Output :
String created from byte array in UTF-8 encoding : CAFEBABE?
byte array to String in Cp1252 encoding : CAFEBABEì
byte array to String in Windows-1252 encoding : CAFEBABEì


That's all about
 how to convert byte array to String in Java. Always provide character encoding while converting bytes to character and that should be the same encoding which is used in original text. If you don't know then UTF-8 is good default but don't rely on platform's default character encoding because that is subject to change and might not be UTF-8. Better option is to set character encoding for your application at JVM level to have complete control on how byte array gets converted to String.
Read More »