Senin, 31 Maret 2014

Top 10 Google Interview Questions Answers for Software Engineer - Books, Resources




These Google interview questions are some of my favorites collected from different sources. Every Programmer know that Google is one of the best technology company and its dream for many software developer to work for google, but at same time interview process at google is very tough and only few genuine intelligent programmers get through there interview process. Google interview questions are always been a good topic of discussion when few young software developer gathered around, I can still remember when one of my friend got call from google for interview then how whole bunch was got excited. We have searched a lot on internet on google interview questions and answers for him and us and then make a note of some of the best questions for preparation. I am listing down some google interview questions from that list. Apart from the popular questions asked in various Google Interview for software engineers or developers, books on algorithm and data structure plays a lot more important roles. Books like Algorithms for Interviews and Introduction to Algorithms are must read for any Programmer, who is serious about converting Google interview or similar companies like Facebook, Amazon and Microsoft. Once you start preparing for Google, rest of them become very easy.




Answers of these Google interview questions can be found  by doing google :) , Also each question in itself demand a blog post and I will try to cover those one by one as and when time allows. I have divided all interview questions on different category like data structure, puzzles, operating system , Software Design and Coding etc for better organization.  In the last section, I have shared some top class, must read books for Google Interview preparation. It contains books like Are You Smart Enough to Work at Google?, which is not only a good read but tells you a lot about Google interview, it's process. Before starting preparation, a must read to get yourself motivated.





Google Interview questions answers for Software Engineers




Google interview questions based on data structure




top google interview questions and answers for software engineer

Here are few questions from data structures appeared on various google interviews, data-structure is a complex topic and can get very complex at google and we have purposefully not collected very tough data-structure questions at that time because of time limit and we wanted to gain some confidence to solve moderate questions, though this may not be a good strategy for many people but it depends how much knowledge you have and how confident you are on data-structure.





1) find out the fastest way to locate the largest element in a circular sorted array ?


2) You have a binary search tree and integer n, find out the most efficient way to locate two nodes of the


three whose summation is equals to "n" ?


3) How do you convert a max heap to min heap ?


4) You have two list L1 and L2 write an algorithm to see if both the lists are equivalent or not?


5) How do you figure out time and space complexity of recursive function ?


6) how will you implement three stacks with one array.



See here for few more questions on data structure and algorithms





Google interview questions based on operating system



Here are some of my favorite Google interview questions from various operating systems like Unix and Linux. Good knowledge of how operating system works always helps to excel any programming interview and Google is not an exception.





1) If you have given a chance to rewrite linux, how will you do that ?


2) Explain how congestion control works in the TCP protocol ?


3) How would you optimize TCP Protocol without going on UDP ways ?








Google interview questions on Software design



Here are some of software design questions from various Google interviews for software engineer position. Software design is critical piece to get though Google interview and people has almost always faced one of two questions from this category.





1) You have provided a set of points across globe as latitudes and longitudes ? How will you determine


points which are within a particular mile ?


2) Can you design data package transfer form London to Tokyo ?


3) Design a distributed system for storing a static set of (key, value) pairs which will behave like


a hashtable , user will provide you key and system will return value.


4) Design Algorithm for Lift to get minimum waiting time on each floor ?



For more questions on Object oriented design and software design see here


 



Google interview questions on Coding



There will always be some questions on coding in Google interview, especially if it is for software engineer or developer role. They want to see you writing code. There is no language barrier and you can choose whatever programming language you are most comfortable with.Google interview questions on coding mostly requires good knowledge of recursion, data structure and good familiarity of programming language.





1)Can you write code in Java or C++ to find the power set of a given set.


for example if S={a,b} the power set is P={{},{a},{b},{a,b}} ( you can also choose any of your favorite programming language)


2) Write code in Java to find out whether a binary tree is a mirror image of itself or not. Code should be thread-safe?


3) Can you write code to implement your own hashtable in C++ or Java?


4) Write code to find out number of occurrence of a number in a sorted array ?


5) Can you implement a Generic LRU Cache in Java ?


6) write a program to solve a Rubik's cube in any programming language.




For more coding questions, you can  also see my list of Top 30 programming interview questions.





Miscellaneous Google interview questions



In this category of google interview question you will see mostly behavioral questions, some time before throwing data-structure questions they ask light question and some time after exhaustive screening they ask based on your profile and luck. Apart from below they also questions based on puzzles and riddles.





