Misc Interview Questions

Java Quick Notes

Refresh Your Java

We are Agile, believe in less Documentation - Only Quick notes of Java/J2ee Read more....

Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

"Click on other Tabs for more Questions"  

"Misc "

Focuses on Miscellaneous things including DB,JavaScript or some other useful stuff.

1 )   Quick HTML Tags


Body Tag with onLoad Event :

<body onLoad="populateComboBox()"> </body>

Some other Events , onunload

HyperLink with OnClick Event :

<a href="http://test" onClick="alert('You Clicked on HyperLink')">Visit your side</a>

Some Other Events,  onmousedown,onmousemove

Tooltip -  Use "alt" attribute for ToolTip

Input Text Box :
<input type="text" name="yourname" />

Text Area :

<textarea rows="2" cols="30">
 your First Text Are

Button with OnClick:
<button type="button" onClick='yourSubmit();'>Click </button>
 <input type="button" value="Click">

Submit Button :
<input type="submit" value="Submit" />

Reset Button :
<input type="reset" value="Reset" />

CheckBox :
<input type="checkbox" name="vehicle" value="Bike" checked />

Combo Box :

<select id='stateList' onchange='OnChange(this)'>
  <option value="NJ">New Jersy</option>

Bullet List

 <ul >
         <li>First Bullet</li>
         <li>First Bullet</li>
 Div :

For invisible
 <div style="display: none;">
  <h2>Click Here</h2>

For Visble

 <div style="display: block;">
  <h2>Click Here</h2>

Back to top

2 )   EHCACHE Example ?



Step 1: Get the EhCache Manager

BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(f));
CacheManager cacheManager = CacheManager.create(bis);

Step 2 : Putting Data in Cache
Object valeu = element.getValue();

Step 3 : Getting Data From Cache
cacheManager.getCache(YOUR_CACHE).put(new Element(key, value));

Configuration : Ehcache.xml

<cache name="YOUR_CACHE"


Back to top

3 )   Java template engine ?


Java "template engine" is a generic tool to generate text output (anything
 from HTML to autogenerated source code) based on templates. It's a Java package,
a class library for Java programmers. It's not an application for end-users in itself,
but something that programmers can embed into their products.

Really helpful for creating a Generic HTML tables or Email Contents or Document Contents. 

Back to top

4 )   Free Marker Templete Engine ?


import freemarker.template.*;
import java.util.*;
import java.io.*;

public class FreeMarkerExample {

    //Load the Templates only once
       /* Create and adjust the configuration */
        Configuration cfg = new Configuration();
                new File("/store/templates"));

        cfg.setObjectWrapper(new DefaultObjectWrapper());

    public static void main(String[] args) throws Exception {
        /* Get a template */
        Template temp = cfg.getTemplate("test.ftl");

        /* Create a data-model */
        Map root = new HashMap();
        root.put("user", "John Joe");
        Map latest = new HashMap();
        root.put("latestProduct", latest);
        latest.put("url", "test/yourTest.html");
        latest.put("name", "yourTest");

        /* Merge data-model with template */
        Writer out = new OutputStreamWriter(System.out);
        temp.process(root, out);

Back to top

5 )   Velocity Template Engine Example ?


Step 1: Create a .vm file

  Hello $name !  How are you ?

Sample : input this to ve.getTemplate()
import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
public class HelloWorld
    public static void main( String[] args )
        throws Exception
        /* initialize an engine  */
        VelocityEngine ve = new VelocityEngine();
        /*  get the Template  */
        Template t = ve.getTemplate( "sayHello.vm" );
  /*  create a contex */
        VelocityContext context = new VelocityContext();
        context.put("name", "John");
        StringWriter writer = new StringWriter();
  t.merge( context, writer );
        System.out.println( writer.toString() );    

Output : Please see below Name is replaced with "John"

Hello John !  How are you ?

Back to top

6 )   JDBC Connection String for MYSQL ?



Jar name : mysql-connector-java-5.1.20



Back to top

7 )   JDBC Connection Srting for Sybase Database ?


 DRIVER = "com.sybase.jdbc2.jdbc.SybDataSource";
 URL = "jdbc:sybase:Tds:Host:port/yourDB";

Please note these are one of the possible values, there values vary based on Driver Jar. 


Back to top

8 )   No suitable driver found for "jdbc:mysql://" , how to solve ?



Please add the appropriate Driver Jar to classpath Or If this happens in a WEB app, please palce the Driver jar in WEB-INF/lib.

In above case we need to add "mysql-connector-java-5.1.20-bin.jar"

Back to top

9 )   JDBC Connection URL and Driver for MS SQL ?




If you want to integrate with your Windows Credentials, please use the following.

i) SQL_JDBC_URL=jdbc:sqlserver://SQLRPT:1433;databaseName=yourDB;

ii) You should add the library as System Parameter.


Back to top

10 )   How to create a HTML log file ?


Step 1:

You need to create a Log4J property files , take a look at a sample below.

log = C://logs//log

log4j.rootLogger = INFO, FILE

# Define the file appender


# Define the layout for file appender
log4j.appender.FILE.layout.Title=HTML Layout Example

Step 2:

Create your own "ownHTMLFileAppender"

package util;

import java.io.File;
import java.io.IOException;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Layout;
import org.apache.log4j.spi.ErrorCode;

* This is a customized log4j appender, which will create a new file for every
* run of the application.
public class OwnHTMLFileAppender extends FileAppender {

public OwnHTMLFileAppender() {

public OwnHTMLFileAppender(Layout layout, String filename,
  boolean append, boolean bufferedIO, int bufferSize)
  throws IOException {
 super(layout, filename, append, bufferedIO, bufferSize);

public OwnHTMLFileAppender(Layout layout, String filename,
  boolean append) throws IOException {
 super(layout, filename, append);

public OwnHTMLFileAppender(Layout layout, String filename)
  throws IOException {
 super(layout, filename);

public void activateOptions() {
if (fileName != null) {
 try {
  fileName = getNewLogFileName();
  setFile(fileName, fileAppend, bufferedIO, bufferSize);
 } catch (Exception e) {
  errorHandler.error("Error while activating log options", e,

private String getNewLogFileName() {
if (fileName != null) {
 final String DOT = ".";
 final String HIPHEN = "-";
 final File logFile = new File(fileName);
 final String fileName = logFile.getName();
 String newFileName = "";

 final int dotIndex = fileName.indexOf(DOT);
 if (dotIndex != -1) {
  // the file name has an extension. so, insert the time stamp
  // between the file name and the extension
  newFileName = fileName.substring(0, dotIndex) + HIPHEN
    + +System.currentTimeMillis() + DOT
    + fileName.substring(dotIndex + 1);
 } else {
  // the file name has no extension. So, just append the timestamp
  // at the end.
  newFileName = fileName + HIPHEN + System.currentTimeMillis();
 return logFile.getParent() + File.separator + newFileName;
return null;

Step 3:

Read the Properties File

static {




private final static Logger log = Logger.getLogger(ValidateLogger.class);

Back to top

Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,

This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.

Face Book

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free

Go To Site Map