/* Function Overloading program in java. The program overloads the area() function and calculates the area for square, rectangle and triangle */
class overloading
{
double area,root;
//Area Of Square
public void Area(double a)
{
area = a*a;
System.out.println("The Area Of Square : " +area);
}
// Area of rectangle
public void Area(double a,double b)
{
area= a*b;
System.out.println("The Area Of Rectangle : " +area);
}
// Aera Of Triangle
public void Area(double a,double b,double c)
{
double s= (a+b+c);
root = s*(s-a)*(s-b)*(s-c);
area = Math.sqrt(root);
System.out.println("The Area Of Triangle : " +area);
}
public static void main(String args[])
{
overloading ar = new overloading();
ar.Area(5.65);
ar.Area(5.32,43.2);
ar.Area(4,7,7);
}
}
/* Output
The Area Of Square : 31.922500000000003
The Area Of Rectangle : 229.82400000000004
The Area Of Triangle : 174.61958653026298 */
Labels: Core Java
/* Simple Type casting program */
class cast
{
public static void main(String args[])
{
double a=5.35, b=55.6;
int rem;
rem = (int)a% (int)b;
System.out.println("Remainder : "+rem);
}
}
/* Output
Remainder : 5 */
Labels: Core Java
Today we have come to the point where our life would be impossible without computers. We do not even care to think how we will live without our lap-top or mobile phone which has build-in programs for searching the Net or creating text documents or just listening to mp3 files. We all got accustomed to the Internet and E-mail which help to connect with our friends for different countries. And if your website tends to be a unique presentation of the company it should definitely use the technology feature such as phpfox that lets you customize the design and additional features available to the visitors.
But how can we use all these devices. The answer is obvious. People create different software to suit every device. Also there can be offered the services of custom software development that might include jdbc drivers for Java-applications which give an opportunity to adapt to the needs of particular companies which are going to use this kind of software or device.
Alongside with software development many companies use Internet for their business. In this case it is advisable to order an outstanding Web design of your resource. Today there is no problem with that. For example, your company is situated it Chicago. So you can order Chicago web design just round the corner which is definitely great for corrective feedback. So you can see that computer technologies are practically irreplaceable in our life
Labels: Websites
Program in java for inserting, recording, deleting, editing and searching student details stored in the SQL database.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
class studentdetails
{
Statement stmt;
String strSql;
Connection con;
BufferedReader bufferObj;
studentdetails (){
bufferObj=new BufferedReader(new InputStreamReader(System.in));
}
void establishConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex)
{
System.out.println(ex);
}
try
{
String url="jdbc:odbc:new_dsn";
con=DriverManager.getConnection(url,"sa","");
stmt=con.createStatement();
}
catch(SQLException ce)
{
System.out.println("Error... "+ce);
}
}
void add()
{
try
{
System.out.println("\nEnter Roll Number: ");
String rollno=bufferObj.readLine();
System.out.println("\nEnter Students Name: ");
String name=bufferObj.readLine();
System.out.println("\nEnter Course Name");
String course=bufferObj.readLine();
strSql="Insert into Student values(" +rollno+",'"+name+"',' "+course+" ')";
stmt.executeUpdate(strSql);
System.out.println("\nRecords Successfully Added!");
System.out.println();
}
catch(SQLException ce)
{
System.out.println("Error... "+ce);
}
catch(Exception e)
{
System.out.println(e);
}
}
void update()
{
try
{
System.out.println("\nEnter Roll Number whose "+"record should be updated: ");
String roll=bufferObj.readLine();
System.out.println("Enter Students Name to be Modified: ");
String name=bufferObj.readLine();
System.out.println("Enter course name to be modified: ");
String course=bufferObj.readLine();
strSql="update Student set name=' "+name+" ',course='"+course+"' where rollno='"+roll+"'";
stmt.executeUpdate(strSql);
System.out.println("\nRecord Successfully Modified !");
System.out.println();
}
catch(SQLException ioe)
{
System.out.println(ioe);
}
catch(Exception er)
{
System.out.println(er);
}
}
void delete()
{
try
{
System.out.println("Enter Students Name to be Deleted :") ;
String name=bufferObj.readLine();
strSql="Delete from Student where rtrim(name) like '"+name+ "'";
stmt.executeUpdate(strSql);
System.out.println("Record Successfully Deleted !");
System.out.println();
}
catch(SQLException et)
{
System.out.println("Error in Deletion.... "+et);
}
catch(Exception ty)
{
System.out.println("Error.... "+ty);
}
}
void search()
{
try
{
System.out.println("Enter Roll Number "+"whose record should be searched: ");
int roll=Integer.parseInt(bufferObj.readLine());
System.out.println("Enter Students Name to be Searched");
String name=bufferObj.readLine();
strSql="select * from student where name like'"+name;
strSql=strSql+"' and Rollno="+roll;
ResultSet rs=stmt.executeQuery(strSql);
if(!rs.next())
{
System.out.println("Name");
System.out.println(rs.getString(1)+"\t");
System.out.println("Roll Number");
System.out.println(rs.getInt(2)+"\t");
System.out.println("Course");
System.out.println(rs.getString(3)+"\n");
}
}
catch(SQLException er)
{
System.out.println(er);
}
catch(Exception t)
{
System.out.println(t);
}
}
public void menudisplay() throws IOException
{
char choice;
while(true)
{
System.out.println();
System.out.println("1. Add a Record");
System.out.println("2. Modify Record");
System.out.println("3. Delete a Record");
System.out.println("4. Search a Record");
System.out.println("5. Exit");
System.out.println("Enter your choice....:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
choice=(char) br.read();
switch(choice)
{
case '1' :
System.out.println("Adding a Record........");
add();
break;
case '2' :
System.out.println("Updating a Record........");
update();
break;
case '3' :
System.out.println("Deleting a Record........");
delete();
break;
case '4' :
System.out.println("Searching a Record........");
search();
break;
case '5' :
System.exit(0);
break;
default :
System.out.println("Adding a Record........");
add();
break;
}
}
}
}
class student
{
public static void main(String[] args) throws IOException
{
studentdetails stud = new studentdetails();
stud.establishConnection();
stud.menudisplay();
}
}
Labels: Advanced Java, Networking
keyword - a word whose meaning is defined by the programming language
true and false aren't in fact keywords, they are literal boolean values
goto and const are reserved words
identifier - is a word used by a programmer to name a variable, method, class or label. Must begin with a letter, a dollar sign or underscore
Java's four signed integral data types are: byte, short, int, long
Double and float can take on values that are bit patterns that do not represent numbers
Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY.. the same with Double
A literal is a value specified in the program source, they cannot appear on the left side of assignments.
A Java array is an ordered collection of primitives, object references or other arrays, all elements must be of the same type. To create and use an array you must follow three steps: Declaration, Construction, Ininialization. 1. int[] integers, 2. integers = new int[20]
Java array is starting with index 0.
A common mistake is to guess that importing has something to do with class loading. The fact is, that the name is brought into the source file's namespace.
import static java.awt.Color.RED; ... myColor = RED; ... Static imports eliminate the nuisance of constant interfaces.
import static measure.Scales.kilometersToMiles();
Member variable - is created when the instance is created, and exists as long the enclosing object exists. Automatic variable - is created on entry to the method. Class variable - (aka. static variable) is created when the class is loaded and is destroyed when the class is unloaded. Initial value is assigned to member variables, static variables, but not automatic variables.
When java passes an argument into a method call, a copy of the argument is actually passed.
Each process has its own stack and heap. Objects are always allocated on the heap.
Explicitly assign null into a variable when you have finished with it.
When the garbage collector finds memory that is no longer accessible from any live thread it takes steps to release it back into the heap for re-use. Class destructor method is called finalize().
It is not possible to force the garbage collection.
Importing slightly increases compilation time.
In Java all arguments are passed by value.

Do you have a need to stay on top of things? Are you planning for private school, college, grad school, continuing education or a vocational program and finding it really difficult?
The My Petersons is the site for you. Search and save your list of schools. Find out about the kind of financial aid you need to pay for your education. Learn everything you need to know about admission tests. It's the easiest way to stay organized and, best of all, it’s free!
Distance Learning Search
Distance learning and online degrees make the world your classroom! Now from the comfort of your own home, you can easily receive a degree from a traditional accredited college online and earn a certificate award, bachelors, masters, or doctorate degree or complete your degree via the Internet. Browse a wide variety of online degree programs and locate the one that's best for you. Find opportunities by selecting the distance learning courses or online courses that spark your interest, the degree level of your choice, and your campus requirements. It's that easy!
Labels: Websites
/* Java Program that implements data connectivity */
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Test extends JFrame implements ActionListener
{
Container con;
JLabel l1;
JLabel l2;
JLabel l3;
JLabel l4;
JLabel l5;
JTextField lt1;
JTextField lt2;
JTextField lt3;
JTextField lt4;
JTextField lt5;
JButton lb1;
Connection con1;
Statement s;
ResultSet rs;
public Test()
{
super("student details!!!");
con=getContentPane();
con.setLayout(null);
l1=new JLabel("Roll no.");
l1.setBounds(50,10,250,75);
con.add(l1);
l2=new JLabel("Name");
l2.setBounds(50,30,250,75);
con.add(l2);
l3=new JLabel("Age");
l3.setBounds(50,50,250,75);
con.add(l3);
l4=new JLabel("Address");
l4.setBounds(50,70,250,75);
con.add(l4);
l5=new JLabel("Marks");
l5.setBounds(50,90,250,75);
con.add(l5);
lt1=new JTextField(10);
lt1.setBounds(115,35,100,15);
con.add(lt1);
lt2=new JTextField(20);
lt2.setBounds(115,60,100,15);
con.add(lt2);
lt3=new JTextField(30);
lt3.setBounds(115,80,100,15);
con.add(lt3);
lt4=new JTextField(40);
lt4.setBounds(115,103,100,15);
con.add(lt4);
lt5=new JTextField(50);
lt5.setBounds(115,127,100,15);
con.add(lt5);
lb1=new JButton("GO");
lb1.setBounds(250,30,100,50);
con.add(lb1);
lb1.addActionListener(this);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con1=DriverManager.getConnection("jdbc:odbc:mydsn","sa","");
s=con1.createStatement();
}
catch(SQLException e)
{
System.out.println(e.toString());
}
catch(ClassNotFoundException e)
{
System.out.println(e.toString());
}
}
public void actionPerformed(ActionEvent e)
{
/*int m=Integer.parseInt(lt1.getText());
String n=lt2.getText();
int o=Integer.parseInt(lt3.getText());
String p=lt4.getText();
int q=Integer.parseInt(lt5.getText());*/
String str="select *from student_det1 where roll_no='"+lt1.getText()+ "'";
System.out.println(str);
try
{
rs=s.executeQuery(str);
while(rs.next())
{
lt2.setText(rs.getString(2));
lt3.setText(rs.getString(3));
lt4.setText(rs.getString(4));
lt5.setText(rs.getString(5));
}
}
catch(SQLException ee)
{
System.out.println(ee.toString());
}
}
public static void main(String args[])
{
Test t=new Test();
t.setSize(500,600);
t.setVisible(true);
}
}
Labels: Advanced Java, Frames
Blogsvertise is set up for bloggers to earn revenue from their blogs. Firstly you need to submit your blog to them for approval and once your blog is approved it goes into assignment queue, then the Blogsvertise administrator assigns tasks ( writing posts) for what their advertisers want you to mention in your blog. You dont have to endorse the website product/service, just mention it in your blog and add 3 links to the advertiser website in your entry.Labels: Websites
Loading the Applet
When an applet is loaded, here's what happens:
* An instance of the applet's controlling class (an Applet subclass) is created.
* The applet initializes itself.
* The applet starts running.
Leaving and Returning to the Applet's Page
When the user leaves the page -- for example, to go to another page -- the applet has the option of stopping itself. When the user returns to the page, the applet can start itself again. The same sequence occurs when the user iconifies and then reopens the window that contains the applet. (Other terms used instead of iconify are minaturize, minimize, and close.)
Some browsers let the user reload applets, which consists of unloading the applet and then loading it again. Before an applet is unloaded, it's given the chance to stop itself and then to perform a final cleanup, so that the applet can release any resources it holds. After that, the applet is unloaded and then loaded again.
Quitting the Browser
When the user quits the browser (or whatever application is displaying the applet), the applet has the chance to stop itself and do final cleanup before the browser exits.
An applet can react to major events in the following ways:
1. It can initialize itself.
2. It can start running.
3. It can stop running.
4. It can perform a final cleanup, in preparation for being unloaded.
import java.net.*;
class Gotest
{
public static void main(String agrs[]) throws MalformedURLException
{
URL hp = new URL("http://www.javapgms.blogspot.com/Array.html");
System.out.println("Protocol : " +hp.getProtocol());
System.out.println("Port : " +hp.getHost());
System.out.println("Host : " + hp.getHost());
System.out.println("File : " +hp.getFile());
}
}
/*
getProtocol() : Returns the protocal identifier of the given URL object.
getPort() : Returns the integer value of the port number of the URL Object. If the port is not set the it returns -1.
getHost() : Returns The Host Name.
getFile() : Returns The file Name.
getRef() : Returns The reference component
Labels: Advanced Java, Networking