1) How Google Search work ? If asked to you how will you design it to scale and fast at same time ?


2) Why do you want to work with Google ?


3) Which Google product you like most and why ?


4) Do you like coding or designing application ?


5) Questions about your previous project and work experience.





Puzzles are another popular topic on various google interview and there are lot of puzzles available in internet as well make sure you prepare on puzzles before appearing to any google interview. Some time they even ask questions on lateral thinking and tricks which doesn't require complex logic but sharp mind to guess. See this list of the most popular puzzles asked in programming interviews.






Books to Prepare Google Interview Questions


There are lot of books available in market, which covers lot of different topics asked in Google or Amazon interviews, but most of them lack quality. In order to succeed in Google, most important thing is data structure and algorithm topic along with problem solving skills, if you have that, half of battle is won. Following are some of the popular books, which programmers prefer during preparation of Google interviews:



1. Algorithms For Interviews By Adnan Aziz and Amit Prakash

This book is especially written for Google interviews. Authors has put decent effort to not only show how to use algorithm but also focus on problem solving skill. A must read for any Google aspirants.



2. Are You Smart Enough to Work at Google?  By William Poundstone

Google is known for asking insanely difficult puzzles, this books takes you on both. It's readable, fun and same time introduce hard realities of Google interviews. You will be glued to read this book, after reading the first interview experience :) 



3. Introduction to Algorithms (Includes CD-Rom) By Thomas Cormen, Charles Leiserson, Ronald Rivest, Clifford Stein

Another top class book on topic of Algorithm. As I said, data structure and algorithms are extremely important to survive and excel google interviews. Read this book at least one time, if not two. Another must read for Google aspirants.



4. Top 10 coding interview problems asked in Google with solutions: Algorithmic Approach

One more great book to prepare for Google interviews. This book present 10 top quality code questions asked on Google, with full solution including pseudo code and C++. This book fills lot of gap on how to solve coding questions on Google, something freshers and software engineers lacks.





That's all on Google interview questions .What is most important is that most of the questions asked in google is original and you don't see them again. practice can give you guidance on how to tackle those questions.
























Source:http://javarevisited.blogspot.com/2012/01/google-interview-questions-answers-top.html

Listing existing Maximo/TPAE customizations

During my job assignments it often happens that I'm sent to a customer that already has Maximo in production with some customizations in place. One of the problems in such cases is to quickly get an overall picture of how many customizations have been made and what have been customized.
One approach that I have found useful is to 'diff' the existing environment with a clean one exporting Maximo definitions into text files. The only problem with this approach is that requires a clean installation of the product. If you don't have a clean system to compare you can use a simpler approach.

I have developed a set of database select statements whose output can be put into one or more text files. I export the results of such queries on both production and reference system. Then I use a diff tool to compare the outputs.
Note that this approach can be useful also to detect differences between dev-test-production systems.

Database

The following queries list the objects and attributes defined on the Maximo database. The number, location and type of changes give a very quick idea of the amount of customizations in place. For example many changes on classname fields point out heavy Java customizations.

select
servicename, objectname, classname, description,
persistent, entityname, extendsobject, siteorgtype, userdefined, mainobject, internal, eauditenabled, eauditfilter, esigfilter
from maxobject
order by servicename, objectname;

select
objectname, attributeno, attributename,
alias, autokeyname, canautonum, classname, columnname,
complexexpression, defaultvalue, domainid, entityname,
handlecolumnname, isldowner, ispositive, length, localizable,
maxtype, mlinuse, mlsupported, mustbe, persistent,
primarykeycolseq, remarks, required, restricted,
sameasattribute, sameasobject, scale, searchtype,
textdirection, title, userdefined, eauditenabled, esigenabled
from maxattribute
order by objectname, attributeno, attributename;

Applications

Applications are stored in the MAXAPPS table.

select app, apptype, custapptype, description,
maintbname, orderby, originalapp, reportobject, restrictions
from maxapps
order by app;

The problem with this approach is that it does not point out changes in the application definitions. Those changes are stored in MAXPRESENTATION table. However, the applications definitions are stored in XML format into CLOB field so it is hard to export all such fields in a single text file. An approach is to calculate a hash value of such field in order to be able to quickly detect changes. Starting from Oracle 10g a function called ora_hash has been introduced. Here follows the 'enhanced' query.

