Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Avaya Accessing Orchestration designer variables in servlet node



Setting value to OD variables in Servlet node:

mySession.getVariableField(IProjectVariables.C__COUNTS,IProjectVariables.C__COUNTS_FIELD_MAXNI).setValue("");

Writing trace info

TraceInfo.trace(ITraceInfo.TRACE_LEVEL_INFO,this.getClass().getName() + " -> Value - " + mySession.getVariableField("OD", "OD_complex").getStringValue(), mySession);



Read more »

Java code to connect Oracle database using JDBC driver



Making JDBC Query to database using code

 Connection conn=null;
 ResultSet rs1=null;

try
{
 PreparedStatement ps1=null;

Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:XE", "system", "manager");

Statement stmt = conn.createStatement();

rs1= stmt.executeQuery("select SUBJECT from HR.SUBJECT ");
}
catch(SQLException e)
{
while((e = e.getNextException()) != null) out.println(e.getMessage() + "");
  }
catch(ClassNotFoundException e)
{
 }


Reading the ResultSet

 try{
while(rs1.next()){
String ComboBoxValue1=rs1.getString("SUBJECT")  ; 
 }
                 catch(Exception exp){
 out.println("exception in populating subjects");
 }

Read more »

Java code to connect Oracle database using JDBC driver



Making JDBC Query to database using code

 Connection conn=null;
 ResultSet rs1=null;

try
{
 PreparedStatement ps1=null;

Class.forName("oracle.jdbc.driver.OracleDriver");

conn = DriverManager.getConnection( "jdbc:oracle:thin:@127.0.0.1:1521:XE", "system", "manager");

Statement stmt = conn.createStatement();

rs1= stmt.executeQuery("select SUBJECT from HR.SUBJECT ");
}
catch(SQLException e)
{
while((e = e.getNextException()) != null) out.println(e.getMessage() + "");
  }
catch(ClassNotFoundException e)
{
 }


Reading the ResultSet

 try{
while(rs1.next()){
String ComboBoxValue1=rs1.getString("SUBJECT")  ; 
 }
                 catch(Exception exp){
 out.println("exception in populating subjects");
 }

Read more »

Servlet Code to Update records in SQL database using Tomcat server

In this post we will illustrate how to Search and display information from database.
This post is continued from previous post have a look on how to do:

1. Database settings and Insetion of data into SQL database.
2. Searching information from Database
3. Deleting informstion from database

Create a html form upinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/upinfo>
<font face="Copperplate Gothic Bold">STUDENT NAME</font face>:<input type="text" name="t1" size="30"><p><br>
<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<font face="Copperplate Gothic Bold">AGE</font face>:<input type="text" name="t3" size="30"><p><br>
<font face="Copperplate Gothic Bold">BRANCH</font face>:<input type="text" name="t4" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>


Now Create a up.java which has the actual logic for deleting information from database.

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class upinfo extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("t1");
String s2=req.getParameter("t2");
String s3=req.getParameter("t3");
String s4=req.getParameter("t4");
out.println("<html><body><h1>............................servlet updating..........:):).......</h1></body></html>");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
String query="update studentinfo set name1='"+s1+"',age='"+s3+"',branch='"+s4+"'where id1='"+s2+"'";
out.println("<html><body><h3>updating from database.......</h3></body></html>");
Statement stmt=con.createStatement();
out.println("<h2>:):):)</h2>");
ResultSet rs=stmt.executeQuery(query);
out.println("<html><body><h4>thank you for registrating.......</h4></body></html>");
con.close();
}
catch(Exception e)
{
System.out.println("Error in login:"+e);
}
}
}


Read more »

Servlet Code to Delete information from SQL database Tomcat server

In this post we will illustrate how to delete information from database.
This post is continued from previous post have a look on how to do:
1. Database settings and insetion of data into SQL database.
2. Searching information from database.

Create a html form delinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/delinfo>

<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>


Now Create a delinfo.java which has the actual logic for deleting information from database.

import java.util.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class delinfo extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException
{
try
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s2=req.getParameter("t2");
out.println("<html><body><h1>............................servlet deletion working..........:):).......</h1></body></html>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
if(con!=null)
{
out.println("<html><body><h4>connection established........</h4></body></html>");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("delete from studentinfo where id1='"+s2+"'");
out.println("<html><body><h4>deleted from database.......</h4></body></html>");
stmt.close();
}



con.close();
out.close();


}
catch(Exception e)
{}
}
}

