Home > Development > Java and Random Interview Knowledge

Java and Random Interview Knowledge


  • Interpreted and Just-In-Time Compilation (JIT) – hybrid, translation occurs continuously but caches some of the translated machine code to prevent performance degradation
  • Portable – Java compiler generate bytecodes (architecture neutral intermediate format), setting strict definitions of the basic data types and behavior of the arithmetic operators.
  • Robust and reliable – compile time checking and a run-time checking. Automatic garbage collection.
  • High Performance – interpreter can run at full speed without need to check run-time environment
  • No Pointers, functions, structures, complex memory management
  • Have: Classes, Sub-classes, methods, interfaces, packages
  • Single inheritance (extend) of classes
  • Interface (implements) – only methods (no code), can extend multiple interfaces
  • Public (all classes), protected (only subclasses), private (within class)
  • Class variables (static – only one) and instance variable (shared with all objects)
  • Abstract Class/Methods – place-holders that subsequent subclasses must override
  • Synchronized methods – prevents thread interference and memory consistency errors

Object Oriented

  • Encapsulated data and procedures grouped together to represent an entity. Objects and their interactions to solve a problem, design a application or program.
  • Abstraction – data and programs are defined with a representation similar to its meaning and hide away the implementation details, e.g. object
  • Modularity – separate interchangeable components, breaking down program functions into modules
  • Encapsulation–implements information hiding and modularity (abstraction)
  • Polymorphism–the same message sent to different objects results in behavior that’s dependent on the nature of the object receiving the message
  • Inheritance–you define new classes and behavior based on existing classes to obtain code re-use and code organization
  • Dynamic binding–objects could come from anywhere, possibly across the network. You need to be able to send messages to objects without having to know their specific type at the time you write your code. Dynamic binding provides maximum flexibility while a program is executing. Process of mapping a specific sequence of code at runtime.


  • Virtual method table, virtual function table
  • Dynamic dispatch (run-time method binding)
  • Table that contain the addresses of the object’s dynamically bound methods. Method calls are performed by fetching the method’s address from this object’s vtable. Same for objects from same class.

Overloading and Overriding

  • Overloading – Type of polymorphism, different functions/methods of the same name are invoked based on the data types of the parameters passed
  • Overriding – An instance method in a subclass with the same signature that have different methods. Have same name, number, type of parameter, return type. (@override). Cannot override static methods.


  • constant


  • Final class cannot be extended
  • Final methods cannot be overridden by subclasses
  • Final variables can only be assigned once

Aspect-Oriented programming

  • Cross-cutting concerns – code scattering and tangling. Provide systematic means to modularize these concerns.
  • Implementation: Combined program or ultimate interpreter or environment is updated
  • Pointcut/Join points: the possible interaction points, point of execution in the application which cross-cutting concern needs to be applied.
  • Advice: the additional code that you want to apply to your existing model.
  • Aspects: a module that encapsulates a concern, combination of a pointcut (Join point) and a advice


  • Unit testing framework
  • Linked as a JAR at compile time
  • Test fixtures: setUp, teardown (@Before, @After) methods
  • Place in same class directory to test that class

Database: Normalization

  • Efficiently organizing data in a database
  • Goals: eliminating redundant data (storing same data in more than one table), ensuring data dependencies make sense (only storing related data in a table)
  • Normal forms – guidelines to ensure databases are normalized. 1NF-5NF.
  • BCNF – slightly stronger than 3NF

Database: Denormalization

  • Attempt to optimize the read performance by adding redundant data or by grouping data
  • Cover up inefficiencies
  • E.g. If a query of normalized tables involves a join, creating a denormalized table avoids the join
  • Normalized database imposes a heavy access load over physical storage of data

Database: levels of database schema

  • Conceptual – map of concepts and their relationships
  • Logical – map of entities and their attributes and relations
  • Physical – particular implementation of a logical schema
  • schema

Database: requirements

  • Completeness
  • Overlap preservation
  • Extended overlap preservation
  • Normalization – independent entities and relationships should not be grouped together, no overlapping schema elements
  • Minimality – if any element of the database schema are dropped then the database schema is not ideal

Database: Mapping

  • One-to-one
  • One-to-many
  • Many-to-many



  • Set of properties that guarantee database transaction process reliably.
  • Atomicity
  • Consistency
  • Isolation – degree of locking data
  • Durability


Database: Locking

  • Lock is used when multiple users are accessing a database concurrently
  • Pessimistic locking – immediately locked when requested
  • Optimistic locking – only locked when changes are made to the record are updated


Performance Improvement

  • Code optimization – reusing code
  • Caching strategy
  • Load balancing
  • Distributed computing – multiple processes on single CPU, multiple CPU, machines

Tokenizer, Parser


  • Quick sort – nlogn, nlogn, n2 (already sorted list)
    • function quicksort(array)
    •      var list less, greater
    •      if length(array) ≤ 1
    •          return array  // an array of zero or one elements is already sorted
    •      select and remove a pivot value pivot from array
    •      for each x in array
    •          if x ≤ pivot then append x to less
    •          else append x to greater
    •      return concatenate(quicksort(less), pivot, quicksort(greater))
  • Merge sort – nlogn, nlogn, nlogn
·         function merge(left,right)
·             var list result
·             while length(left) > 0 or length(right) > 0
·                 if length(left) > 0 and length(right) > 0
·                     if first(left) ≤ first(right)
·                         append first(left) to result
·                         left = rest(left)
·                     else
·                         append first(right) to result
·                         right = rest(right)
·                 else if length(left) > 0
·                     append first(left) to result
·                     left = rest(left)
·                 else if length(right) > 0
·                     append first(right) to result
·                     right = rest(right)
·             end while
·             return result
  • Bubble sort – n, n2, n2
procedure bubbleSort( A : list of sortable items )
  n = length(A)
  for (i = 0; i < n; i++)
     /* back through the area bringing smallest remaining element to position i */
     for (j = n-1; j > i; j--)
        if A[j-1] > A[j] then
           swap(A[j-1], A[j])
        end if
     end for
  end for
end procedure

UML Diagrams

  • Structure diagrams – Class, Component, Composite, deployment, object, package, profile
  • Behaviour diagrams – activity, UML state machine, use case diagram
  • Interaction diagrams – communication, interaction overview, sequence, timing

Halting problem

  • Have a description of a computer program, decide whether the program finishes running or continues to run forever. Given a program and a input, whether the program will eventually halt or run forever.
  • Related to Turing machine

Travelling salesman problem

  • Given a list of cities and their pairwise distances, the task is to find a shortest possible tour that visits each city exactly once
  • Solutions: Brute force search, Branch-and-bound, Progressive improvement
  • Benchmark for many optimization methods. Large number of heuristics and exact methods are known.

Bin Packing problem

  • First fit algorithm – placing each item into the first bin in which it will fit – not optimal
  • First fit decreasing algorithm – sorting elements first into decreasing order – better

Java Design Patterns

GoF Design patterns – Interface over implementation

  • Abstract Factory – interface for creating a family of related objects, without explicitly specifying their classes. Avoid the idea of adding code to existing classes in order to make them support encapsulating more general information.
  • Singleton – only one instance of the class is created, provide a global point of access to the object. Consists of a static member, private constructor, and static get method
  • Builder, Prototype, Adapter, Bridge, Façade, Proxy, Chain of responsibility, interpreter, state, template

J2EE patterns

  • MVC – Model/View/Controller
  • Business Delegate
  • Service Locator
Categories: Development
  1. July 5, 2011 at 8:10 pm
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: