Interview Wiki Java v1/2 Flashcards
(Beginner) What is the MVC pattern?
The Model-View-Controller pattern.
Application logic is separated into three layers:
–a model, which knows about the data
–a view, which knows how to display things
–a controller, which implements application logic and knows how to map the raw data into the elements to be displayed.
(Beginner) Are you familiar with any other design patterns other than MVC?
Common answers: Singleton, Factory, Observer, Facade
(Beginner) What is the command line utility used to compile java source code into byte code?
javac
(Beginner) How do you handle exceptions in Java?
try, catch, finally
(Beginner) What is the difference between Final, finally and finalize()?
Final - declares a constant who’s value can’t be changed, or a method which can’t be overridden
finally
- is always called before leaving a try catch block.
- Used usually to close connections.
- Typically used for freeing resources.
finalize() - Called during garbage collection
(Beginner) What is the difference between == operator and equals () method?
== compares objects (memory locations — are they the same instance)
.equals compares the object content based on how the class defines equality for instances of the class.
(Intermediate) What is AJAX?
A) AJAX = Asynchronous Javascript and XML
A) AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes… allows parts of a web page to be updated, without reloading the whole page.
(Intermediate) What is the difference between overriding and overloading methods?
A) Overwriting (Overriding) means having two methods with the same arguments, but different implementations. For example, a parent class has a method doWork() that does work for the what is present in the parent class. A child class extends the parent class, and needs to do work differently. The child class would override the doWork() method from the parent class.
A) Overloading means that you have multiple methods with the same name but different method signatures. For example, in the String class, there are 4 different indexOf methods: indexOf(int ch), indexOf(int ch, int fromIndex), indexOf(String str), indexOf(String str, int fromIndex)
(Intermediate) What does protected mean?
protected - changes the scope of the class or method to only be accessible to other classes or sub classes in the same package
(Advanced) What is the difference between SOAP and REST Web Services? (http://keydifferences.com/difference-between-soap-and-rest-web-services.html)
- SOAP is a protocol that is based on the HTTP protocol.
- REST is an architecture that uses the different HTTP methods to act on a resource.
(Advanced) Which HTTP methods are supported by RESTful web services ? (http://www.restapitutorial.com/lessons/httpmethods.html)
GET, POST, PUT, PATCH and DELETE
(Advanced) What do http methods do? What are they used for? (http://www.restapitutorial.com/lessons/httpmethods.html)
GET: The HTTP GET method is used to read (or retrieve) a representation of a resource. In the “happy” (or non-error) path, GET returns a representation in XML or JSON
POST: The POST verb is most-often utilized to create new resources. In particular, it’s used to create subordinate resources. That is, subordinate to some other (e.g. parent) resource. In other words, when creating a new resource, POST to the parent and the service takes care of associating the new resource with the parent, assigning an ID (new resource URI), etc.
PUT: PUT is most-often utilized for update capabilities, PUT-ing to a known resource URI with the request body containing the newly-updated representation of the original resource
PATCH: PATCH is used for modify capabilities. The PATCH request only needs to contain the changes to the resource, not the complete resource.
DELETE: DELETE is pretty easy to understand. It is used to delete a resource identified by a URI.
(Advanced) What are the differences between a LinkedList and an ArrayList? When might you prefer a LinkedList over an ArrayList?
There are many differences.
—ArrayList provides efficient random access, but has expensive inserts/deletes in the middle of the list and semi-expensive size growth.
—LinkedList provides cheap insertions at any point in the list, but only supports sequential iteration starting from the ends, and also uses more memory.
(Advanced) What are autoboxing and unboxing?
A) Boxing is the process of converting a primitive type (such as an int) to an object type (such as Integer), and auto-unboxing is the reverse process. Prior to Java 5, this had to be done with manual casts, but Java 5 and higher will automatically perform the conversions where necessary. One common scenario where this is useful is when working with generic collections - only object types can be used with generics, so without autoboxing, storing e.g., primitive ints in an ArrayList would require a significant amount of manual casting between int and Integer. (More details)
(Advanced) What will unboxing do with null values?
A NullPointerException will be thrown because you can’t have null invoke a method.
Ex: To unbox an Integer object to int, Java calls the “Integer Object”.intValue() method.
(Advanced) What is Cross Site Scripting (XSS) and how would you protect against it?
It is a Security Vulnerability that allows the user to inject javascript into a webpage and can get the page to execute that script.
Hackers will use this to steal a users session cookies and compromise their account.
To protect against it you can use:
1. URL Encoding and Use Reg Expressions to Filter out non Alpha Numeric Characters.
2. black list or white list to validate inputs.
(Advanced) If you could change one thing about Java what would it be?
Come up with answer - no answer was provided
(Java EE Questions) What is a deployment descriptor?
Typically it is a file that holds configuration information about how an application should be deployed in a JavaEE environment. For instance, in a web application. the web.xml file defines what servlets receive which URL mappings, what the index files are, what the error conditions are, and what roles are required for certain HTTP methods.
(Java EE Questions) What is an EJB?
An EJB is an Enterprise Java Bean. It is a Java class that is defined to interact directly with the JavaEE environment.
(Java EE Questions) What benefits do we get from using EJBs?
We can put JavaEE extensions in an EJB for things like transactions, validations, restart/retry logic.
(Java EE Questions) What is a Web container?
A web container is a Java application that serves web applications that are packaged in the form of WARs (Web Application Resource).
Technically, these are different from web application servers
(Java EE Questions) What is a Web Application Server?
Implementation of a JavaEE server
(Java EE Questions) When to use web containers vs. web application servers?
—Web container used if you do not need a full stack JavaEE server.
—Most web applications probably only ever need a web container.
—If you need to do stuff with EJB’s, you will either need to add frameworks to the web container or just run a web application server.
(java v2 Core) Discuss some of the features of Java. Comparedd to other languages.
4 things
generics, autoboxing, annotations, varArgs
Generics - provides compile-time (static) type safety for collections and eliminates the need for most typecasts (type conversion).
AutoBoxing - Automatic conversions between primitive types (such as int) and primitive wrapper classes (such as Integer
Annotations - allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities.
Varargs - The last parameter of a method can now be declared using a type name followed by three dots (e.g. void drawtext(String… lines)). In the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type.
(java v2 Core) What is an interface? Why would you use one?
1) An Interface defines what has to be implemented;
2) Insulation from implementation, development can occur separately
_ _ ___
- Provides a standard implementation of some behaviors. You subclass and provide implementations for other methods.
- Commonly used in frameworks to provide structure and consistent implementation.
(java v2 Core) What is an abstract class? How is it different from an interface? Why would you use one?
Abstract class
—cannot be instantiated but allows implementation of methods
Implementation
—Provides a standard implementation of some behaviors. You subclass and provide implementations for other methods.
—Commonly used in frameworks to provide structure and consistent implementation.