Deleting information from SQL database
Deleting information from SQL database




Read more »

Servlet Code for Searching information from SQL database Tomcat Server

In this post we will illustrate how to Search and display information from database.This post is continued from previous post have a look on how to do:

1. Database settings & Insetion of data into SQL database.

Create a HTML page named searchinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/searchinfo>

<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>


Now Create a Searchinfo.java which has the actual logic for seraching information and displaying it.


import java.util.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class searchinfo extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)
throws ServletException,IOException
{
try
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s2=req.getParameter("t2");
out.println("<html><body><h1>............................servlet retrieval working..........:):).......</h1></body></html>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
if(con!=null)
{
out.println("<html><body><h4>connection established........</h4></body></html>");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from studentinfo where id1='"+s2+"'");
out.println("<html><body><h4>retrieved from database.......</h4></body></html>");
ResultSetMetaData md=rs.getMetaData();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("retrieval servlet");
out.println("</head>");
out.println("<table border=1>");
out.println("<tr><td>student name</td><td>id</td><td>age</td><td>branch</td></tr>");
while(rs.next())
{
for(int i=1;i<md.getColumnCount();i++)
{
out.println("<tr><td>"+rs.getString(i++)+"</td><td>"+rs.getString(i++)+"</td><td>"+rs.getString(i++)+"</td><td>"+rs.getString(i++)+"</td></tr>");
out.println("***");
out.println("</table></body></html>");
}
}

rs.close();
stmt.close();
con.close();
out.close();

}
}
catch(Exception e)
{}
}
}

Searching information from SQL database
Searching information from SQL database

Read more »

Servlet code to insert data into MS SQL database using Tomcat Server

Unlike JSP and PHP Servlet is also server side scripting language. Servlet is Java based, Here this post we are going to illustrate how to add, delete , update and Search data from a form interacting with SQL database.
For consideration we will need tomcat server installed running on the system by default at port 8080 and sql database running on the system.

STEP 1:

Create database in Microsoft sql Query analyser .
Create table with 4 fields viz StudentName , ID , Age and Branch.
->Keep ID as  INT and set it as primary key
->keep StudentName as VARCHAR(100)
->keep age as INTEGER
->Keep Branch as VARCHAR(100)

STEP 2 :

This code is only for addition of information to the database

Create a html page as follows:

studentinfo.html

<html>
<head>
<h1><u>student form</u></h1>
</head>
<body bgcolor="DarkSalmon">
<form name=Student method=POST action=http://localhost:8080/examples/servlet/studentinfo>
<font face="Copperplate Gothic Bold">STUDENT NAME</font face>:<input type="text" name="t1" size="30"><p><br>
<font face="Copperplate Gothic Bold">ID</font face>:<input type="text" name="t2" size="30"><p><br>
<font face="Copperplate Gothic Bold">AGE</font face>:<input type="text" name="t3" size="30"><p><br>
<font face="Copperplate Gothic Bold">BRANCH</font face>:<input type="text" name="t4" size="30"><p><br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>

Now Create a page named studentinfo.java which has actual logic to interact with SQL database and insert information.

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class studentinfo extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doGet(req,res);
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
String s1=req.getParameter("t1");
String s2=req.getParameter("t2");
String s3=req.getParameter("t3");
String s4=req.getParameter("t4");
out.println("<html><body><h1>............................servlet running..........:):).......</h1></body></html>");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
out.println("<html><body><h4>connectiopn established........</h4></body></html>");
String query="insert into studentinfo values('"+s1+"','"+s2+"','"+s3+"','"+s4+"')";
out.println("<html><body><h3>inserting into database.......</h3></body></html>");
Statement stmt=con.createStatement();
out.println("<h2>:):):)</h2>");
ResultSet rs=stmt.executeQuery(query);
out.println("<html><body><h4>thank you for registrating.......</h4></body></html>");
con.close();
}
catch(Exception e)
{
System.out.println("Error in login:"+e);
}
}
}

inserting to SQL databse using servlet

Read more »

JSP Java Code to Search record in SQL database using Apache server


searchstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="searchstud"action="searchstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>enter the id u want to search:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
</form>
</body>
</html>

searchstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<table>
<tr>
<th>name</th>
<th>id</th>
<th>age</th>
<th>branch</th>
</tr>
<%
Connection con=null;
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement();
String s2=request.getParameter("id");
%>
<%

ResultSet res=stmt.executeQuery("select * from studentinfo where id1='"+s2+"'");
while(res.next())
{
%>
<tr>
<td><%=res.getString("name1")%></td>
<td><%=res.getString("id1")%></td>
<td><%=res.getString("age")%></td>
<td><%=res.getString("branch")%></td>
</tr>
<%
}
%>
</table>
</body>
</html>


OUTPUT:

Read more »

JSP Java code to Update Record in SQL database using Tomcat server

upstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="upstud"action="upstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>student name:</b>
<input type="text"name="name"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>id:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>age:</b>
<input type="text"name="age"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>branch:</b>
<input type="text"name="branch"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
<input type="button"value="delete"/>
</form>
</body>
</html>

upstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%
Connection con=null;
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
try
{
String s1=request.getParameter("name");
String s2=request.getParameter("id");
String s3=request.getParameter("age");
String s4=request.getParameter("branch");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement();
stmt.executeUpdate("update studentinfo set name1='"+s1+"',age='"+s3+"',branch='"+s4+"'where id1='"+s2+"'");
%>
data updated successfully...........
<%
stmt.close();
stmt=null;
}
finally
{
if(con!=null)
{
con.close();
}
}
%>
</body>
</html>

OUTPUT:


Read more »

JSP Java code to Delete Record using SQL and apache server

delstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="delstud"action="delstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>id:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
<input type="button"value="delete"/>
</form>
</body>
</html>


delstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%
Connection con=null;
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
try
{

String s2=request.getParameter("id");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement();
stmt.executeUpdate("delete from studentinfo where id1='"+s2+"'");
%>
data deleted successfully...........
<%
stmt.close();
stmt=null;
}
finally
{
if(con!=null)
{
con.close();
}
}
%>
</body>
</html>

OUTPUT:


Read more »

JSP Java Code to Post Data to SQL database using Tomcat Server

JSP is widely used Java based server side scripting language . Here in this tutorial I am going to give you code which  will post data from a html form. before you run through code ensure that the tomcat server is installed or you can download it directly from the official website also download and install Microsoft server 2000.Go to the database console and

1.Create  database named "student1".

2.Create table with four fields NAME,ID,AGE and BRANCH , keep ID as primary key.

First we began with creating a html form. For consideration here we are going to create a form for entering student details such as NAME,ID,AGE and BRANCH. The following is the code for form . Just name it addstud.jsp . After submit button is pressed  then the details are forwarded to addstudinfo.jsp which connects to the database and enters the data into mysql database.

addstud.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<br></br>
<h2><center>enter stuent details</center></h2>
<form name="addstud"action="addstudinfo.jsp"method="post">
<table border="2"align=center>
<tr><td>
<b>student name:</b>
<input type="text"name="name"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>id:</b>
<input type="text"name="id"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>age:</b>
<input type="text"name="age"/>
<br/>
<br/>
</td></tr>
<tr><td>
<b>branch:</b>
<input type="text"name="branch"/>
<br/>
<br/>
</td></tr>
</table>
<center>
<input type="submit"value="submit"/>
<input type="reset"value="reset"/>
<input type="button"value="delete"/>
</form>
</body>
</html>

addstudinfo.jsp

<%@page session="true"import="java.io.*"%>
<html>
<body bgcolor="#d0d0d0">
<br></br>
<br></br>
<%@page import="java.sql.*"%> //imports 
<%@page import="java.util.*"%>
<%
Connection con=null; 
Statement stmt=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","username","password");
try
{
String s1=request.getParameter("name");
String s2=request.getParameter("id");
String s3=request.getParameter("age");
String s4=request.getParameter("branch");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:student1","sa","sa");
stmt=con.createStatement(); //opening a connection
stmt.executeUpdate("insert into studentinfo(name1,id1,age,branch)values('"+s1+"','"+s2+"','"+s3+"','"+s4+"')");
%>
//inserting into database

data enterd successfully...........
<%
stmt.close();//close conncetion
stmt=null;
}
finally
{
if(con!=null)
{
con.close();
}
}
%>
</body>
</html>




