Corrected Interview Quetions and Answers

Anything that simple is too easy to look up. Questions like that are asked to gauge whether you understand the language that you claim to be experienced in. When you gave the wrong answer, that told the interviewer that your understanding is rather shallow. Review these typical interview questions and think about how you would answer them. I am not suggesting that every one should go contracting but by performing well at the interviews you can be in a position to pick the permanent role you like and also be able to negotiate your salary package. Those of you who are already in good jobs can impress your team leaders, solution designers and/or architects for a possible promotion by demonstrating your understanding of the key areas discussed in this book.
You can discuss with your senior team members about performance issues, transactional issues, threading issues (concurrency issues) and memory issues. In most of my previous contracts I was in a position to impress my team leads and architects by pinpointing some of the critical performance, memory, transactional and threading issues with the code and subsequently fixing them. Trust me it is not hard to impress someone if you understand the key areas.

For example:
-Struts action classes are not thread-safe
-JSP variable declaration is not thread-safe
-Valuable resources like database connections should be closed properly to avoid any memory and performance issues 
-Throwing an application exception will not rollback the transaction in EJB.

The other key areas, which are vital to any software development, are a good understanding of some of key design concepts, design patterns, and a modeling language like UML. 
These key areas are really worthy of a mention in your
resume and interviews.

For example:
-Know how to use inheritance, polymorphism and encapsulation. -Why use design patterns? 
-Why is UML important?If you happen to be in an interview with an organization facing serious issues with regards to their Java application relating to memory leaks, performance problems or a crashing JVM etc then you are likely to be asked questions on these topics. 

Read the questions and answers listed; you will also find some strategy suggestions with it.

Q:What is not possible using java class Inheritance?
A:1. Private members of the superclass are not inherited by the subclass and can only be indirectly accessed.
2. Members that have default accessibility in the superclass are also not inherited by subclasses in other packages, as these members are only accessible by their simple names in subclasses within the same package as the superclass.
3. Since constructors and initializer blocks are not members of a class, they are not inherited by a subclass.
4. A subclass can extend only one superclass

Q: What is an abstract class?
A: Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such.
A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.

Q: What is final?
A: A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

Q: What is the purpose of garbage collection in Java, and when is it used?
A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

Q: Describe synchronization in respect to multithreading.
A: With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors. 

Q: Explain different way of using thread?
A: The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

Q: What are pass by reference and passby value?
A: Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed. 

Q: What is HashMap and Map?
A: Map is Interface and Hashmap is class that implements that.