select
m.app, m.apptype, m.custapptype, m.description,
m.maintbname, m.orderby, m.originalapp, m.reportobject, m.restrictions,
ora_hash(mp.presentation)
from maxapps m
join maxpresentation mp on mp.app=m.app
order by m.app;

Another (maybe simpler) approach could be to export the entire list of applications definition. This can be achieved opening the Application Designer application, listing all the applications (simply press enter) and clicking on 'Export application definitions' button on the toolbar.

Reports

Reports are stored in the REPORT table.

select
reportfolder, appname, basetablename, reportname, runtype,
description, scheduleonly, norequestpage, detail,
toolbarlocation, toolbaricon, toolbarsequence, destinationfolder
from report
order by reportfolder, appname, reportname;

Reports are stored in the REPORTDESIGN table. Here we have the same problem found for Maximo application so we need to use the 'hashing' solution.

select
r.reportfolder, r.appname, r.basetablename, r.reportname, r.runtype, r.description,
r.scheduleonly, r.norequestpage, r.detail, r.toolbarlocation,
r.toolbaricon, r.toolbarsequence, r.destinationfolder,
ora_hash(rd.design)
from report r
join reportdesign rd on rd.reportname=r.reportname;
order by reportfolder, appname, reportname;

Menus

System and application menus including search definitions are stored in the MAXMENU table.

select 
menutype, moduleapp, position, subposition, visible, elementtype,
keyvalue, headerdescription, image, tabdisplay, accesskey, url
from maxmenu
order by menutype, moduleapp, position, subposition;

Final considerations

The described approach has several limitations including the not comprehensive coverage of all the possible customizations that are available within TPAE. Another limitation is the hashing solution that is only described for Oracle databases. Please send me any updates and comments that can improve the quality or coverage of this solution.

Source:http://maximodev.blogspot.com/2012/01/listing-existing-maximotpae.html

How to find if JVM is 32 or 64 bit from Java program.



You can find JVM bit size e.g. 32 bit or 64 bit by using either running java command from command prompt or by using System.getProperty() from Java program. Question is why do you want to know hardware or platform configuration while writing Java code which is supposed to write once and read anywhere(32 bit, 64 bit etc)? Yes we don't really need to know whether JVM is 32 bit or 64 bit more often but there are many situation when this matters







Check if JVM is 32 or 64 bit from Java program:

1)Since in 32 bit JVM maximum heap size in Java can not be more than 4GB (theoretically) , if you can get JVM version from script like running java command you can have different memory configuration for your application. Also if there is any specific JVM options which only applicable to 64 bit JVM than you can set those.




2)If your Java application is using native libraries than you certainly want to know whether Java running on host is 32 bit or 64 bit because native library may have different versions loaded for 32 bit or 64 bit architectures.





I am sure there could me some more practical reasons when you like to find JVM bit size or whether JVM is 64 bit or not





Now let's come to second part how to find if JVM is 32 bit or 64 bit in Java.





How to check if JVM is 32 or 64 bit in host



check if JVM is 32 bit or 64 bit in JavaAs I said earlier there are two different approaches either using Java system property like "sun.arch.data.model" or "os.arch" or by running java command from script and checking its output for certain characters to identify whether JVM is 64 bit or not. let's see example of different ways to find if JVM is 32 bit or 64 bit:





1) By using System property sun.arch.data.model:


You can find whether your JVM is 32 bit or 64 bit by calling System.getProperty("sun.arch.data.model") at least on Sun's hotspot JVM. I don't expect this to be run on any other Vendor specific JVM but since most of the programmer or project uses Sun's hotspot JVM. this is an handy option. for 32 bit JVM "sun.arch.data.model" will be 32 and for 64 bit JVM this would be 64. here is an example:





System.out.println("JVM Bit size: " + System.getProperty("sun.arch.data.model"));





Output:


JVM Bit size: 32 //JVM is 32 bit


JVM Bit size: amd64 //JVM is 64 bit





2)By using System.getProperty("os.arch")


"os.arch" is another System property which you can use to find whether installed JRE or JVM is 32 bit or 64 bit. by name it sounds that it will return operating system arch but you can still give it a try. Though I haven't tested on all different JVM, I have read that it can indeed return JVM Bitness.If you try this on 64 bit machine and 32 bit JVM combination than please let us know what does it return. here is what it returns in case of 32 bit JVM:





System.out.println("JVM Bit size: " + System.getProperty("os.arch"));





JVM Bit size: x86 //on 32 bit JVM