Keep both the files in the tomcat server and then run it from the browser on port 8000 (or as configured on the system)
.
Read more »

Program to reverse a number and find its sum using java



PROGRAM:


                                                                     
                                                                     
                                                                     
                                             
package reverse;
import java.io.*;

 public class reverse {
 public static void main(String[] args)throws IOException {
        BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter a number ");
        int num=Integer.parseInt(in.readLine());
        int n=num;
        int temp=0,rem=0,sum=0;
       while(num>0)
        {
            temp=num%10;
            rem=rem*10+temp;
            num=num/10;
            sum=sum+temp;
        }
        System.out.println(rem+" is a reverse of "+n);
        System.out.println(sum+" is the sum of digit "+n);
        // TODO code application logic here
    }

}

OUTPUT:


                                                                     
                                                                     
                                                                     
                                             
 Enter a number 
 5432
 2345 is a reverse of 5432
 14 is the sum of digit 5432
Read more »

Remote Method Invocation RMI program code using Java



The program is written 3 files namely :RMI.java , RMIserver.java, RMIclient.java. This program implements RMI concept in java .
The Java Remote Method Invocation Application Programming Interface, or Java RMI, is a Java API that performs the object-oriented equivalent of remote procedure calls , with support for direct transfer of serialized Java objects and distributed garbage collection.

CODE:


RMI.java

import java.rmi.*;

public interface RMI extends Remote
{
void receiveMessage(String x) throws RemoteException;
}




RmiServer.java

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.net.*;

public class RmiServer extends java.rmi.server.UnicastRemoteObject
implements RMI
{
    int      thisPort;
    String   thisAddress;
    Registry registry;    // rmi registry for lookup the remote objects.

    // This method is called from the remote client by the RMI.
    // This is the implementation of the “ReceiveMessageInterface”.
    public void receiveMessage(String x) throws RemoteException
    {
        System.out.println(x);
    }

    public RmiServer() throws RemoteException
    {
        try{
            // get the address of this host.
            thisAddress= (InetAddress.getLocalHost()).toString();
        }
        catch(Exception e){
            throw new RemoteException("Can't get inet address.");
        }
        thisPort=3232;  // this port(registry’s port)
        System.out.println("This address="+thisAddress+",port="+thisPort);
        try{
        // create the registry and bind the name and object.
        registry = LocateRegistry.createRegistry( thisPort );
            registry.rebind("rmiServer", this);
        }
        catch(RemoteException e){
        throw e;
        }
    }
  
    static public void main(String args[])
    {
        try{
        RmiServer s=new RmiServer();
    }
    catch (Exception e) {
           e.printStackTrace();
           System.exit(1);
    }
     }
}


RmiClient.java

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;

public class RmiClient
{
    static public void main(String args[])
    {
       RMI rmiServer;
       Registry registry;
       String serverAddress=args[0];
       String serverPort=args[1];
       String text=args[2];
       System.out.println("Sending "+text+" to "+serverAddress+":"+serverPort);
       try{
           // get the “registry”
           registry=LocateRegistry.getRegistry(
               serverAddress,
               (new Integer(serverPort)).intValue()
           );
           // look up the remote object
           rmiServer=
              (RMI)(registry.lookup("rmiServer"));
           // call the remote method
           rmiServer.receiveMessage(text);
       }
       catch(RemoteException e){
           e.printStackTrace();
       }
       catch(NotBoundException e){
           e.printStackTrace();
       }
    }
}





OUTPUT:



Server Output:-
C:\Program Files\Java\jdk1.5.0\bin>javac RMI.java

C:\Program Files\Java\jdk1.5.0\bin>javac RmiServer.java

C:\Program Files\Java\jdk1.5.0\bin>rmic RmiServer

C:\Program Files\Java\jdk1.5.0\bin>java RmiServer
This address=i3-05/192.168.100.180,port=3232
Hi,
This
is
Ascyena


Client Output:-
C:\Program Files\Java\jdk1.5.0\bin>javac RmiClient.java

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 Hi,
Sending Hi, to 192.168.100.180:3232

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 This
Sending This to 192.168.100.180:3232

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 is
Sending is to 192.168.100.180:3232

C:\Program Files\Java\jdk1.5.0\bin>java RmiClient 192.168.100.180 3232 Ascyena
Sending Ascyena to 192.168.100.180:3232

Read more »

Revers Name Resolution Program code using java

