Fibonacci Series



public class Fibonacci {
public static long fib(int n) {
if (n <= 1) return n;
else return fib(n-1) + fib(n-2);
}

public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
for (int i = 1; i <= N; i++)
System.out.println(i + ": " + fib(i));
}
}
[Read More...]


Palindrome String



import java.util.*;

public class CheckPalindrome{
public static void main(String[] args) {
String str="madam";
Stack s= new Stack();
int i,count=0;
char array[]=str.toCharArray();
for(i=0;i(less than symbol)array.length;i++)
{
char arr=array[i];
s.push(arr);
}
for(i=0;i(less than symbol)array.length/2;i++)
{
char st=array[i];
Object ob=s.pop( );
if(st==ob) {
count++;
}
}
if(count==array.length/2) {
System.out.println("String is Palindrome");
}
else{
System.out.println("String is not a Palindrome");
}
}
}
[Read More...]


Palindrome number



import java.io.*;

public class Palindrome {
public static void main(String [] args){
try{
BufferedReader object = new BufferedReader(
new
InputStreamReader(System.in));
System.out.println("Enter number");
int num= Integer.parseInt(object.readLine());
int n = num;
int rev=0;
System.out.println("Number: ");
System.out.println(" "+ num);
for (int i=0; i<=num; i++){
int r=num%10;
num=num/10;
rev=rev*10+r;
i=0;
}
System.out.println("After reversing the number: "+ " ");
System.out.println(" "+ rev);
if(n == rev){
System.out.print("Number is palindrome!");
}
else{
System.out.println("Number is not palindrome!");
}
}
catch(Exception e){
System.out.println("Out of range!");
}
}
}
[Read More...]


File: Create a program for which out put wil be the same program



import java.util.*;
import java.io.*;
class Syam
{
public static void main(String args[])throws Exception
{
PrintWriter pw=new PrintWriter(System.out,true);
Scanner sc=new Scanner(new File("Syam.java"));
String s=null;
try
{
while((s=sc.nextLine())!=null)
{
pw.println(s);
}
}
catch(Exception e)
{
}
}
}
[Read More...]




Difference Between Two Days
import java.io.*;
import java.util.*;
import java.util.Date.*;
import java.util.Calendar;
import java.lang.Math.*;
import java.util.StringTokenizer;
public class DateDemo
{
String s,s1;
int i;
int d,d1,m,m1,y,y1;
public void add(String a,String b)
{
s=a;
s1=b;
StringTokenizer ss=new StringTokenizer(s,"/");
while(ss.hasMoreTokens())
{
d=Integer.parseInt(ss.nextToken());
m=Integer.parseInt(ss.nextToken());
y=Integer.parseInt(ss.nextToken());
}
StringTokenizer st=new StringTokenizer(s1,"/");
while(st.hasMoreTokens())
{
d1=Integer.parseInt(st.nextToken());
m1=Integer.parseInt(st.nextToken());
y1=Integer.parseInt(st.nextToken());
}
Calendar c1=Calendar.getInstance();
Calendar c2=Calendar.getInstance();
c1.set(y,m,d);
c2.set(y1,m1,d1);

long t1=c1.getTimeInMillis();
long t2=c2.getTimeInMillis();
long t3=Math.abs(t1-t2);
i=60*1000*60*24;
System.out.println(t3);
long diff= t3/i;
System.out.println("Difference btn"+ s+" and"+s1+" is"+diff+"days");
}
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
DateDemo dd=new DateDemo();
System.out.println("Enter the date as dd/mm/yyyy");
String d1=br.readLine();
System.out.println("Enter second date as dd/mm/yy");
String d2=br.readLine();
dd.add(d1,d2);
}
}
[Read More...]




[Read More...]


JavaScript Tutorials



JavaScript can be used to validate forms, provide interactive calendars, post the current day's headlines, produce background effects on a Web page, and play games, among many other things.

Netscape created JavaScript in 1995. It was originally called "LiveScript”.

An Introduction

JavaScript is not Java

JavaScript can either be client-side or server-side

JavaScript is an object-based scripting language

JavaScript is cross-platform

