Java

http://www.devdaily.com
http://www.vaannila.com/struts-2/struts-2-example/struts-2-validation-example-1.html
http://www.precisejava.com/javaperf/j2ee/EJB.htm
http://www.devx.com/java/Article/29309/1954 
http://www.thatsjava.com/category/java-bean-j2ee/
http://sourceforge.net/
http://articles.sitepoint.com/category/java
http://pdf.coreservlets.com/ 
http://www.javalobby.org/articles/hibernatequery103/?source=archives
http://www.jwebhosting.net/servlets/jr123/fill.html 
http://devzone.skillfusion.com/jasperArticle8.php
www.orafaq.com/wiki/SQL_FAQ 
http://www.bodo.com/javacool.htm
http://www.roseindia.net/answers/viewqa/Java-Beginners/6613-how-to-store-data-in-table-using-swings.html
http://www.thatsjava.com/category/jdbc/
http://snippets.dzone.com/posts/show/12961
http://scjptest.com/ http://www.javalobby.org/java/forums/t76867.html
http://www.javachamp.com/public/renderExamQuestion.xhtml?groupId=1938 
http://www.jchq.net/mockexams/exam1.htm
http://www.javacertificationexams.com/scjp-mock-exams.php
http://www.javacertificationexams.com/view.php?book=home-1.tiscali.nl/~bmc88/java/javacert/newboone1-19.html&t=Sun+Certified+Programmer+Practice+Exam+by+Barry+Boone+Part+I
 http://www.java2s.com/Code/Oracle/User-Previliege/Grant-Permission.htm


"Misc "


Focuses on Miscellaneous things including DB,JavaScript or some other useful stuff.
1 )   Quick HTML Tags

Ans)
Body Tag with onLoad Event :
<body onLoad="populateComboBox()"> </body>
Some other Events , onunload
HyperLink with OnClick Event :
<a href="http://testonClick="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
</textarea>
Button with OnClick:
<button type="button" onClick='yourSubmit();'>Click </button>

 Or

 <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>
 </select>
Bullet List
 <ul >
         <li>First Bullet</li>
         <li>First Bullet</li>
 </ul>

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

2 )   EHCACHE Example ?

Ans)

Step 1: Get the EhCache Manager
File f = new File(EHCACHE_CONFIG_FULL_PATH);
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(f));
CacheManager cacheManager = CacheManager.create(bis);

Step 2 : Putting Data in Cache 
cacheManager.getCache(YOUR_CACHE).get(key));
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"
maxElementsInMemory="1000"
eternal="true"
timeToLiveSeconds="0"
timeToIdleSeconds="0"
diskPersistent="false"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"
>


3 )   Java template engine ?

Ans)
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. 
4 )   Free Marker Templete Engine ?

Ans)
import freemarker.template.*;
import java.util.*;
import java.io.*;
public class FreeMarkerExample {
    //Load the Templates only once
    static{
       /* Create and adjust the configuration */
        Configuration cfg = new Configuration();
        cfg.setDirectoryForTemplateLoading(
                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);
        out.flush();
    }
5 )   Velocity Template Engine Example ?

Ans)
Step 1: Create a .vm file
sayHello.vm:
  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();
        ve.init();
 
        /*  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 ?
6 )   JDBC Connection String for MYSQL ?

Ans)
db.url=jdbc:mysql://localhost:3306/dbName
db.driverName=com.mysql.jdbc.Driver
db.userName=userName
db.passWord=password
 
Jar name : mysql-connector-java-5.1.20


7 )   JDBC Connection Srting for Sybase Database ?

Ans)
 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. 
 

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

Ans)

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"
9 )   JDBC Connection URL and Driver for MS SQL ?

Ans)
SQL_DRIVER=com.microsoft.sqlserver.jdbc.SQLServerDriver
SQL_JDBC_URL_Org=jdbc:sqlserver://localhost:1433;DatabaseName=yourDB
If you want to integrate with your Windows Credentials, please use the following.
i) SQL_JDBC_URL=jdbc:sqlserver://SQLRPT:1433;databaseName=yourDB;
         integratedSecurity=true;
ii) You should add the library as System Parameter.
-Djava.library.path=C:\Softwares\sqljdbc_auth.dll
10 )   How to create a HTML log file ?

Ans)
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
log4j.appender.FILE=util.ownHTMLFileAppender
log4j.appender.FILE.File=${log}/ServiceResult.html
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.HTMLLayout
log4j.appender.FILE.layout.Title=HTML Layout Example
log4j.appender.FILE.layout.LocationInfo=true
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,
    ErrorCode.FILE_OPEN_FAILURE);
 }
}
}
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 {
PropertyConfigurator.configure("C://ServiceTestNew//conf//log4j.properties");
}
Step4:
private final static Logger log = Logger.getLogger(ValidateLogger.class);