Tuesday, 21 June 2016

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 »

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 »

Java ArrayList Examples For Programmers

ArrayList Example in Java
In this Java ArrayList Example we will see how to add elements in ArrayList, how to remove elements from ArrayList, ArrayList contains Example and several other ArrayList functions which we use daily. ArrayList is one of the most popular class from Java Collection framework along with HashSet and HashMap and a good understanding of ArrayList class and methods is imperative for Java developers. ArrayList is an implementation ofList Collection which is ordered and allow duplicates. ArrayList is alos index based and provides constant time performance for common methods e.g. get().Apart from very popular among Java programmers, ArrayList is also a very popular interview topic. Questions like Difference between Vector and ArrayList and LinkedList vs ArrayList is hugely popular on various Java interview specially with 2 to 3 years of experience. Along with Vector this is one of the first collection class many Java programmer use. By the way e have already seen some ArrayList tutorial e.g. ArrayList sorting example,  converting Array to ArrayList looping through ArrayList which is good to understand ArrayList in Java.

Java ArrayList Examples
Java ArrayList Example contains empty size removeIn this section we will see actual code example of various ArrayList functionality e.g. add, remove, contains,clear, size, isEmpty etc.


  
import java.util.ArrayList;
import java.util.Arrays;

/**
 *
 * Java ArrayList Examples - list of frequently used examples in ArrayList e.g. adding 
 * elements, removing elements, contains examples etc
 * @author
 */

public class ArrayListTest {

    public static void main(String args[]) {
      
        //How to create ArrayList in Java - example
        ArrayList<String> list = new ArrayList<String>();
      
        //Java ArrayList add Examples
        list.add("Apple");
        list.add("Google");
        list.add("Samsung");
        list.add("Microsoft");
    
        //Java ArrayList contains Example, equals method is used to check if
        //ArrayList contains an object or not
        System.out.println("Does list contains Apple :" + list.contains("Apple"));
        System.out.println("Does list contains Verizon :" + list.contains("Verizon"));
      
        //Java ArrayList Example - size
        System.out.println("Size of ArrayList is : " + list.size());
      
        //Java ArrayList Example - replacing an object
        System.out.println("list before updating : " + list);
        list.set(3, "Bank of America");
        System.out.println("list after update : " + list);
      
        //Java ArrayList Example - checking if ArrayList is empty
        System.out.println("Does this ArrayList is empty : " + list.isEmpty());
      
        //Java ArrayList Example - removing an Object from ArrayList
        System.out.println("ArrayList before removing element : " + list);
        list.remove(3); //removing fourth object in ArrayList
        System.out.println("ArrayList after removing element : " + list);
      
       //Java ArrayList Example - finding index of Object in List
        System.out.println("What is index of Apple in this list : " + list.indexOf("Apple"));
      
        //Java ArrayList Example - converting List to Array
        String[] array = list.toArray(new String[]{});
        System.out.println("Array from ArrayList : " + Arrays.toString(array));
      
        //Java ArrayList Example : removing all elements from ArrayList
        list.clear();
        System.out.println("Size of ArrayList after clear : " + list.size());
    } 
  
}

Output:
Does list contains Apple :true
Does list contains Verizon :false
Size of ArrayList is : 4
list before updating : [Apple, Google, Samsung, Microsoft]
list after update : [Apple, Google, Samsung, Bank of America]
Does this ArrayList is empty : false
ArrayList before removing element : [Apple, Google, Samsung, Bank of America]
ArrayList after removing element : [Apple, Google, Samsung]
What is index of Apple in this list : 0
Array from ArrayList : [Apple, Google, Samsung]
Size of ArrayList after clear : 0

These were some frequently used examples of ArrayList in Java. We have seen ArrayList contains example which used equals method to check if an Object is present in ArrayList or not. We have also see how to add, remove and modify contents of ArrayList etc.

Other Java Collection tutorial and Interview Questions



Read More »

Java Enum Example with Constructor

Java Enum with Constructor
Java Enum can have Constructor to pass data while creating Enum constants. One example of passing arguments to enum Constructor is our TrafficLight Enum where we pass action to each Enum instance e.g. GREEN is associate with go, RED is associate with stop and ORANGE is associated with slow down. You can also provide one or more constructor to your Enum as it also support constructor overloading. Just note that modifierpublic and protected are not allowed to Enum constructor, it will result in compile time error. By the way We have covered see some enum examples in our previous posts e.g. Java Enum Switch Example, Java Enum valueOf Example and Enum to String Exmaple in Java, which is good to learn enum in Java.