PROGRAM NAME: REVERSE NAME RESOLUTION

In computer networkingreverse DNS lookup or reverse DNS resolution (rDNS) is the determination of a domain name that is associated with a given IP address using the Domain Name Service (DNS) of the Internet.

COMPLIED USING : JAVA JDK or NETBEANS IDE

CODE:



ReverseNameResolution.java

import java.net.*;
import java.util.Scanner;


class ReverseNameResolution {

    public static void main(String[] args) {

        System.out.println("Enter the IP address of the pc :-");
        Scanner in=new Scanner(System.in);
        String ip=in.nextLine();
        InetAddress inetAddress = null;
        // Get the host name given textual representation of the IP address
        try
        {
           inetAddress = InetAddress.getByName(ip);
           // Determines the IP address of a host, given the host's name.
        }
        catch (UnknownHostException e)
        {
            System.out.println("Unknown Host Exception");
            e.printStackTrace();
        }

        // The InetAddress object
        System.out.println("InetAddress object " + ip.toString());
        // Converts this IP address to a String.


        //  Gets the host name for this IP address.
        System.out.println( "Host name of " + ip + " is " + inetAddress.getHostName());

        // Gets the fully qualified domain name for this IP address.
        System.out.println("Canonical host name of " + ip + " is " + inetAddress.getCanonicalHostName());

    }

}


OUTPUT:



Enter the IP address of the pc :-
192.168.100.180
InetAddress object 192.168.100.180
Host name of 192.168.100.180 is I3-05
Canonical host name of 192.168.100.180 is I3-05
Read more »

Multiple inheritance Program Code in Java

The code Below implements the concept of multiple inheritance.The program takes Roll number of student as input using one class. Then Marks obtained in two subject .Later the marks are added together along with bonus marks and total is printed.The code is implemented using multiple inheritance concept in mind.
You can use JDK or Netbeans IDE to run below code.

                                                                     
CODE:                                                                     
                                                                     
                                             
package mulinheritance;
import java.io.*;
	class student
	{
      	int rn;
  	void getNumber(int n)
  	{
      	rn = n;
 	 }
  	void putNumber()
  	{
   	   System.out.println("Roll Number: " +rn);
  	}
	}

	class test extends student
	{
    	float pt1, pt2;
 	void getMarks(float m1, float m2)
 	{
     	pt1 = m1;
     	pt2 = m2;
	 }
 	void putMarks()
 	{
     	System.out.println("<Marks Obtained>");
     	System.out.println("sports: " +pt1);
     	System.out.println("computer: " +pt2);
 	}
	}
 	interface theory
 	{
     	float theory= 10.0F;
     	void putWt();
	 }

	class result extends test implements theory
	{
    	float total;
    	public void putWt()
   	 {
      	 System.out.println("practical score: " +theory);
    	}
    	void display()
    	{
        total = pt1+pt2+theory;
        putNumber();
        putMarks();
        putWt();
        System.out.println("Total score: " +total);
       }
	}
	public class mulinheritance {
   	 public static void main(String[] args)throws Exception {
        try
        {
        result stud1 = new result();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the roll number: ");
        int num = Integer.parseInt(bf.readLine());
        stud1.getNumber(num);
        System.out.println("Enter the marks in sports: ");
        int ma = Integer.parseInt(bf.readLine());
        System.out.println("Enter the marks in computer: ");
        int sc = Integer.parseInt(bf.readLine());
        stud1.getMarks(ma,sc);
        stud1.display();
        }
        catch(Exception e) { }
        
    }

}


OUTPUT:                                                            
                                             
	Enter the roll number: 
	23
	Enter the marks in sports: 
	56
	Enter the marks in computer: 
	67
	Roll Number: 23
	<Marks Obtained>
	sports: 56.0
	computer: 67.0
	practical score: 10.0
	Total score: 133.0




Read more »

Code For Validating Email String Number Html Forms using javascript

Validation is very important when we deal with anything processing on web. The data must be validated before it is entered into the database. Validation could be on server side as well as client side. We are going to focus on validation using java script on the client side.With The below code you can validate Names which is a string , Age which is a number and a email which has syntax such as email@email.com.
To run this code you just need a java script enabled browser to test.
copy the code and rename the file with .html extension.

Code:(Put it into text file and rename the file with .html extension)