Q: Difference between HashMap and HashTable?
A: The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls. (HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time. HashMap is unsynchronized and Hashtable is synchronized.

Q: Difference between Vector and ArrayList?
A: Vector is synchronized whereas arraylist is not.

Q: Difference between Swing and Awt?
A: AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.

Q: What is the difference between a constructor and a method?
A: A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator.
A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.

Q: What is an Iterator?
A: Some of the collection classes provide traversal of their contents via a java.util.Iterator interface. This interface allows you to walk through a collection of objects, operating on each object in turn. Remember when using Iterators that they contain a snapshot of the collection at the time the Iterator was obtained; generally it is not advisable to modify the collection itself while traversing an Iterator.


How to learn Java?

I simply describe a Java beginners to learn something that to first to understand Java system design to have three aspects: the J2ME (J2SE Java, J2EE, KJAVA).Java 2 Platform J2SE Java, Standard, we often say to happen the JDK, mainly refers to this, and it is the foundation of the three, belong to the desktop level this part application development, if learn well easily expand J2EE and J2ME.J2ME, The Micro happen of The Java 2 Platform.Mainly used for embedded Java, such as cell phones, PDA, etc.The J2EE Platform, Enterprise, Java 2 happen is the so-called enterprise-level Java, suitable for Enterprise’s large application development.

Overview of J2SE:
Before you will learn from the study of J2SE Java started, contains the main content of the object-oriented concepts can be divided into: understanding, Java of basic grammar, Java desktop graphics interface application development, grasp the commonly used Java API, etc. (the key is to learn how to access).
Key: the Java basic grammar (circulation structure, data types, array, operators, etc), Swing, awt, event mechanism, file input/output stream processing, etc
Difficulties: the object-oriented idea understanding (interface, class, etc.), thread, socket network programming, etc
Video tutorial recommendation: SunXin video tutorial, the Java foundation ZhangXiaoXiang based video tutorial, the Java speak are very fine, and this two teachers in teaching has very good experience.

Overview of J2EE:
In the study, after the J2SE JAVA can try you slowly transition into the J2EE, of course, learning the J2EE sea requires a lot of the JAVA technology support, such as database technology, web programming technology, etc, stay I’ll detail of this two respects content.There are three will learn J2EE framework, if you say that you learned J2EE, but not the three framework, it may make people laugh tails off, the three framework are Struts, respectively, although these three and Hibernate frame it is widely used, but do not represent the three framework represents the J2EE, J2EE and many other things, such as the EJB, as one paragraph heavyweight (the heavyweight does not mean heavyweight players that meaning, the heavyweight not those heavyweight) framework, although this application slowly replaced by other frame again, but EJB3.0 presence also give it back to some vitality, as a distributed application framework, but also all to learn and understand knowledge.
Of course, just said to J2EE contains range is very wide, even if I see what I understand all technology speak, also does not represent the J2EE, this is a deep, wide knowledge need to work later found to slowly.I know also include:
JDBC: Java based database connection object, the foundation of it, only Hibernate package just
JNDI: Java naming and directory interface, J2EE important standard one
EJBS: had mentioned above
RMI: provide remote calling method support, mainly used for program distributed development
JMS: Java news service, middleware technology
JAVA: providing the J2EE platform IDL ability to interact with CORBA and interconnection and ability of the technology
JTS: component affairs monitors
JTA: affairs division a technical
The email JAVAMAIL: Java technology
JAF: Java start frame, no studied
Log4j, a paragraph of the framework application. Log treatment
Junit: unit test’s good helper
Freemarker, due to: two paragraphs good template engine
And Flash interactive Flex: at present a lot of to MSN application is used in the technology
Web services for: want to know our BBS weather forecast effect is how to do?Please attention this technology
SOA: the service oriented architecture, one of the trend of the development of the future technology
But these are introduced to the front of the foundation, is not the J2EE framework application level of belonging to the above said. To really grasp the knowledge, or learning J2EE core things: JDBC, JSP, servlet and JavaBean, behind three is also learning SSH basis (the Hibernate Struts \ are \ as the content). Given the J2EE is too complex, suggest that we first learned only: JSP, servlet and JavaBean, etc this foundation mastering again again to learn, SSH other J2EE technology has a roughly understanding to go out and get a job.Of course, find the job premise in addition to the Java study well, will still have some other technology is also must grasp.
-_ – I am very simple, Java is asking that I learn so many complicated things.In addition to these technical things, in this phase, everyone more is come into contact with such as design patterns things, such as factory model, bridge mode, single example mode, etc., also study modeling ideas (such as UML modeling, etc) and software lifecycle, etc.These are sublimation everybody programming method and approach of thought.
Database technology:
The database is almost program in an integral part of the development of the software, is occupied an important role in the whole software. Database plays the role of the foundation, you have to fix the house, will first dozen good foundation, you want to do software, will first design good database. Currently database is almost always a relational database, which represents a:
SQL Server, at present the latest like 2008, I don’t like pursued stylish, use of or 2005, but also very good, before this and 2000.
MySQL, one of the most famous open-source database, I like it very durable, learned the cabinet SQL SERVER databases to learn it, self-taught, a piece of cake.
ORACLE. ORACLE products, large database, the original general company can’t afford it. Only see, but now Java development 60% are will use to this database, plus now ORACLE have bought from, Java and ORACLE, you have more ambiguous relationship to spend more time on it.
In addition to these, you should also understand some desktop application software development using the database, for example sqlite.You made the installation program in this database can pack into your setup.
Web programming basis:
Web programming basis to learn more, but the contents are mainly concentrated in the following the three technology above, all the various style looked every day they represent the web are the:
HTML: hypertext markup language
CSS: cascading style sheets
Javascript: browser client script language
Now more popular, such as: various JavaScript library ExtJs Jquery, wait, if you will be one a repository of use, so light to find work.

Overview of J2ME:
If you are learning the above technology is not to satisfy, can learn the development of mobile phone program again, in my personal view, the development of mobile phone program technology actually pretty simple, which is difficult optimization, like how to get you write the program to try to save mobile resources, "code sincere commendable, cell phone price is higher," so have to think about a lot more than a PC cost and practical problems.J2ME learning words, avoid by all means does not simply to simulator test, must find the real machine test, the effect of the real machine and simulator is a lot of differences between.More mobile development of technology, have the interest friend and I can explore together.

Introduction to Java

The Java language was designed at Sun Microsystems over a five year period, culminating in its first release in January 1996. The developers, led by James Gosling, originally set out to build a language for controlling simple home devices with embedding microcomputers. Thus, they started with the object-oriented concepts of C++, simplified it, and removed some of the features, such as pointers, that lead to serious programming errors. While the team may have originally had in mind compiling this language for a specific microprocessor, instead they developed both the Java language and a hypothetical processor called the Java Virtual Machine or JVM. The Java compilers they developed produced binary code designed to execute on the JVM rather than on a PC or Sun workstation. The team’s working name for this evolving language was “Oak,” but as it neared completion, they found that Oak was already registered as a trademark. As the story goes, they came up with the name “Java” while taking a break at a coffee shop.

Executing Java Programs on Real Computers
To actually execute Java programs, they developed Java interpreters that ran on various machines and under various operating systems. Thus, Java became a language that would execute on a number of systems and now has implementations for virtually all common computers and operating systems. Sometime during development, it suddenly became obvious that Java would be an ideal language for use on the Internet, the popularity of which was growing at a phenomenal rate. They added a window manager to allow easy development of user interfaces; they also added network communication methods such as Web page URLs and sockets.
Since Java could now run on nearly any kind of workstation, it became an ideal vehicle for adding powerful computational capabilities to Web pages.

Java Applets
A Java applet is a program designed to be embedded in a Web page. Applets can be quite complex; they are not limited to simple animations or single windows. They can access remote databases or other sources of information and load and operate on complex information on your computer system. Java applets are designed to be quite secure, however. They can be safely downloaded over a network without causing concern that they might be able to do damage or mischief to your computer. They cannot write any information onto your hard disk unless you specifically give them access to a directory. They cannot access any other resources on your network or any other hardware or peripherals on your computer. Java applets are also restricted from writing into memory outside of the Java address space. This is accomplished mainly because Java has no memory pointer type and thus a malicious programmer cannot point to memory he or she might want to attack. Java applets are also scrutinized class by class as they are loaded by the run-time environment in your browser, and checks are made to assure that the binary code has not been modified such that it
might interact with or change any part of the memory of your system. Further, applets cannot access resources on any other computer on your network or elsewhere on the Internet, with one exception; they can open TCP/IP connections back to the machine running the Web server from which they were downloaded. To add even more protection and prevent programmers from spoofing users into giving them confidential information, all windows that you pop up from an applet have a banner along the bottom reading  “Unsigned Java Applet.” The banner serves to prevent hackers from designing an exact copy of a familiar screen and luring users to type confidential information into it.

Java Applications
By contrast, Java applications are full-featured programs that run on your computer and have full access to its resources. They can read, write, create, and delete files and access any other computer on the network. You will quickly appreciate that it is possible to develop full-fledged applications in Java: database viewers, word processors, spreadsheets, math packages, and file and network manipulation programs. In fact, one of Java’s great strengths is that it makes accessing other computers on your network extremely easy. Now you can write quite sophisticated programs in many other languages, so you might ask whether Java is really “ready” for all this attention. 

Advantages of Java
The advantages of Java are substantial for both simple applications and for complex server code.
1. Java is object oriented. Java requires that you write 100 percent
object-oriented code. As we will see, object-oriented (OO) programs
are easier to write and easier to maintain than the spaghetti code that is often the result of programming in other languages.
2. Java works on most platforms. While C/C++ programs are platform specific, Java binary byte code runs identically on most Unix machines, Macintoshes, and PC’s running Windows 95/98/ NT, Windows 2000, and Linux.
3. Java is network enabled. It is trivially simple to write code in Java
that works across networks. The use of URLs, TCP sockets, and
remote classes is essentially built into the language.
4. Java is multithreaded. You can write programs in which several
sections run simultaneously in different execution threads.
5. Java allows you to add major function to Web pages. If you are
interested in building interactive World Wide Web pages that
compute, collect, or display data, Java is the language of choice.
There simply is not a better way to add interactive controls to Web
pages. With all of these pluses, the only possible drawback is that you’ll have to learn a new language. This is, of course, what this book is about and we’ll see some very significant advantages to Java as we begin to explore it.