JavaScript comes in different 'flavors'

  • JavaScript: This was the name given by Netscape, who invented it.
  • JScript: This is the scripting language invented by Microsoft to compete with JavaScript.
  • ECMAScript: The de facto international standard for JavaScript. This standard covers the core of the language.

Comments

// This whole line will be ignored by the JS interpreter

var myOldCar = Ford // The first part will be interpreted; this part will be ignored.

If you need to comment out several lines, you would begin with a forward slash and an asterisk, "/*", and end with an asterisk and a forward slash, "*/". For example,

/* All of this, all three lines,

will be ignored in their entirety

by the JavaScript interpreter */

Remember that JavaScript is case-sensitive.

Remember that the semicolon at the end of a statement is optional in JavaScript. But it is a good programming practice to include one.

Where Does the Script Go?

There are three places where a script can be located:

  1. In the top section of the page ("head"), between the and tags;
  2. In the middle section of the page ("body"), between the and tags; or
  3. In a separate file.

Placing the Script on the Page

When the script is placed on the page, it is located between a set of container tags that look like:

 
 

Data Types

JavaScript is a "loosely typed" language, meaning you don't need to specify the type of data being declared in a variable.

There are four basic data types used in JavaScript: strings, numbers, booleans, and nulls.

1. Strings

The following are examples of a string:

  "cheeseburger"
  "123 Main Street, Anytown, FL 32714"
 
  var favfood="a big juicy hamburger";  // Correct
  var favfood='a big juicy hamburger';  // Correct
 
  var favfood="a big juicy hamburger';  // Incorrect

HTML elements can also be used inside of strings. Doing so will help you to create more dynamic pages.

document.write("This is really fantastic!");

2. Numbers

· JavaScripts recognizes two types of numbers: integers and floating point numbers.

· Integers are whole numbers (e.g., 1, 20, 546).

· Floating point numbers are numbers that have a decimal point (e.g., 23.8, 23.890).

·         Default is floating point number.

3. Boolean

A Boolean data type is used for true or false statements. It's mostly used in if() statements:

  var myCar=Chevy;
  if (myCar==Chevy)
  ...
 

4. Null

A null variable has no value. A null variable is useful for testing input in scripts. Since it's a keyword, it doesn't need to be enclosed in quotation marks:

  var nothingNow=null;

Variables

A variable is declared using the var reserved word. A variable can be declared and initialized using one of two methods.

  var myName;
      myName="Lee";
 
  var myName="Lee";

Our First Script

Let's take a break and write our first script. First, open a new document in your text editor and insert the following HTML elements:

Top of Form

Just a Demo

This will give an alertbox.

The JavaScript Diaries: Part 2

This time, we use a prompt box. 
 
 
 

Just a Demo

 

A prompt is the result of this program.

Special Operators

Operator

Name

Description

?:

Conditional

A type of if...else statement. A condition is placed before the (?) and a value is placed on each side of the (:)

,

Comma

Used to process a series of expressions

delete

Delete

Deletes an object, property, or element from an array

in

In

Used to inspect the contents of a specified object

instanceof

Instanceof

Tests an object to see if it is of a specified object.

new

New

Creates an instance of an object

this

This

Refers to the current object

typeof

Typeof

Identifies the type of value being evaluated

void

Void

Evaluates an expression without returning a value

Writing Functions

 function giveName()
  {
     code goes here;
    code goes here;
  }
Calling a Function

giveName();.

Example:

Place this in the portion:

Then, put this in the portion:

Window Object Event Handlers

An event handler is a JavaScript

keyword that allows a script to perform certain functions based on events on a Web page. Anytime something happens — a page loads, a link is clicked, the mouse moves — an event happens. Many times it's desirable to control these events. This can be done by using event handlers.

onLoad

Thisevent handler is used to execute a script after a page has fully loaded. That

includes loading all scripts, graphics, plugins and Java applets.

onUnload

This event handler is used toexecute a script before the page in the browser is exited. It's executed in the same manner as the onLoadevent handler. An example would be:

onFocus

This eventhandler executes whenever a window or form element is selected by the visitor

by clicking on the item, using the keyboard, or through manipulation by a script. An example is shown below:

  Credit Card Number:
  

onBlur

This event handler is executedwhenever the window or form element loses the focus. It's the opposite of the onFocus event handler.

It can be used like this:

  Credit Card Number:
  
onError

