A kind of multiarray in Java

I want to use a kind of multiarray;
I need to create sometrhing like this : array[String][int] and I want to be ale to use like in exemple:
array[String1][1] = "Jony";
So something like this:
array[String][int]= String;

private TreeMap <String, String[]> tm = new TreeMap();
for (i=0....) // for function
for....
here I create an array where I putt al the param name
tm.put(numaFfunction, parameterNameEqualXML2);
now for print all my function with all parameters name I obtain the result just for the last one (becaus of for)
to obtain all I think I must use an Iterator... but I don't know exacly how
thanks

Similar Messages

  • Getch() kind of functionality in java

    Hi all,
    i wanted
    "char getch()"
    kind of functionality that exists in C/C++ on java, can anyone help
    System.in.read() does'nt read until enter(return) key is pressed.
    I cant use java.io.BufferedReaders etc as I am working on the oldest of all old jdk compilers (jdk1.0.2 !!!!!!!!!!!)
    Please help
    Sunil

    There isn't.
    Kind regards,
      Levi

  • Kind of New to Java

    Well i'm still on my quest to learn java and so for yet another test of my skills thus far, I came up with this program. The only thing that is left is that I can't get my program to take the diameter and color the user enters and draw a circle with it!?! Haha its driving me crazy!? Can anyone help?? Here is my code down below
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import javax.swing.*;
    public class CircleGUI implements ActionListener
    JLabel diameterLabel = new JLabel("Diameter");
    JLabel colorLabel = new JLabel("Color");
    JTextField diameterField = new JTextField(4); //text field for firstname
    JTextField colorField = new JTextField(10); //text field for lastname
    JTextArea bothArea = new JTextArea(15,30); //text area for bothnames
    JButton button1 = new JButton("Draw");
    JPanel panel = new JPanel();
    JFrame frame = new JFrame("Address"); //frame for window
    public CircleGUI()
    panel.add(diameterLabel);
    panel.add(diameterField); //add text field to panel
    panel.add(colorLabel);
    panel.add(colorField);
    panel.add(bothArea);
    button1.addActionListener(this); //add a click listener tobutton
    panel.add(button1); //add another label to panel
    frame.setContentPane(panel); //set panel as frame's content
    frame.setSize(200, 200); //set frame size (width,height)
    frame.setVisible(true); //make frame visible
    }//end FrameExample()
    public void actionPerformed(ActionEvent e)
    if (e.getSource().equals("draw")) {
    String command = e.getActionCommand();
    String a = diameterField.getText();
    String b = colorField.getText();
    lblOutput.setText(drawCircle(diameterField.getText(),colorField.getText()));
    }//end actionPerformed()
    }//end FrameExample

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CGUI implements ActionListener
        JTextField diameterField;
        JComboBox colorCombo;
        GraphicPanel graphicPanel;
        Color[] colors;
        public CGUI()
            colors = new Color[]
                Color.black, Color.red, Color.green.darker(), Color.blue
            // initialize components
            graphicPanel = new GraphicPanel();
            diameterField = new JTextField(4);
            String[] colorNames = { "black", "red", "green", "blue" };
            colorCombo = new JComboBox(colorNames);
            JButton button1 = new JButton("Draw");
            button1.addActionListener(this);
            // assemble components
            // north section
            JPanel panel = new JPanel();
            panel.add(new JLabel("Diameter"));
            panel.add(diameterField);
            panel.add(new JLabel("Color"));
            panel.add(colorCombo);
            // south section
            JPanel southPanel = new JPanel();
            southPanel.add(button1);
            // create, configure and load components
            // into top-level container
            JFrame frame = new JFrame(getClass().getName());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(panel, "North");
            frame.getContentPane().add(graphicPanel);
            frame.getContentPane().add(southPanel, "South");
            frame.setSize(400,400);
            frame.setLocation(200,200);
            frame.setVisible(true);
        public void actionPerformed(ActionEvent e)
            JButton button = (JButton)e.getSource();
            String command = button.getActionCommand();
            if (command.equalsIgnoreCase("draw"))
                String a = diameterField.getText();
                if(a.equals("")) return;
                int diameter = Integer.parseInt(a);
                Color color = colors[colorCombo.getSelectedIndex()];
                graphicPanel.setColor(color);
                graphicPanel.setDiameter(diameter);
        public static void main(String[] args)
             new CGUI();
    class GraphicPanel extends JPanel
        int diameter;
        Color color;
        public GraphicPanel()
            diameter = 100;
            color = Color.black;
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);       
            int w = getWidth();
            int h = getHeight();
            int x = w/2 - diameter/2;  // center it
            int y = h/2 - diameter/2;
            g2.setPaint(color);
            g2.drawOval(x, y, diameter, diameter);
        public void setDiameter(int diam)
            diameter = diam;
            repaint();
        public void setColor(Color color)
            this.color = color;
            repaint();
    }

  • How to run a Java program without the command line.

    Is there anyway to create a Java program that runs like most programs do in Windows ,by double clicking on their icons?
    Thanks,
    Vance

    http://www.ej-technologies.com/products/exe4j/overview.html
    Looks kinda cool. Most java-2-exe programs are usually way too expensive and wont work with GUIs and require other dlls/libraries...

  • Java Progrramming HELP, Needed Urgently, T hanks

    hey guys,
    I have this lab I need to be done tomorrow, its been weeks lol of thinking and figuring things out can someone make it work ? Pleaseeeee !
    I feel like going out and yelling for help lol I have been trying to figure this out for weeks now.
    I am pasting my Lab and My Codes I did so far, And Please I really need this done today at any rate, all help would be kindly appreciated.
    A Java program is required that will produce a number of reports based on the data from the Product file. This file contains the product name, cost, quantity and UPC. The file name must be input. Valid data from the file will be loaded into an array.
    A menu will provide the following options: (Note there are changes from previous assignment.)
    1     Display of all valid product information including extended price and GST including totals sorted by name.
    2     Display of all invalid records sorted by name.
    3     Search and display a certain product by name.
    4     Sort by UPC and use a binary search and display a certain product by UPC. (valid records)
    9 Exit.
    Processing requirements:
    Input the data from a file and load the records into an object array. Use this object array to produce the above reports.
    Code a class definition exactly as given in the following UML.
    (For specific students: you may code the UPC as an integer but if not numeric throw an exception that is handled in main. Document your choice in your submission).
    Product
    ? Name : String
    ? UPC : String
    ? Cost : Real
    ? Quantity : Integer
    + Product (Name : String, UPC : String, Cost : Real, Quantity : Integer)
    + Calculate Extended Cost() : Real
    + Calculate GST(): Real
    Input Record:
    Product name: String
    UPC: String
    Cost: real
    Quantity: integer
    Output Reports
    1. Display of all product information including extended cost and GST including totals of these 3 fields.
    Following is a sample of the output required:
    ************************ Product Cost REPORT ****************************
    Product                    Cost Quantity Extended Cost     GST     Total Cost
    Diamond Necklace 12345678901x 54,321.99 188 10,212,534.12 510,626.71 10,723,160.83
    Tissues 98989898989x 1.99 2 3.98      0.20     4.18
    TOTALS                         10,212,538.10 510,626.91 10,723,165.01
    2. Display of all invalid records and the count.
    Following is a sample of the output required:
    Invalid UPC Records = 1
    Count Record
    1          Tiara Diamond, 12345678901x, 36020.00, 2
    3. Search and display a certain product by name. Display appropriate message if not found.
    Following is a sample of the output required:
    Enter product name: CrownJewels
    CrownJewels 99999999991x     100,000.00 1 100,000.00 5,000.00 $105,000.00
    6. Display the product information sorted by name
    Following is a sample of the output required:
    ************************ Product Cost REPORT ****************************
    Product                    Cost Quantity Extended Cost     GST     Total Cost
    CrownJewels 99999999991x 100,000.00 1 100,000.00 5,000.00 $105,000.00
    Diamond Necklace 12345678901x 54,321.99 188 10,212,534.12 510,626.71 $10,723,160.83
    Pearls      88888888881x 10,000.00 1 10,000.00 500.00 $10,500.00
    RubyRing      77777777771x 10,000.00 1 10,000.00 500.00 $10,500.00
    Tissues      98989898989x 1.99 2 3.98 0.20     $4.18
    TOTALS          (complete these values)           xxx           xxx      xxx
    Java coding requirements for this assignment
    Main methods required
    1.     Load array with all records. Display exception messages only for records that have invalid data in any of the fields. Return array of valid records and logical size.
    2.     Validate the UPC. Display each report when requested from the menu.
    3.     Justify the data in the columns. Right justify numeric fields; left justify the alpha fields.
    4.     A method for each report required in the menu.
    Class methods
    5.     Use the object method for the extended cost.
    6.     Use the object method for the GST.
    You may use additional methods in the main program but do not add any methods in the class definition.
    Use DecimalFormat for rounding.
    Create an array to hold the objects. Assume that we only need to process a file of a maximum of 500 records but the file may be larger than 500 records.
    A Universal Product Code consists of 12 digits. The first digit (from the left) is the UPC type. The next five digits are the Manufacturer code. The next five digits are the product code which is assigned by the manufacturer. The final digit is the check digit. A person can determine the check digit of a Universal Product Code by doing the following:
    Step 1: Sum all of the digits in the odd positions together.
    0+4+0+1+5+9 = 19
    Step 2: Multiply the sum from Step 1 by 3.
    3 * 19 = 57
    Step 3: Sum all of the digits in the even positions together.
    6+2+0+1+8 = 17
    Step 4: Sum together the results from Step 2 and Step 3.
    17 + 57 = 74
    Step 5: Subtract the sum from the next highest multiple of 10.
    80 - 74 = 6 [check digit]
    TEST DATA:
    Step 1: Create 5 or MORE additional records that will test all conditions. Include these in your documentation. Identify what field is tested in your test data. (Example: error in each field of the record, rounding up, rounding down, valid UPC, invalid UPC, formatting of report, file too large
    Step 2: Use the file attached.
    GODDDDDDDDDDDDDD lol pasting it made me go crazy,
    these are my codes so far, HOwever the problem is ONLY DISPLAY MENU SHOWS, nothing else even though i have enough codes that it can show something,
    My codes are as follows:
    I am working on Eclipse.
    import java.util.Arrays;
    import java.util.Scanner;
    import java.io.*;
    import java.util.*;
    import java.io.IOException;
    * Name : Sana Ghani
    * Date : July 10
    public class lab56
         public static Scanner file;
         public static Scanner parse;
         public static Scanner input = new Scanner(System.in);
         public static Scanner searchInput = new Scanner(System.in);
         public static void main(String[] args) throws Exception
              Product1[] validProduct = new Product1[500];
              int logicalSize = 0;
              int menuChoice=0;
              String FileName = getFileName();
              displayMenu();
              switch(menuChoice)
              case 1:
                   displayAllValidRecords(validProduct, logicalSize);
                   try
                   // Open an output stream
                   OutputStream fout = new FileOutputStream ("myfile.txt");
                   // Print a line of text
                   new PrintStream(fout).println ("hello world!");
                   // Close our output stream
                   fout.close();          
                   // Catches any error conditions
                   catch (IOException e)
                        System.err.println ("Unable to write to file");
                        System.exit(-1);
                   break;
              case 2:
                   break;
              case 3:
                   binarySearchByName( validProduct,logicalSize);
                   break;
              case 4:
                   break;
              case 5:
                   break;
              menuChoice = displayMenu();
         public static void display(Product1[]validProduct, int logicalSize)throws Exception
              String Product, UPC;
              double Cost;
              int Quantity;
              for(int index =0; index<logicalSize; index++)
                   Product = validProduct[index].GetName();
                   UPC = validProduct[index].GetUPC();
                   Cost=validProduct[index].GetCost();
                   Quantity=validProduct[index].GetQuantity();
                   System.out.println(Product+"\t\t"+UPC+"\t\t"+Cost+"\t\t"+Quantity);
         public static String getFileName()
              String fileName;
              Scanner input = new Scanner(System.in);
              System.out.print("Please enter a file name: ");
              fileName = input.next();
              return fileName;
         public static int displayMenu()
              int menuChoice;
              boolean validFlag = false;
              do
                   System.out.println("\n\n*************************************");
                   System.out.println(" Product Display Menu ");
                   System.out.println("*************************************");
                   System.out.println("(1)Display All Records");
                   System.out.println("(2)Display All Invalid Records");
                   System.out.println("(3)Search by Product Name");
                   System.out.println("(4)Sort by Product Name");
                   System.out.println("(5)Exit");
                   System.out.println("*************************************");
                   System.out.print("Enter your choice(1-5): ");
                   menuChoice = input.nextInt();
                   if ((menuChoice >= 1) && (menuChoice <= 5))
                        validFlag = true;
                   if (!validFlag)
                        System.out.println("You have chosen " + menuChoice + ", " + menuChoice +
                        " is not valid. Please try again");
              }while(!validFlag);
              return menuChoice;
         public static String loadArray(Product1 [] ValidProduct, String fileName)throws Exception
              int logicalSize=0;//will always have to declare
              String record;//will always have to declare
              String Product, UPC;//variable names from
              double Quantity;
              double Cost;
              Scanner file = new Scanner(new File(fileName));//open
              record = file.nextLine();//read a line
              record = file.nextLine();//read a line
              for(int index = 0; index < ValidProduct.length && file.hasNext(); index++)//check to see if the file has data
                   record = file.nextLine();
                   parse = new Scanner(record).useDelimiter(",");
                   String Name = parse.next();
                   UPC = parse.next();
                   Cost = parse.nextDouble();
                   Quantity=parse.nextDouble();
                   ValidProduct[index] = new Product1 ( Name, UPC, Cost, (int) Quantity);
    //               create the object-- call the constructor and pass info
                   logicalSize++;
              return logicalSize+".txt";
         public static double roundDouble(double value, int position)
              java.math.BigDecimal bd = new java.math.BigDecimal(value);
              bd = bd.setScale(position,java.math.BigDecimal.ROUND_UP);
              return bd.doubleValue();
         * This method will print report about valid records
         public static void displayAllRecords( Product1[]valid, int ValidProduct,
                   Product1[] invalid, int InvalidProduct)
    //          Print valid records
              displayAllValidRecords(valid, ValidProduct);
    //          Print invalid UPC records
              displayAllValidRecords(invalid, InvalidProduct);
         public static void displayOneRecord(Product1[]valid, int index)
              double extendedCost, GST, SumofGST = 0, // Total Extended Cost
              totalCost, SumOfTotalCost = 0; // Total Extended Cost + GST
    //          Print title
              System.out.println(leftJustify("Product", 50) +
                        leftJustify("UPC", 15) +
                        rightJustify("Cost", 10) +
                        rightJustify("Quantity", 5) +
                        rightJustify("Extended Cost", 15) +
                        rightJustify("GST", 5) +
                        rightJustify("Total Cost", 13));
              extendedCost = valid[index].CalculateExtendedCost();
              extendedCost = roundDouble(extendedCost, 2);
              GST = valid[index].CalculateGST();
              GST = roundDouble(GST, 2);
              totalCost = extendedCost + GST;
              totalCost = roundDouble(totalCost, 2);
    //          justify method ensures all values are of the same size
              System.out.println(//leftJustify(i+"",3) + ": " +
                        leftJustify(valid[index].GetName(), 50) +
                        leftJustify(valid[index].GetUPC(), 15) +
                        rightJustify(valid[index].GetCost()+"", 10) +
                        rightJustify(valid[index].GetQuantity()+"", 5) +
                        rightJustify(extendedCost+"", 10) +
                        rightJustify(GST+"", 10) +
                        rightJustify(totalCost+"", 10));
         * This method will print report about valid records
         public static void displayAllValidRecords( Product1[]valid, int validCounter)
              double extendedCost, sumOfExtendedCost = 0, // Total Extended Cost
              GST, sumOfGST = 0, // Total GST
              totalCost, sumOfTotalCost = 0; // Total Extended Cost + GST
              System.out.println("************************ XYZ Product " +
                        "Cost REPORT ****************************" +
    //          Print title
              System.out.println(leftJustify("Product", 50) +
                        leftJustify("UPC", 15) +
                        rightJustify("Cost", 10) +
                        rightJustify("Qty", 5) +
                        rightJustify("Extended Cost", 15) +
                        rightJustify("GST", 5) +
                        rightJustify("Total Cost", 13));
    //          Print Records
              for(int i=0; i<validCounter; i++)
                   extendedCost = valid.CalculateExtendedCost();
                   extendedCost = roundDouble(extendedCost, 2);
                   GST = valid[i].CalculateGST();
                   GST = roundDouble(GST, 2);
                   totalCost = extendedCost + GST;
                   totalCost = roundDouble(totalCost, 2);
    //               justify method ensures all values are of the same size
                   System.out.println(//leftJustify(i+"",3) + ": " +
                             leftJustify(valid[i].GetName(), 50) +
                             leftJustify(valid[i].GetUPC(), 15) +
                             rightJustify(valid[i].getClass()+"", 10) +
                             rightJustify(valid[i].GetQuantity()+"", 5) +
                             rightJustify(extendedCost+"", 10) +
                             rightJustify(GST+"", 10) +
                             rightJustify(totalCost+"", 10));
                   sumOfExtendedCost += extendedCost;
                   sumOfGST += GST;
                   sumOfTotalCost += totalCost;
         private static void sortByName(Product1 [] ValidProduct, int logicalSize) throws Exception
              Product1 temp;
              for (int outer = logicalSize-1; outer > 1; outer --)
                   for (int inner = 0; inner < outer; inner ++)
                        if (ValidProduct[inner].GetName().compareToIgnoreCase(ValidProduct[inner+1].GetName())>0)
                             temp = ValidProduct[inner];
                             ValidProduct[inner] = ValidProduct[inner + 1];
                             ValidProduct [+ 1] = temp;
         public static void binarySearchByName(Product1 [] ValidProduct, int logicalSize)
              int high = logicalSize - 1;
              int low = 0;
              int mid = 0;
              int count = 0;
              int compare = 0;
              boolean found = false;
              System.out.print("Enter a product name");
              String product = input.nextLine();
              while (high >= low && !found)
                   count += 1;
                   mid = (high + low) / 2;
                   compare = ValidProduct[mid].GetName().compareToIgnoreCase(product);
                   if (compare == 0)
                        System.out.println("Found: " + ValidProduct[mid].GetName());
                        found = true;
                   else if (compare < 0)
                        low = mid + 1;
                   else
                        high = mid - 1;
              if (!found)
                   System.out.println(product + " not found.");
              System.out.println(count + " steps");
              System.out.println();
         public static String leftJustify(String field, int width)
              StringBuffer buffer = new StringBuffer(field);
              while (buffer.length() < width)
                   buffer.append(' ');
              return buffer.toString();
         public static String rightJustify(String field, int width)
              StringBuffer buffer = new StringBuffer(field);
              while (buffer.length() < width)
                   buffer.append(' ');
              return buffer.toString();
         public static void displayValidRecords(Product1 [] ValidProduct, int logicalSize) throws Exception {
              long longMAX_POSSIBLE_UPC_CODE = 999999999999L;
              // set input stream and get number
              Scanner stdin = new Scanner(System.in);
              System.out.print("Enter a 12-digit UPC number: ");
              long input =stdin.nextLong();
              long number = input;
              // determine whether number is a possible UPC code
              if ((input < 0)|| (input > longMAX_POSSIBLE_UPC_CODE)) {
                   // not a UPC code
                   System.out.println(input +"is an invalid UPC code");
              else {   
                   // might be a UPC code
                   // determine digits
                   int d12 = (int) (number % 10);
                   number /= 10;
                   int d11 = (int) (number % 10);
                   number /= 10;
                   int d10 = (int) (number % 10);
                   number /= 10;
                   int d9 = (int) (number % 10);
                   number /= 10;
                   int d8 = (int) (number % 10);
                   number /= 10;
                   int d7 = (int) (number % 10);
                   number /= 10;
                   int d6 = (int) (number % 10);
                   number /= 10;
                   int d5 = (int) (number % 10);
                   number /= 10;
                   int d4 = (int) (number % 10);
                   number /= 10;
                   int d3 = (int) (number % 10);
                   number /= 10;
                   int d2 = (int) (number % 10);
                   number /= 10;
                   int d1 = (int) (number % 10);
                   number /= 10;
                   // compute sums of first 5 even digits and the odd digits
                   int m = d2 + d4 d6 d8 + d10;
                   int n = d1 + d3 d5 d7 + d9 + d11;
                   // use UPC formula to determine required value for d12
                   int r = 10 - ((m +3*n) % 10);
                   // based on r, can test whether number is a UPC code
                   if (r == d12) {
                        // is a UPCcode
                        System.out.println(input+" is a valid UPC code");
                   else {   
                        // not a UPCcode
                        System.out.println(input+" is not valid UPC code");
    Any help would be great thanks !!
    Take care,

    1) It's your problem that you waited until the last minute before you went for help...not ours. We'll give your problem the same attention as anyone elses...therefore your problem isn't any more urgent than any other problem here.
    2) I don't intend on doing your entire assignment. Nor do I intend on reading all of it. If you need help with a specific requirement, then post the information/code relevant to that requirement. I don't know how to help you when you bury the problem inside a 9 mile long essay.
    3) Post code in tags so it's formatted and readable. (there's a *code* button up above that makes the tags for you).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Help needed in printing in java

    hello everyone, i m in grave need of a solution of printing a java page. I have a page designed in Java swings which contains mainly labels and textareas. And i need to print this page. The problem is that I have no clue how to go ahead. Cud neone arnd pls help me on this matter asap as this is very urgent. I shall be highly obliged to all the takers on this issue. Please email me at [email protected]
    Thanks and kind regards,
    Rahul.

    http://java.sun.com/docs/books/tutorial/2d/printing/index.html

  • MAC OSX 10.9 and Java Web start

    Hello All ,
    We are facing a warning when we tried to launch the JNLP on MAC using Java 1.7_45 .
    Warning message - "This Java Application will be blocked in a future Java Security update because the jar file manifest does not contain the Permissions attribute . Please contact the Publisher for
    more information "
    Warning is about adding permissions to application jar files but we have already done this on all the jars .
    Added code base and permissions attribute in manifest file of each jar . This works fine on Windows 7 and XP with same Java version .
    Example -
    Permissions: all-permissions
    Codebase: code base location from jnlp
    Interestingly Java console does not show any warnings so i am not sure why Java is showing this message that the application will be blocked in future java releases on MAC if permissions is not added to Jar file  .
    Looking at all the testing it seems there is some kind of issue between Java 7 update 45 and MAC OSX 10.9
    (As the same jnlp works without any warnings on other OS )
    Any help will be much appreciated .
    System Details
    OS - MAC OSX 10.9
    Java - 1.7_45
    thanks
    Rupesh

    Hi,
    The Drivers are available via Apple Software Update,
    In order to configure it wirelessly you may use the HP Easy Wireless Install app.
    You may find a step by step guide in the following document:
    h20565.www2.hp.com/portal/site/hpsc/template.PAGE/public/kb/docDisplay/?sp4ts.oid=4337543&spf_p.tpst...
    The app iself can be downloaded from the Mac App Store:
    https://itunes.apple.com/us/app/hp-easy-wireless-setup/id876495880?mt=12
    If you experience any issues while trying to locate the pritner during the wireless configuration. restoring the network defaults for the printer can be done by pressing and holding both the Cancel ( ), the Wireless ( ), and the Power ( ) buttons for three seconds.
    Regards,
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • Unable to read data in Java

    Hi,
    I tried to use this sample problem to extract the data from a primary database. But I am not getting anything back. Could someone please help me to take a kind look at my java code see what is wrong? I am new to Java, any help will be greatly appreciated.
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.Database;
    import com.sleepycat.db.SecondaryDatabase;
    import com.sleepycat.db.DatabaseConfig;
    import com.sleepycat.db.DatabaseType;
    import java.io.FileNotFoundException;
    import com.sleepycat.db.DatabaseEntry;
    import com.sleepycat.db.SecondaryCursor;
    import com.sleepycat.db.Cursor;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.LockMode;
    import com.sleepycat.db.OperationStatus;
    import com.sleepycat.db.SecondaryCursor;
    import com.sleepycat.db.SecondaryConfig;
    import com.sleepycat.bind.EntryBinding;
    import com.sleepycat.bind.serial.SerialBinding;
    import com.sleepycat.bind.tuple.TupleBinding;
    import com.sleepycat.db.Cursor;
    import com.sleepycat.db.DatabaseEntry;
    import com.sleepycat.db.DatabaseException;
    import com.sleepycat.db.LockMode;
    import com.sleepycat.db.OperationStatus;
    import com.sleepycat.db.SecondaryCursor;
    public class bdbtest {
    public static void main(String args[]) {
    SecondaryDatabase myDatabase = null;
         Database primDB = null;
         Cursor cursor = null;
         SecondaryCursor secCursor = null;
    try {
    // Open the database. Create it if it does not already exist.
    DatabaseConfig dbConfig = new DatabaseConfig();
         dbConfig.setErrorStream(System.err);
    dbConfig.setErrorPrefix("MyDbs");
         dbConfig.setType(DatabaseType.BTREE);
    dbConfig.setAllowCreate(false);
         SecondaryConfig mySecConfig = new SecondaryConfig();
         mySecConfig.setErrorStream(System.err);
    mySecConfig.setErrorPrefix("MyDbs");
         mySecConfig.setType(DatabaseType.BTREE);
    mySecConfig.setAllowCreate(false);
         mySecConfig.setReadOnly(true);
         dbConfig.setAllowCreate(false);
         ResNameKeyCreator keyCreator =
    new ResNameKeyCreator(new CallAttemptBinding());
    // mySecConfig.setSortedDuplicates(true);
    mySecConfig.setAllowPopulate(true); // Allow autopopulate
    mySecConfig.setKeyCreator(keyCreator);
         primDB = new Database("/tmp/bdb_ca_db.db",
    "bdb_ca_db",
    dbConfig);
    /*myDatabase = new SecondaryDatabase("/tmp/bdb_ca_sdb.db",
    "ca_sdb_res_alias",
    primDB,
    mySecConfig);*/
         String res ="12";
         DatabaseEntry searchKey =
    new DatabaseEntry(res.getBytes("UTF-8"));
         DatabaseEntry foundKey = new DatabaseEntry();
    DatabaseEntry foundData = new DatabaseEntry();
         cursor =
    primDB.openCursor(null, null);
    // Search for the secondary database entry.
         System.out.println("starting to get data\n");
         while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) ==
    OperationStatus.SUCCESS) {
    String keyString = new String(foundKey.getData(), "UTF-8");
    String dataString = new String(foundData.getData(), "UTF-8");
    System.out.println("Key | Data : " + keyString + " | " +
    dataString + "");
         } catch (Exception e) {
    System.err.println("Error on inventory secondary cursor:");
    System.err.println(e.toString());
    e.printStackTrace();
         finally {
    // Make sure to close the cursor
              try {
                   secCursor.close();
              }catch (com.sleepycat.db.DatabaseException e) {
    System.out.println("All done.");
    }

    Hi,
    As you can see from the output of db_dump, there is data in it. I just don't understand why the Java code can't return anything:
    [root@localhost examples_java]# /usr/local/BerkeleyDB.4.7/bin/db_dump -d a /tmp/bdb_ca_db.db
    In-memory DB structure:
    btree: 0x4048000 (open called, read-only, subdatabases)
    bt_meta: 0 bt_root: 1
    bt_minkey: 2
    bt_compare: 0x2b2adbd21520 bt_prefix: 0x2b2adbd21590
    bt_lpgno: 0
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    page 0: btree metadata: LSN [0][1]: level 0
    magic: 0x53162
    version: 9
    pagesize: 4096
    type: 9
    keys: 0 records: 0
    free list: 0
    last_pgno: 3
    flags: 0x20 (multiple-databases)
    uid: 43 0 8b 0 0 fd 0 0 ba 43 53 91 12 fe 1 0 0 0 0 0
    minkey: 2
    root: 1
    page 1: btree leaf: LSN [0][1]: level 1
    prev: 0 next: 0 entries: 2 offset: 4076
    [000] 4084 len: 9 data: bdb_ca_db
    [001] 4076 len: 4 data: 0000000x02
    page 2: btree metadata: LSN [0][1]: level 0
    magic: 0x53162
    version: 9
    pagesize: 4096
    type: 9
    keys: 0 records: 0
    free list: 0
    last_pgno: 2
    flags: 0x20 (multiple-databases)
    uid: 43 0 8b 0 0 fd 0 0 ba 43 53 91 12 fe 1 0 0 0 0 0
    minkey: 2
    root: 3
    page 3: btree leaf: LSN [0][1]: level 1
    prev: 0 next: 0 entries: 0 offset: 4096
    [root@localhost examples_java]#

  • How to declare a dynamic array in java

    I have to use a dynmic array of boolean and the size of this array will defiend throuh the run of the program to explian
    boolean[][] a;
    a=new boolean[number_of_ raw][number_of_ culm];
    after the program run the number_of_ raw and number_of_ culm will defind..so if any body know how to declare this kind of arraies in java please help me.

    My previous post gives me an idea on how to use ArrayList of ArrayList as dynamic 2 dimensional array.
    More info bellow
    ArrayList rows = new ArrayList()
    ArrayList columns_of_row0 = new ArrayList()
    rows.insertAt(0) = columns_of_row0;
    ArrayList columns_of_row1 = new ArrayList()
    rows.insertAt(1) = columns_of_row1;and so on..
    You can't use the code exactly or similar way, it would depend on how this array grows in your application.
    But this and my previous post should give an idea on how to insert and retrieve elements from ArrayList when
    treated as 2 dimensional array.
    Hope this helps.

  • Threading with Java 1.4.2_05-b04??

    Hi!
    Could some please tell me that what has happened with the threading model on Java 1.4.2?? I mean, I have applications that has been developed with 1.3.1_b24, and everything worked OK. Now that I updated to this newer Java version 1.4.2_05-b04, my applications just don�t seem to work, they crash instantly after the startup without throwing any exceptions. So everything SEEMS to go OK, but in fact nothing works! I used a profiler to solve things out, and noticed that there is a huge amount of deadlocks with my communication threads, and I really can't figure out why!!??
    I haven't been able to find any documentation if there really is something new with this Java version. I would expect that if Sun has changed something important concerning threading, my application should not even compile with the new Java. Now anyway, all the code compiles ok, and don't even throw any errors, it just crashes..:=(
    Could someone please give me a hint that what's wrong?? Does somebody have same kind of problems with Java 1.4.2??

    Hi,
    Just as Peter said, you wouldn't need to do any changes at all if your application had been correctly implemented. The deadlocks is probably not a direct cause of the changes in the threading model, but rather a cause due to changes in the behaviour in the program. E.g. execution times could have decreased/increased in some methods, and that exposes a bug in your application. Do you always aquire the locks in the same order in all methods/classes?
    /Kaj

  • I need help finishing the java install

    i have windows Millenium Edition & am trying to download J2SDK 1.5.0_4 so that i can write small programs at home. However, i cannot get the install software to finish putting java onto my desktop. it just keeps telling me that the install is complete but, there is no java icon to open the package. i have removed the program completely and tried a second time to install the software but i can get no further that the installshield wizard. i am at a loss and desperately want to start writing programs with java. someone out there, please help!
    i tried downloading an installing " Windows Offline Installation, Mult-language jdk-1_5_0_04-windows-i586-p.exe ( J2SE Develop. Kit 5.0 Update 4 ) " but it won't let me open java to write any programs.
    Thank you for your help in this matter.
    kind regards
    eric d.

    Java does not have a desktop icon to click. You open the command window and type commands to compile and execute the programs you write.
    I strongly suggest that you go to this tutorial
    http://java.sun.com/docs/books/tutorial/
    and click the First Steps: link. Be sure to click the link to the installation instructions and read them, especially the instructions about setting the PATH environment variable and the coaution regarding the use of Windows' Notepad.

  • How to filter datas  and display in java

    Hi guys.
    I'm kind of new to Java,
    I've have a database where values are stored ,i just have to take one column and i got to filter one value and display all .
    is there a command to filter
    I just want to do that if that Not wanted value is there to ignore and display the rest of the data in the html when search is called.
    i have to do this in the java , not in jsp.
    mysql,hibernate,ejb,jsp are being used at my environment.
    please help

    Simply put you want to 'selectively' navigate through the collection of data. Here, is an alternative using Iterator pattern given below;
    Create an interface
    * Iterator interface has method declarations for iterating through
    * data.
    public interface Iterator {
      public MyData next(int current);
      public MyData prev(int current);
    }// End of interfaceNow, create implementation classes for the above interface and you can aptly name them based upon your filtering criteria
    public MyFlter implements Iterator {
    * next � method which takes the current data number
    * and returns the next selected data.
      public MyData next (int current) {
        MyData data = null;
        while desired data not found: iterate --> implement your selection criteria here
        return data
      }              Similarly implement the previous method.
    Hope that helps.

  • Are java byte[] stored on the heap?

    are java byte[] stored on the heap?
    If not, How can I clear a byte[]?
    For example in C, I could simply put the '\0' at
    the zeroth index.
    Please help.
    hm

    Yes, byte[] objects are stored on the heap. In Java, all objects are stored on the heap, all arrays are objects, and byte[] is an array.
    You seem to be equating byte[] with a C-style string. That kind of thinking will get you into all kinds of trouble in Java. Strings in Java are sequences of Unicode characters. Byte arrays can be converted to and from Strings using encodings such as UTF-8.

  • Java.io.IOExecption; must be caugh or declared to be thrown - omg?

    Hello everybody,
    I'm kind of new to java and as part of a school project I've got to make a fully functional program.
    When compiling (I use BlueJ, if it matters), I'm getting this message:
    java.io.IOExecption; must be caugh or declared to be thrown
    What does this mean?
    I'm missing something(obviously), the IOExection, I think I saw that a mate from class has some part of code which does something when the wrong datatype or input is inputed, te IOExecption thingy.
    Please help, I need to do this very quickly, and time is running out!

    IOException is a "checked exception". That means that it's an exception that you must handle.
    Exceptions are classes that represent something going wrong in the program. They're not likely to go wrong (that's why they're called "exceptions" and not "typicals"), but the developer of the API you're using felt that it was likely enough, and that it was something that you could reasonably deal with if it does go wrong. The exception represents that unlikely event.
    Your job is to write some code that handles the exception. One way to handle it is just to declare your method as throwing that exception, and let the caller handle it. Another way to handle it is just to tell the user that it happened. In other cases, you can do more subtle handling -- say, you might be able to fix the core problem that the exception represents.
    Read about try/catch blocks in the tutorials.

  • Can not run the java

    It is very annoying when I type java at the prompt. It gives the following error.
    Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg'
    Initially, a variable, qtjava was pointing to this path.
    There was an entry i classpath for qtjava and there was a variable qtjava as well. I removed both of these. There is not qtjava in the list of set now but still when I type java, it displays the above error.
    how this is being invoked when I try to run java?
    Can any one give me some idea why this is hapening? and how to remove? the new java\jdk\bin is in the path? does it have to be in classpath ?
    thanks
    kiran
    Edited by: xmlcrazy on Aug 23, 2009 2:07 PM

    Thank you very much for your reply and link. There was an entry in registry. I am not sure how and why. Once I clean that and reboot the laptop, it is working now.
    I have a few more questions. I am kind of new to java. In fact I have worked a bit in the past but have left for long. So, I am now trying to revive and plannign to go in it as java technology alludes me always. It is not affected due to econymy or other technology.
    I am trying to test generics. When I tried to compile the following code
    import java.util.*;
    public class ArrayListGenericDemo {
    public static void main(String[] args) {
    ArrayList<String> data = new ArrayList<String>();
    data.add("hello");
    data.add("goodbye");
    // data.add(new Date()); This won't compile!
    Iterator<String> it = data.iterator();
    while (it.hasNext()) {
    String s = it.next();
    System.out.println(s);
    I got this error. Why generics does not work in eclipse?
    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
         The type ArrayList is not generic; it cannot be parameterized with arguments <String>
         Syntax error, parameterized types are only available if source level is 5.0
         The type ArrayList is not generic; it cannot be parameterized with arguments <String>
         Syntax error, parameterized types are only available if source level is 5.0
         The type Iterator is not generic; it cannot be parameterized with arguments <String>
         Syntax error, parameterized types are only available if source level is 5.0
         at ArrayListGenericDemo.main(ArrayListGenericDemo.java:5)
    any suggestion would be highly appreciated

Maybe you are looking for