Java Enum with Constructor Example
Java Enum with constructor example tutorialhere is complete code example of using Constructor with Java Enum. Here our TrafficLight constructor accept an String argument which is saved to action field which is later accessed by getter method getAction().

/**
 * Java enum with constructor for example.
 * Constructor accept one String argument action
 */

public enum TrafficSignal{
    //this will call enum constructor with one String argument
    RED("wait"), GREEN("go"), ORANGE("slow down");
  
    private String action;
  
    public String getAction(){
        return this.action;
    }
  
    // enum constructor - can not be public or protected
    TrafficSignal(String action){
        this.action = action;
    }
}

/**
 *
 * Java Enum example with constructor. Java Enum can have constructor but can not
 * be public or protected
 *
 * @author http://java67.blogspot.com
 */

public class EnumConstructorExample{

    public static void main(String args[]) {
      
      //let's print name of each enum and there action - Enum values() examples
      TrafficSignal[] signals = TrafficSignal.values();
    
      for(TrafficSignal signal : signals){
          //Java name example - Java getter method example
          System.out.println("name : " + signal.name() + " action: " + signal.getAction());
      } 
    
    } 
  
}
This was our Java Enum example with Constructor. Now you know that Enum can  have constructor in Java which can be used to pass data to Enum constants, just like we passed action here. Though Enum constructor can not be protected or public, it can either have private or default modifier only.

Other Java 5 tutorial you may like

Java 5 new features list



TAGS :     JAVA          JAVA TUTORIAL           JAVA STUDY ONLINE
Read More »

What is difference between View and Materialized View in Database or SQL?

Difference between View and Materialized view is one of the popular SQL interview question, much like truncate vs deletecorrelated vs noncorrelated subquery or primary key vs unique key This is one of the classic question which keeps appearing in SQL interview now and then and you simply can’t afford not to learn about them. Doesn’t matter if you are a programmer, developer or DBA, this SQL questions is common to all. Views are concept which not every programmer familiar of, it simply not in the category of CRUD operation or database transactions or SELECT query, its little advanced concept for average programmer. Views allows a level of separation than original table in terms of access rights but it always fetch updated data. Let’s see What is View in database, What is materialized View and difference between view and materialized view in database.

What is View in database
What is difference between View vs Materialized View in database or SQL?Views are logical virtual table created by “select query” but the result is not stored anywhere in the disk and every time we need to fire the query when we need data, so always we get updated or latest data from original tables. Performance of the view depend upon our select query. If we want to improve the performance of view we should avoid to use join statement in our query or if we need multiple joins between table always try to use index based column for joining as we know index based columns are faster than non index based column. View allow to store definition of the query in the database itself.

What is Materialized View in database
Materialized views are also logical view of our data driven by select query but the result of the query will get stored in the table or disk, also definition of the query will also store in the database .When we see the performance of Materialized view it is better than normal View because the data of materialized view will stored in table and table may be indexed so faster for joining also joining is done at the time of materialized views refresh time so no need to every time fire join statement as in case of view.

Difference between View vs Materialized View in database
Based upon on our understanding of View and Materialized View, Let’s see, some short difference between them :

1) First difference between View and materialized view is that, In Views query result is not stored in the disk or database but Materialized view allow to store query result in disk or table.

2) Another difference between View vs materialized view is that, when we create view using any table,  rowid of view is same as original table but in case of Materialized view rowid is different.

3) One more difference between View and materialized view in database is that, In case of View we always get latest data but in case of Materialized view we need to refresh the view for getting latest data.

4) Performance of View is less than Materialized view.

5) This is continuation of first difference between View and Materialized View, In case of view its only the logical view of table no separate copy of table but in case of Materialized view we get physically separate copy of table

6) Last difference between View vs Materialized View is that, In case of Materialized view we need extra trigger or some automatic method so that we can keep MV refreshed, this is not required for views in database.

When to Use View vs Materialized View in SQL
Mostly in application we use views because they are more feasible,  only logical representation of table data no extra space needed. We easily get replica of data and we can perform our operation on that data without affecting actual table data but when we see performance which is crucial for large application they use materialized view where Query Response time matters so Materialized views are used mostly with data ware housing or business intelligence application.

That’s all on difference between View and materialized View in database or SQL. I suggest always prepare this question in good detail and if you can get some hands on practice like creating Views, getting data from Views then try that as well.

Other SQL Interview Question articles for you


TAGS :     SQL          SQL TUTORIAL           SQL STUDY ONLINE
Read More »