This event handler is executedwhenever an error is encountered. It's used to provide an alternative response when an error happens. If used, it should be placed toward the beginning of the script so it's available when the script is executed. An example would be:

window.onError = errpage();
 function errpage() {
  document.write(“Error”);
}

The history Object

Browsers store a list of URLs that the user has previously visited. This list enables the user to navigate to previously visited Web pages using the back and forward buttons in the browser. This list of URL's is called the browser's history. It's stored in the form of a list (a portion is pictured at right) that can be accessed by JavaScript. For security reasons, a JavaScript function can't read the URL's that are stored in the history object, so you can't use the list to figure out where your visitors have been.

Methods

back()
forward()

The back() and forward() methods do exactly what they say. They reload the previous page or go to the next page in the browser's history. They act exactly like the browser's Back and Forward buttons. The methods can be written as follows:

  onClick="history.back()"> // combine with line above
  onClick="history.forward()"> // combine with line above
  

go()

The go() method is used to move forward or back more than one page at a time in the history list. This is done by placing the number of pages you want to go in the parentheses. Positive numbers move the browser forward; negative numbers move the browser backward. It's like moving in steps. If you want to go forward one page (one step), use this:
history.go(1)

To go back two pages (two steps), you would use this:

history.go(-2)

The problem with this method is that you need to make sure that the browser's history contains that many URLs.

The Date Object

JavaScript uses the Date() constructor to obtain and manipulate the day and time in a script. The information is taken from the user's computer and is only as accurate as the user's system.

Creating Dates

var d=new Date();

document.write("The date is "+ d.toLocaleDateString()+"
"
);

document.write("and the time is "+ d.toLocaleTimeString());

which would print as follows:

The date is Friday, September 22, 2006
and the time is 2:29:28 PM


Related Topics

Javascript tutorials

Tags:Java tutorias


[Read More...]


Microsoft to strip Internet Explorer browser



San Francisco: Microsoft is to strip its Internet Explorer browser from the new version of its Windows 7 operating system that it sells in Europe, the company announced Thursday.

Microsoft said the move was designed to meet criticism from European Union (EU) regulators who have launched an investigation into whether bundling the browser with the operating system is in breach of European anti-trust rules.

"Given the pending Microsoft to strip Internet Explorer browser from European Windows, we will offer it separately and on an easy-to-install basis to both computer manufacturers and users," Microsoft said in a statement.

"This means that computer manufacturers and users will be free to install Internet Explorer on Windows 7, or not, as they prefer."

Windows 7 is scheduled to be generally available Oct 22. Ironically, Microsoft is making the changes as rival firms like Firefox, Apple Safari and Google Chrome chip away at Internet Explorer's once unassailable lead.
[Read More...]


Kerala Enterance Results



Today Kerala Medical and Engineering results are to be published.For results through phones you can call through BSNL 155300 and from other phones 0471-2115054,2115098.

Click to check your Results
Tags:Engineering Enterance results,Kerala Enterance Results,Kerala Engineering Enterance Results,Medical enterance results,Medical enterance results 2009,Kerala Engineering Enterance Results 2009,Enterance 2009
[Read More...]


Ajax ........



[Read More...]


Ajax in a page



[Read More...]


Getting Started with Struts 2



Struts 2 is an interesting tool for creating web project.

To do struts 2 project in eclipse.

Here we can use eclipse europa version..

File- >new - >other->web- >dynamic web project-> next- >give project name- >next- > next->finish.

Now you can see a folder in the project explorer having the name( here assume demo) that you have given.
the directory structure for our application is given below.

create folder classes inside WEB-INF. Save all packages containing class files inside it.Also save struts.xml file inside this.

copy library files inside :demo\WEB-INF\lib

demo\WEB-INF > web.xml

create jsp files inside demo along with WEB-INF.

To run the project

1. Navigate to "Window -> Show View -> Other..."
2. Open "Server" and select "Servers". This will open a "Servers" tab, probably in your bottom tab panel.
3. Right-click in the new "Servers" tab and select "New -> Server"
4. Select the version of Tomcat you installed and click "Next"
5. Click "Browse" and locate your Tomcat installation, and click "Next"
6. If "demo" isn't already in the "Configured projects" column, move it over and click "Finished"



