java programs

java programs

1:- java program to copy the contents of one file to another file(input the file names using command-line arguments).

2:- java program to perform insertion,updation,deltion and selection operation on the database.

3:-java program to find the repeated digits in a given number.

View Answers

October 28, 2010 at 11:50 AM

Hello Friend,

Try these codes:

1)

import java.io.*;

public class CopyFile {
    private static void copyfile(String srcfile,String destfile) {
        try {
            File f1 = new File(srcfile);
            File f2 = new File(destfile);
            InputStream in = new FileInputStream(f1);
            OutputStream out = new FileOutputStream(f2, true);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
            System.out.println("File copied.");
        } catch (Exception ex) {
            System.out.println(ex);
        }
    }

    public static void main(String[] args)throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Source File: ");
        String srcFile=reader.readLine();
        System.out.println("Desination File: ");
        String destFile=reader.readLine();

        copyfile(srcFile,destFile);
    }
}

2)

import java.sql.*;

class DatabaseOperations{
    public static void main(String[] args){
    try{
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
      Statement st = con.createStatement(); 
      String name="roseindia";
      String address="delhi";
      int i = st.executeUpdate("INSERT INTO data(name, address) VALUES ('"+name+"','"+address+"')");
      System.out.println("Data is inserted!");
      int j=st.executeUpdate("update data set name='rose' where id='1'");
      System.out.println("Data is updated!");
      ResultSet rs=st.executeQuery("select * from data");
      while(rs.next()){
      System.out.println(rs.getString("name")+"     "+rs.getString("address"));
      }
      int k=st.executeUpdate("delete from data where id='1'");
      System.out.println("One row is deleted!");
    }
    catch(Exception e){
        e.printStackTrace();
    }
    }
}

For the above code, we have created a table named 'data' in the database:

CREATE TABLE `data` (                                     
          `id` bigint(30) NOT NULL auto_increment,                
          `name` varchar(255) default NULL,                       
          `address` varchar(255) default NULL,                
          PRIMARY KEY  (`id`)                                     
        )

3)

import java.util.*;

class  CountRepeatedNumber {
  public static void main(String[] args) throws Exception{
  Scanner input=new Scanner(System.in);
 System.out.print("Enter number of multiple digits: ");
 long num=input.nextLong();
  String st=Long.toString(num);

  char[]third =st.toCharArray();
  for(int counter =0;counter<third.length;counter++){
  char ch= third[counter];
  int count=0;
  for ( int i=0; i<third.length; i++){
  if (ch==third[i])
  count++;
}
boolean flag=false;
for(int j=counter-1;j>=0;j--){
if(ch==third[j])
flag=true;
}
if(!flag){
if(count>1){
System.out.println("Number "+ch+" is repeated "+count+" times ");
}
}
}
}
}









