The following Java Servlet shown below helps you determine whether your Browser Cookie Setting is On/Off; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class CheckCookieServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // If this is the first request to your Browser if (request.getParameter("cookieFlag") == null) { Cookie cookie = new [...]
Continue reading...Monday, August 25, 2008
Fibonacci Series This Program generates Fibonacci series for a given number of times. Output: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 public class FibonacciSeries { /* * Generates the Fibonacci Series */ public void generateSeries(int num) { int f1, f2 = 0, f3 = 1; System.out.println("fib(0) = " + f2); for (int i = 1; i <= num; i++) [...]
Continue reading...Sunday, July 6, 2008
public class Factorial { public static long factorial(int n) { if (n <= 1) return 1; else return n * factorial(n - 1); } public static void main(String[] args) { for (int i = 1; i <= 10; i++) System.out.println("Factorial of "+i+" : "+factorial(i)); } }
Continue reading...Wednesday, June 18, 2008
Blogs in Wordpress can be created either in a subdomain of wordpress or with your own domain name. So there can be 2 scenarios. For the ones that are created under wordpress (subdomain of wordpress) syntax highlighting plugin is activated by default. So if you want java code to appear with syntax highlighting you need [...]
Continue reading...
Sunday, October 26, 2008
1 Comment