<html>
<head>
<title>
Register Form
</title>
<style type="text/css">
h3{color:white;font-size:20pt;font-family:comicsansms}
.inset
{
border-width: 8px; border-style: inset; border-color: black;padding:20pt 
}
.margin{margin-left:100pt;margin-right:100pt}
a:link {color:pink;
            text-decoration:none;
       }


a:hover {
            color:peach;
            text-decoration:none;
}
table{line-height:0.5cm;letter-spacing:2px}
</style>


<script type="text/javascript">
function chkname()
{
var exp=RegExp(/^[A-Za-z]+$/);
var str=document.getElementById("name").value;
if(exp.test(str)==false)
{
alert("Name is either empty or invalid");
}
}
function chkemail()
{
var exp=RegExp(/^(\w*\.?\_?)+@\w+(\.[a-z])+/);
var str=document.getElementById("email").value;
if(exp.test(str)==false)
{
alert("email is either empty or invalid");
}
}


function filldob()
{
var month=new Array();
month=["January","February","March","April","May","June","July","August","September","October","November","December"];
for(i=0;i<month.length;i++)
{
var op1=document.createElement("OPTION");
op1.text=month[i];
op1.value=i;
document.getElementById("mth").options[i]=op1;
}
var dt=new Date();
for(i=0;i<31;i++)
{
var op1=document.createElement("OPTION");
op1.text=i+1;
op1.value=i+1;
document.getElementById("date").options[i]=op1;
}

for(i=0;i<60;i++)
{
var str=dt.getFullYear()-i;
var op1=document.createElement("OPTION");
op1.text=str;
op1.value=str;
document.getElementById("yr").options[i]=op1;
}
}






function calc_age()
{
var now=new Date();

var dat=document.getElementById("date").value;
var mnth=document.getElementById("mth").value;
var yrs=document.getElementById("yr").value;
var d1=parseInt(dat);
var mth=parseInt(mnth);
var yr=parseInt(yrs);
var dt=new Date(yr,mth,d1,00,00,00,00);
var str=now.getFullYear()-dt.getFullYear();
if(str>0&&(dt.getMonth()-now.getMonth())>=0&&(dt.getDate()-now.getMonth())>=0)
document.getElementById("age").value=str-1;
else
document.getElementById("age").value=str-1;
}
function chkfeb()
{
if(document.getElementById("mth").value==1)
{
for(i=28;i<31;i++)
{
document.getElementById("date").options[i].text="";
}
}
else
{
for(i=28;i<31;i++)
{
document.getElementById("date").options[i].text=i+1;
}
}
}
function chkmth()
{
if((document.getElementById("mth").value==3)||(document.getElementById("mth").value==5)||(document.getElementById("mth").value==8)||(document.getElementById("mth").value==10))
{
for(i=30;i<31;i++)
{
document.getElementById("date").options[i].text="";
}
}

}
</script>
</head>

<body style="background-color:orange"         onload="filldob();calc_age()">
<center>
                            <h3>>>>>>Fill In The  Details to Register<<<<</h3>
</center>
<br>


<form style=padding:auto;font-size:10pt onSubmit="chkname();chkemail()">
<div class="inset margin">
<table style="color:Black">
<tr>
<td>
Name:</td><td><input type="textbox" id="name"></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="add" id="addr"></textarea></td>
</tr>
<tr>
<td>D.O.B:</td>
<td><select id="date" onChange="calc_age()"></select>
<select id="mth" onChange="chkfeb();chkmth();calc_age()"></select>
<select id="yr" onChange="calc_age()"></select></td>
</tr>
<tr>
<td>Age:</td><td><input type="textbox" id="age"></td>
</tr>
<tr>
<td>Email ID:</td>
<td><input type="textbox" id="email"></td>
</tr>
<tr>
<td>Gender:</td>
<td><input type=radio>Male
<input type=radio>Female</td>
</tr>
<tr>
<td>Hobbies:</td>
<td><input type="checkbox" name="ch" value:"play">Playing
<input type="checkbox" name="ch" value:"dance">Dancing
<input type="checkbox" name="ch" value:"read">Reading</td>
</tr>
<tr>

<td><input type="submit" value="Submit">
<input type="submit" value="Reset"></td>

</tr>

</table>
</div>
</form>
<br>

</body>
</html>





OUTPUT:


Read more »