Posts

Showing posts from 2017

How to Create Whole Path Automatically and write into File In Java

        File file = new File("/home/anand/Desktop/filename.html");         file.getParentFile().mkdirs();         FileWriter writer = new FileWriter(file);                 bw = new BufferedWriter(writer);         PrintWriter  out = new PrintWriter(bw);         out.println("<h4>Welcome in Bangalore</h4>");         out.close();

How Session Managment Works in servlet/jsp

/*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.sql.*; /**  *  * @author pandey  */ public class Registration extends HttpServlet {     @Override     protected void doGet(HttpServletRequest request, HttpServletResponse response)             throws ServletException, IOException {         PrintWriter out = response.getWriter();         HttpSession hs = request.getSession();    ...

Java Experiance InterView Questions and answer

--> Example of SingleTone in java  public final class SingleTone {         /**      * @author anand      *      */             public static SingleTone single;     //Can be act as SingleTone or make constructor as private         private SingleTone(){}         public static synchronized SingleTone getInstance(){                 if(single==null){                         single=new SingleTone();         }         return single;     }     } --> What is difference between StringBuffer and StringBuilder in Jav...

Scheduler JOB in java

package com..scheduler; import static org.quartz.CronScheduleBuilder.dailyAtHourAndMinute; import java.util.Calendar; import org.quartz.Job; import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public class SchedulerTest implements Job {     public static void main(String[] args) {         int HOUR_OF_DAY = Integer.parseInt("20");         int MINUTE_OF_HOUR = Integer.parseInt("10");         Trigger trigger1 = TriggerBuilder.newTrigger().withIdentity("test trigger1", "group1").withSchedule(dailyAtHourAndMinute(08, 00)).build();         Trigger trigger2 = TriggerBuilder.newTrigger().withIdentity("test ...

How to write Scheduler in Java

import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; /**  * This Class is Used to Run Every after 15 min  *  * @author ananddw  **/ public class TestScheduler{     public static void main(String[] args) {         new TestScheduler().start();     }     public void start() {         System.out.println(" scheduler starts");         Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {             @Override             public void run() {                 try {                     //Need to Call Your Method which will execute every after 15 min     ...

how to get src value from normal Text in javascript

<html> <head> </head> <title>|| Video Uploader || </title> <body> <input type="text" id="video_url" name="video_url" value="<iframe   width='420' height='315'    src='https://www.youtube.com/embed/XGSy3_Czz8k'></iframe>"  /> <button id = "opener" onclick="insertURL()">Show URL </button> <script type="text/javascript"> <!-- If User's Provide direct URL or Full iframe innerhtml-->     function insertURL(){         var ishare_url = document.getElementById("video_url").value;                 if(undefined!==ishare_url.split('src=')[1]){         var src = ishare_url.split('src=')[1].split(/[ >]/)[0];         if(src){             var decode_ishare_url = decodeUR...

How to Add Javascript,CSS inside Javascript

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> var CSSURL="https://fonts.googleapis.com/css?family=Hind"; $(document).ready(function(){     $("p").click(function(){        alert("Hi");   $.getScript("https://code.jquery.com/ui/1.12.1/jquery-ui.js", function(){    alert("Script loaded but not necessarily executed."); });     }); }); var linkElem = document.createElement('link'); document.getElementsByTagName('head')[0].appendChild(linkElem); linkElem.rel = 'stylesheet'; linkElem.type = 'text/css'; linkElem.href = CSSURL; </script> </head> <body> <p>Click Here to load JS and CSS As well !</p> </body> </html>

How to Read XLSX File in Java Using apache Poi API

Image
Here we will implement the code to read XLSX file using apache POI API : and download required jars based on below snapshot Code : - /*  * To change this license header, choose License Headers in Project Properties.  * To change this template file, choose Tools | Templates  * and open the template in the editor.  */ package com.test.XLS; import java.io.*; import java.util.*; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; /**  *  * @author anand  */ public class XLSReader {     static final String fileName = "FriendsZone.xlsx";     FileInputStream file = null;     public void readXLSFile() {         try {             file = new FileInputStream(new File(fileName));             XSSFWorkbook workbook = new XSSFWorkbook(file);             XSSFSheet ...