Related Tutorials/Questions & Answers:
Programs in java
Programs in java  Hi, What are the best programs in java for a beginner? Thanks
java programs
java programs  Why word "static" is used in java programs
Advertisements
Java Programs
Java Programs  Hi, What is Java Programs? How to develop application for business in Java technology? Is there any tool to help Java programmer in development of Java Programs? Thanks
java programs
java programs  Explain types of Java programs. Also explain how to compile and run them.   Types of Java Programs: Standalone Applications Web Applications Enterprise Applications Console Application Web services
java programs
java programs  i need help in understanding the whole concept of the 13 java programs that i hav...here r de programs.. int i,j,m,n; m=Integer.parseInt(args [0]); n=Integer.parseInt(args [1]); System.out.print
programs in java
programs in java  . I need an application for managing an educational institute. That application should provide the details of Students Courses Faculty Fee details etc.., pl z guide me how to write these programe
java programs
java programs  A union B, transpose of matric, denomination of a given number i need java programs for this category?   Hi Friend, Transpose of matrix: import java.util.*; public class Transpose { public
java programs
java programs  write java applet program to display an image using drawimage method of an java graphic class
java programs
java programs  55555 54444 54333 54322 54321
java programs
java programs  problems 1 21 312 4123 51234
java programs
java programs  1.define frame? 2.what is the need for java programming? 3.list the events of classes? 4.define Event handling? 5.List event listener interface
java programs
java programs  please help in this series .. 55555 55554 55543 55432 54321
java programs
java programs  1:- java program to copy the contents of one file to another file(input the file names using command-line arguments). 2:- java.... 3:-java program to find the repeated digits in a given number.ADS_TO_REPLACE_1
Java Programs
Java Programs  Hello. I need help with the following. Write a program that prompts the user for 2 different integers, then prints out the numbers between the 2 integers (inclusive) and their squares and the sum
Explain types of java programs
Explain types of java programs  Explain types of java programs   Types of Java Programs: Standalone Applications Web Applications Enterprise Applications Console Application Web services
how to execuite java programs???
how to execuite java programs???  I have jdk 1.6 installed in my pc.i want to execuite java programs in ms-dos for applet and without using applet.please tell me
how to execuite java programs???
how to execuite java programs???  I have jdk 1.6 installed in my pc.i want to execuite java programs in ms-dos for applet and without using applet.please tell me
programs
programs  give some programs on control statementds
Java programs - Java Beginners
Java programs  Hello Please write the following programs for me using GUI.Thanks You. 1. Write a java program that reads the first name, last name, hours worked and hourly rate for an employee. Then print the name
Java programs - Java Beginners
Java programs  Could you please write the followong programs for me.. Thanks in advance 1)1. write a program that reads a string composed of 12 characters then splits it into 4 different strings each composed of three
Java programs on students assesment
Java programs on students assesment  1) Write a Java program that reads the details of student and do the mark assessments. (i) Input the name of the student and student id from the user. (Use String variable to hold the student
3 Java Programs for Beginners
3 Java Programs for Beginners  Write a program that prompts the user for 2 different integers, then prints out the numbers between the 2 integers (inclusive) and their squares and the sum of their squares. Write a program
Java Programs - Java Beginners
Java Programs  Dear Sir, Could you give me the syntax for HIERARCHIAL INHERITANCE and give sample program for the same?(if possible with an output...://www.roseindia.net/java/language/inheritance.shtml Thanks
java programs - Java Beginners
java programs  take one file as a input exam.txt under this file 1,2,3,4,5 6,7,8,9,10 11,12,13,14,15 and give output in new file as result.txt under this file 1,6,11 2,7,12 3,8,13 4,9,14 5,10,15
java programs - Java Beginners
java programs  a coin is tossed for three sets of times i.e 10,100,1000.write to print how many times the head and tail occurs in each sets of toss and total number of head nand tail occured at the end.use method call
java programs - Java Beginners
java programs  i need a program for rational numbers to represent 500/1000 as 1/2 in java using java doc comments  Hi Friend, Try... rationalNumber(int p, int q) { if (q==0){ return p
java programs - Java Beginners
java programs  1) write a program to print prime numbers? 2) write a program to print factorial of given number? 3)Please provide complete material..., visit the following link: http://www.roseindia.net/java/java-get-example/ascii
java programs - Java Beginners
java programs  lisp-like list in java to perform basic operations such as car, cdr ,cons  Hi Friend, Try the following code: import java.util.*; class Lisp { public int car(List l){ Object ob=l.get(0
java programs - Java Beginners
java programs   design a vehicle class hierachy in java.write a program to demonstrate polymorphism  Hi Friend, Try the following code: class Vehicle { void test(){} } class Bus extends Vehicle{ void test
java programs - Java Beginners
java programs   I am trying to write a program that prompts the user to enter the month and year and displays the number of days in the month. Need help  Hi Friend, Try the following code: import java.util.
java programs - Java Beginners
java programs  Actually i am searching for the source code ,algorithm and flow chart for prime number ...can u suggest me where can i find it???  Hi Friend, Try the following code: import java.util.*; class
java programs - Java Beginners
java programs  design a java interface for adt stack .develop two different classes that implement the interface one using array and another using linkedlist  Hi Friend, Try the following code: import java.lang.
java programs - Java Beginners
java programs  write a program to enter name of book,author's name,year of publication,and price of any 10 different books in respective arrays.then input an auther name and print all the details such as name of book ,auther's
programs - Java Beginners
Program Java in Linux  How to program Java in Linux system
programs - Java Beginners
. (by using methods of minimum and maximum of numbers) 3. Write a Java program to demonstrate inheritance. 4. Write a Java program to demonstrate dynamic polymorphism. 5. Write a Java program to implement the following hierarchy
programs - Java Beginners
. (by using methods of minimum and maximum of numbers) 3. Write a Java program to demonstrate inheritance. 4. Write a Java program to demonstrate dynamic polymorphism. 5. Write a Java program to implement the following hierarchy
programs - Java Beginners
Java Array Programs  How to create an array program in Java?  Hi public class OneDArray { public static void main (String[]args){ int... information.http://www.roseindia.net/java/beginners/arrayexamples/java_array_usage.shtmlamar.
Abstract programs - Java Beginners
. http://www.roseindia.net/java/master-java/abstract-class.shtml Thanks
programs - Java Beginners
double array in java  Please give me an example of double array in java.  Hi friend public class TwoDArray { public static void main(String[] args){ int[][] twoD = new int[8][4]; for (int i=0; i<twoD.length; i
java mail programs
java mail programs  I got some codes from this about sending mail,forwarding mail,multipart mail etc..and I compiled and executed it,but it did not show any output,IDE(netbeans) showed "build successful" and no more
programs - Java Beginners
three dimensional array programs  Example of three dimensional array program in Java.  Hi friend public class ThreeDArray { public static void main(String[] args) { int[][][] threeD = new int[5][4][3]; for (int i
programs - Java Magazine
: http://www.roseindia.net/java/example/java/applet/ Thanks Amardeep
Installing programs over a network using java
Installing programs over a network using java  Hi, i want to write a java program that will allow me to install programs from a server to a client machine. Any help will be appreciated. Thanks
Java Programs
In this section of RoseIndia we are providing several Java programs... a huge collection of Java programs and examples covering almost all topics. Every... Java programs. Various example like get host name, retrieve month and date
Java programs for beginners
RoseIndia provides a long list of Java programs for beginners that too... prepared these java programs describing every logic and method behind... learning Java. From simple programs to complex programs, all are provided
what programs are needed in java programming? - Java Beginners
what programs are needed in java programming?  What programs are needed in java programming?   Hi friend, For solving the problem visit to : http://www.roseindia.net/java/] Thanks  Hi friend
java lab programs - Java Beginners
java lab programs  Develop with suitable hierarchy, classes for Point, Shape, Rectangle, Square, Circle, Ellipse, Triangle, Polygon, etc. Design a simple test application to demonstrate dynamic polymorphism. 5. Design a Java
Programs in java - Java Interview Questions
Program in Java decimal to binary  i need a java example to String Reverse. Can you also explain the Java decimal to binary with the help.../java/example/java/util/CapturedText.shtml
java lab programs - Java Beginners
java lab programs  1. Develop a Java package with simple Stack... for Complex numbers in Java. In addition to methods for basic operations on complex... to demonstrate dynamic polymorphism. 5. Design a Java interface for ADT Stack. Develop two
writing java programs - Java Beginners
writing java programs  How do i write a code to display even numbers from 1 to 50  Hi Friend, Try the following code: class EvenNumbers{ public static void main (String args[]){ String evenNo

Ads