JVM Bit size: amd64 //on 64 bit JVM





3)java -d64 -version


This is another way of finding whether installed JRE or JVM is 64 bit or not but unfortunately it


doesn't work in all windows version like Windows XP but it works fine on Windows 7. So you still


use it on Windows7 Machine for finding JVM bitness.





4)java -version


Plain old java -version reveals information about JVM bitness only if installed JRE is 64 bit, in case


of 32 bit JVM it doesn't provide any information related to architecture but in case of 64 bit JVM it


prints :


C:\>java -version


java version "1.6.0_25"


Java(TM) SE Runtime Environment (build 1.6.0_25-b06)


Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode)





while in case of 32 bit JVM it will print


C:\> java -version


java version "1.6.0_26"


Java(TM) SE Runtime Environment (build 1.6.0_26-b03)


Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)








That’s all on how to find if JVM is 32 bit or 64 bit from Java program and command prompt. As I said its particularly useful if you have dependency on native libraries which has different build for 32 bit or 64 bit architecture. Let me know if you have some more ways to find JVM is 64 bit or not, you can also share on which scenario you need to know JVM bitness.





Some Java posts you may like






























Source:http://javarevisited.blogspot.com/2012/01/find-jvm-is-32-or-64-bit-java-program.html

What is Constructor overloading in Java with Example




Constructor overloading in java allows to have more than one constructor inside one Class. in last article we have discussed about method overloading and overriding and constructor overloading is not much different than method overloading. Just like in case of method overloading you have multiple methods with same name but different signature, in Constructor overloading you have multiple constructor with different signature with only difference that Constructor doesn't have return type in Java. Those constructor will be called as overloaded constructor . Overloading is also another form of polymorphism in Java which allows to have multiple constructor with different name in one Class in java.






Why do you overload Constructor in Java ?



Constructor overloading in java with ExampleWhen we talk about Constructor overloading, first question comes in mind is why do some one overload Constructors in Java or why do we have overloaded constructor ? If you have been using framework or API like JDK or Spring you must have seen lot of method overloading and constructor overloading. Constructor overloading make sense if you can Construct object via different way. One of Classical example of Constructor overloading is ArrayList in Java. ArrayList has three constructors one is empty, other takes a collection object and one take initial Capacity. these overloaded constructor allows flexibility while create arraylist object. It may be possible that you don't know size of arraylist during creation than you can simply use default no argument constructor but if you know size then its best to use overloaded Constructor which takes capacity. Since ArrayList can also be created from another Collection, may be from another List than having another overloaded constructor makes lot of sense. By using overloaded constructor you can converty your ArrayList into Set or any other collection.





Constructor overloading in Java Example




How to overload Constructor in Java



Constructor overloading is not complex you just need to create another constructor, obviously same name as of class but different signature but there are certain rules related to Constructor overloading which needs to be remembered while overloading constructor in Java. e.g. One Constructor can only be called from inside of another Constructor and if called it must be first statement of that Constructor. here is an example of correct and incorrect constructor overloading:






public loan(){


  this("");  //correct


}





public loan(){


  System.out.println("Calling overloaded Constructor in Java");


  this("");  //incorrect - throw compilation error.


}





public loan(String type){


  this.loanType= type;


}






Also once you provide constructor on Class in Java , Compiler will not insert or add default no argument constructor , so make sure you add a default constructor on your class. Other rules of method overloading


also applies on Constructor overloading in Java e.g. Number or type of arguments of constructor should be different. Just changing access modifier of Constructor will not result in overloading instead it will throw compilation error as shown in below example:






public loan(String type){


  this.loanType= type;


}





//compilation error - only access modifier is changed


private loan(String type){


  this.loanType= type;


}






Important points related to Constructor overloading:



1. Constructor overloading is similar to method overloading in Java.





2. You can call overloaded constructor by using this() keyword in Java.





3. overloaded constructor must be called from another constructor only.





4. make sure you add no argument default constructor because once compiler will not add if you have added any constructor in Java.





5. if an overloaded constructor called , it must be first statement of constructor in java.





6. Its best practice to have one primary constructor and let overloaded constructor calls that. this way


your initialization code will be centralized and easier to test and maintain.








That’s all on Constructor overloading in java. Biggest advantage of Constructor overloading is flexibility which allows you to create object in different way and classic examples are various Collection classes. Though you should remember that once you add a constructor, compiler will not add default no argument constructor.





Thanks





Java post you may like