Now, you should be able to run and debug your project in Tomcat. The way I prefer to do this is to:

1. Right-click on the 'demo' project in the "Package Explorer" and select "Run As -> Run on Server"
2. Select the Tomcat server you set up and click "Finish"
[Read More...]


MSSQL Connection



try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:dsn");
}catch(Exception ex){
ex.printStackTrace();
}
[Read More...]


Mysql Connection



public UserDB() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/ss","root","root");
} catch (Exception e) {
System.out.println("GetConnection"+e);
}
}
[Read More...]


oracle connection



Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@deepak:1521:orcl","scott","tiger");
} catch (Exception e) {
e.printStackTrace();
}
[Read More...]


set path for jsp...



copy from--D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib
servlet-api,jsp-api,el-api
and paste inside
C:\Program Files\Java\jdk1.6.0_02\jre\lib\ext
Setting path
------------
set path for java then
JAVA_Home-C:\Program Files\Java\jdk1.6.0_02
[Read More...]


java coding For getting no of Days in a month



import java.util.Scanner;

public class DateDemo
{
public static void main(String[] args)
{
//Create scanner object to obtain input from user
Scanner input = new Scanner (System.in);

int MonthNum; //To hold the month from user input
int Year; //To hold the year
int numDays;
String Month;

System.out.print("Please enter the Month #");
MonthNum = input.nextInt();
System.out.print("Please enter the Year");
Year = input.nextInt();

if (MonthNum == 2)
{
if ( (Year % 4 == 0) && (Year % 400 == 0)
&& !(Year % 100 == 0) )
numDays = 29;
else
numDays = 28;
}
else if (MonthNum == 1 || MonthNum == 3 || MonthNum == 5 || MonthNum == 7 || MonthNum == 8
|| MonthNum == 10 || MonthNum == 12)
numDays = 31;
else
numDays = 30;

if (MonthNum == 1)
Month = "January";
else if (MonthNum == 2)
Month = "Feburary";
else if (MonthNum == 3)
Month = "March";
else if (MonthNum == 4)
Month = "April";
else if (MonthNum == 5)
Month = "May";
else if (MonthNum == 6)
Month = "June";
else if (MonthNum == 7)
Month = "July";
else if (MonthNum == 8)
Month = "August";
else if (MonthNum == 9)
Month = "September";
else if (MonthNum == 10)
Month = "October";
else if (MonthNum == 11)
Month = "November";
else if (MonthNum == 12)
Month = "December";


System.out.println(Month + " " + Year " has " + numDays "." );
System.out.println(Month);
System.out.println(numDays);
}
}

Difference Between Two Days

package org.kodejava.example.java.util;
02.
03.import java.util.Calendar;
04.
05.public class DateDifferentExample
06.{
07. public static void main(String[] args)
08. {
09. // Creates two calendars instances
10. Calendar cal1 = Calendar.getInstance();
11. Calendar cal2 = Calendar.getInstance();
12.
13. // Set the date for both of the calendar instance
14. cal1.set(2006, 12, 30);
15. cal2.set(2007, 05, 03);
16.
17. // Get the represented date in milliseconds
18. long milis1 = cal1.getTimeInMillis();
19. long milis2 = cal2.getTimeInMillis();
20.
21. // Calculate difference in milliseconds
22. long diff = milis2 - milis1;
23.
24. // Calculate difference in seconds
25. long diffSeconds = diff / 1000;
26.
27. // Calculate difference in minutes
28. long diffMinutes = diff / (60 * 1000);
29.
30. // Calculate difference in hours
31. long diffHours = diff / (60 * 60 * 1000);
32.
33. // Calculate difference in days
34. long diffDays = diff / (24 * 60 * 60 * 1000);
35.
36. System.out.println("In milliseconds: " + diff + " milliseconds.");
37. System.out.println("In seconds: " + diffSeconds + " seconds.");
38. System.out.println("In minutes: " + diffMinutes + " minutes.");
39. System.out.println("In hours: " + diffHours + " hours.");
40. System.out.println("In days: " + diffDays + " days.");
41. }
42.}
[Read More...]


 

Recent Comments

Popular Posts

Return to top of page Copyright © 2010 | Platinum Theme Converted into Blogger Template by HackTutors