Source:http://javarevisited.blogspot.com/2012/01/what-is-constructor-overloading-in-java.html

Minggu, 30 Maret 2014

Difference between Serializable and Externalizable in Java Serialization




Difference between serializable and externalizable is popular java interview question which we have touched on my earlier post on Serialization: Top 10 java serialization interview questions. knowing differences between externalizable and serializable is not just important from interview point of view but also getting control of serialization process and optimizing performance of serialization. both serializable and extenalizable used to serialize or persist java objects but the way they do is little different. In case of Serializable Java Virtual machine has full control for serializing object while in case of Externalizable, application gets control for persisting objects. writeExternal() and readExternal() method provides complete control on format and content of Serialization process to application which can be leverage to increase performance and speed of serialization process.







Serialization and Externalization in Java




Serializable vs Externalization in Java



difference between Java Serialization vs Externalization in Javahere are some more differences between Serializable and Externalizable interface in Java:





1. In case of Serializable, default serialization process is used. while in case of Externalizable custom Serialization process is used which is implemented by application.





2. JVM gives call back to readExternel() and writeExternal() of java.io.Externalizalbe interface for restoring and writing objects into persistence.





3. Externalizable interface provides complete control of serialization process to application.





4. readExternal() and writeExternal() supersede any specific implementation of writeObject and readObject methods.





Though Externalizable provides complete control, it also presents challenges to serialize super type state and take care of default values in case of transient variable and static variables in Java. If used correctly Externalizable interface can improve performance of serialization process.








That’s all on Difference between Externalizable and Serializable interface in Java. This is always asked when Java interview take turn towards Serialization after Multi-Threading questions and Collections Interview questions. Only problem with Serialization is that not many programmer use it and that’s why it look little difficult otherwise once you familiar with Serialization process and rules of Serialization, interview questions can be more easily handled.








Some Interview Questions post:































Source:http://javarevisited.blogspot.com/2012/01/serializable-externalizable-in-java.html

Difference between URL-rewriting URL-encoding in Servlet JSP




URL-rewriting vs URL-encoding in Servlet JSP



Main difference between URL-rewriting and URL-encoding is that URL-rewriting is a technique to maintain user session if cookies are not enabled on client browser or browser doesn't support cookie while URL-encoding is a way to pass string to server containing special characters  by converting special characters like space into some other characters like + . people often confuse between URL encoding and URL rewriting because of there names which sounds quite similar for new guys but functionality wise they are totally different to each other, Also servlet encodeURL() method adds more confusion because its sounds like its used for URL Encoding but indeed used for URL Rewriting. This is also a very popular servlet and JSP interview questions , I have also shared some more questions on my posts 10 Servlet Interview questions answers and 10 JSP interview questions and answers for Java programmer.









Difference between URL Rewriting and URL Encoding in JSP Servlet



difference between URL-Rewriting and URL-Encoding in Java ServletYou often need to encode URL before sending it to server and need to rewrite URL with session id in order to maintain session where cookie is not present. here are some more differences between URL-rewriting and URL encoding in Servlet JSP





1) java.servlet.http.HttpServletResponse methods encodeURL(String url) and encodeRedirectURL(String URL) is used to encode SesssionID on URL to support URL-rewriting. don't confuse with name encodeURL() because it doesn't do URL encoding instead it embeds sessionID in url if necessary. logic to include sessionID is in method itself and it doesn't embed sessionID if browser supports cookies or session maintenance is not required. In order to implement a robust session tracking all URL from Servlet and JSP should have session id embedded on it.





In order to implement URL-rewriting in JSP you can use use JSTL core tag all URL passed to it will automatically be URL-rewriting if browser doesn't support cookies.





While java.net.URLEncoder.encode() and java.net.URLDecoder.decode()is used to perform URL Encoding and decoding which replace special character from String to another character. This method uses default encoding of system and also deprecated instead of this you can use java.net.URLEncoder.encode(String URL, String encoding) which allows you to specify encoding. as per W3C UTF-8 encoding should be used to encode URL in web application.





2) In URL rewriting session id is appended to URL and in case of URL-encoding special character replaced by another character.





That's all on difference between URL-rewriting and URL-encoding, let me know if you come across some more differences between these URL Encoding vs URL-rewriting in Servlet and JSP.





Some more Java post you may like



































Source:http://javarevisited.blogspot.com/2012/01/url-rewriting-url-encoding-in-servlet.html