Help w/ private methods program..

hi guys...
i was just wondering if somebody can help me w/ the code i am writing for a project..
the project is about prime numbers and its factors.
-we have to create a private method called checkInput() which is sent the users String inputted number as a parameter and returns a boolean indicating wether the input is valid or not. (I am using inputNum as the variable that holds the number)
-also i have to call that checkInput private method from some other private method, which giving me errors when compiling...
thanks a lot...
private void getInput()throws IOException
BufferedReader stdin = new BufferedReader
(new InputStreamReader(System.in));
System.out.print("Enter an INTEGER number greater than "+MIN+". ");
while (inputNum <= 1)
System.out.print("Enter an INTEGER number greater than "+MIN+". ");
inputNum= Integer.parseInt(stdin.readLine());
}//end of while loop
checkInput();
}//end of method getInput.
// This method is to send the users String inputted
// number as a formal parameter and returns
// a boolean indicating whether the input is valid
// or not.
private boolean checkInput(String inputNum)
while(inputNum != null)
return true;
}///end of checkInput method.
// This method is to pass a formal parameter number
// which is a valid integer number that the user
// entered. The method will return a Boolean
// value indicating whether the number is a prime.
private boolean IsPrime (int number)
if (number == 1 || number == 2)
return true;
for (int i=2; i<(int)(number/2); i++)
if ( (number/i)==(int)(number/i) )
return false;
return true;
}//end of method IsPrime.
// This method calls the IsPrime method passing
// it the actual parameter inputNum which is
// valid user inputted number.
private void checkForPrime ()
IsPrime(inputNum);
if(true){
System.out.println(inputNum+ " is a prime");
}else
System.out.println(inputNum+ " is not a prime");
printAllFactors(inputNum);
}// end of checkForPrime method.
// This method prints out "Its factors are:",
// skips a line and then prints out all the factors
// of the formal parameter number.
private void printAllFactors (int number)
System.out.println("Its factors are: ");
System.out.println();
for (int i = 2; i <= number; i++){
if(inputNum % number == 0)
System.out.println(number + " is a factor.");
break;
System.out.println(number + " is not a factor.");
}// end of printAllFactors method.
}// end of main class.this is the code i have so far...

Please don't crosspost. It cuts down on the effectiveness of responses, leads to people wasting their time answering what others have already answered, makes for difficult discussion, and is generally just annoying and bad form.

Similar Messages

  • Creation of a static class with private methods

    I'm new to java programming and am working on a project where I need to have a static class that does a postage calculation that must contain 2 private methods, one for first class and one for priority mail. I can't seem to figure out how to get the weight into the class to do the calculations or how to call the two private methods so that when one of my other classes calls on this class, it retrieves the correct postage. I've got all my other classes working correct and retrieving the information required. I need to use the weight from another class and return a "double". Help!!!
    Here's my code:
    * <p>Title: Order Control </p>
    * <p>Description: Order Control Calculator using methods and classes</p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: Info 250, sec 001, T/TH 0930</p>
    * @author Peggy Blake
    * @version 1.0, 10/29/02
    import javax.swing.*;
    public class ShippingCalculator
    static double firstClass, priorityMail;
    //how do I get my weight from another class into this method to use??? not sure I understand how it works.
    public static double ShippingCalculator(double weight)
    String responseFirstClass;
    double quantity, shippingCost;
    double totalFirstClass, firstClass, priorityMail, totalShipping;
    double priorityMail1 = 3.50d;//prioritymail fee up to 1 pound
    double priorityMail2 = 3.95d;//prioritymail fee up to 2 pounds
    double priorityMail3 = 5.20d;//prioritymail fee up to 3 pounds
    double priorityMail4 = 6.45d;//prioritymail fee up to 4 pounds
    double priorityMail5 = 7.70d;//prioritymail fee up to 5 pounds
    quantity = 0d;//ititialization of quantity
    // weight = 0d;//initialization of weight
    // shippingCost = 0d;
    //calculation of the number of items ordered..each item weights .75 ounces
    quantity = (weight/.75);
    if (quantity <= 30d)
    //add 1 ounce to quantities that weigh less than 30 ounces
    weight = (weight + 1);
    else
    //add 2 ounces to quantities that weigh more than 30 ounces
    weight = (weight + 2);
    if (weight > 80d)
    //message to orderclerk ..order over 5 lbs, cannot process
    JOptionPane.showMessageDialog(null, "Order exceeded 5 lbs, cannot process");
    //exit system, do not process anything else
    System.exit (0);
    else
    if (weight < 14d)
    //send message to customer: ship firstclass or priority, y or n
    responseFirstClass = JOptionPane.showInputDialog(null, "Ship first class? y or n?");
    if (responseFirstClass.equals("y"))
    //compute FirstClass shipping cost
    totalFirstClass = ((weight - 1) * .23d) + .34d;
    firstClass = totalFirstClass;
    else
    //compute PriorityMail cost for orders less than 14 ounces
    priorityMail = (priorityMail1);
    else
    if (weight <=16d)
    //compute totalshipping for orders up to 16 ounces
    priorityMail = (priorityMail1);
    else
    if (weight <=32d)
    //compute totalshipping for orders up to 32 ounces
    priorityMail = (priorityMail2);
    else
    if (weight <=48d)
    //compute totalshipping for orders up to 48 ounces
    priorityMail = (priorityMail3);
    else
    if (weight <= 64d)
    //compute totalshipping for orders up to 64 ounces
    priorityMail = (priorityMail4);
    else
    //compute totalshipping for orders up to 80 ounces
    priorityMail = (priorityMail5);
    priorityMail = 0d;
    firstClass = 0d;
    firstClassMail ();
    priorityMailCost ();
    //I think this is where I should be pulling the two methods below into my code, but can't figure out how to do it.
    shippingCost = priorityMail + firstClass;
    return (shippingCost);
    }//end method calculate shipping
    private static double firstClassMail()//method to get first class ship cost
    return (firstClass);
    }//end method firstclass shipping
    private static double priorityMailCost()//method to get priority mail cost
    return (priorityMail);
    }//end method priorityMail
    }//end class shipping calculator

    public class A {
    public String getXXX () {
    public class B {
    A a = new A();
    public void init () {
    a.getXXX();
    }

  • Private methods Importing parameter cannot be changed error

    Hi Guys,
    I have this scenario where I have a private method inside a class which is having an error "Field SAPMF02K cannot be changed".
    here is the code for the private method call.
        call method create_bdc_dynpro
             importing  IM_PROGRAM = 'SAPMF02K'
                        IM_DYNPRO = '0100'.
    code of the method
      data: wa_bdcdata type bdcdata.
      CLEAR wa_bdcdata.
      wa_bdcdata-program = im_program.
      wa_bdcdata-dynpro = im_dynpro.
      wa_bdcdata-dynbegin = at_true.
      APPEND wa_bdcdata to at_bdcdata.
    Hope you can help
    Thanks!

    Howdy,
    I think you have your importing/exporting the wrong way round.
    The method call should be:
    call method create_bdc_dynpro
    exporting IM_PROGRAM = 'SAPMF02K'
    IM_DYNPRO = '0100'.
    And of course in the method definition they should be importing parameters.
    Cheers
    Alex

  • Does abap unit testclass can get acces to private methods of classes to tes

    Hi,
    I want to do a abap unit test inside a user program. the program calls my class and i want some of the methods there to be tested (i.e. db layer, some business logic etc).
    My problem is, that I can define unit test very goog on program level or even for public methods of the class.
    But what should I do if I want the maybe 3 private methods called by the public method to be tested standalone?
    Does anyone have a idea for that?
    THX
    regards,
    Jens

    Hello Jens,
    you may test private methods with the help of the FRIEND statement. For sample you place a local testclass in the class pool. In order to get friendship you may than use the following sequence of statements.
      class ltc_Repository definition deferred.
      class cl_Global definition local friends ltc_Repository.
      class ltc_Repository                     "#AU Risk Level Harmless
        definition for testing.
        private section.
          methods:
            retrieve_Fails_For_Bad_Key   for testing,
            update_Fails_For_Dup_Key     for testing.
    endclass.
    or
      interface lif_Unit_Test.
      endinterface.
      class cl_Global definition local friends lif_Unit_Test.
      class ltc_Repository                     "#AU Risk Level Harmless
        definition for testing.
        public section.
          interfaces: lif_Unit_Test.
        private section.
          methods:
            retrieve_Fails_For_Bad_Key   for testing,
            update_Fails_For_Dup_Key     for testing.
    endclass.
    By this technique you can grant access to private members of the global class to any local class. Without exposing something to the outside world! This code can be placed in the local implementation include of the class pool, or in test class include from release 7.02 onwards.
    Using transaction /nABAPHELP provides all details on the FRIEND statement.
    Testing private methods can be useful but also tends to result in [fragile tests|http://xunitpatterns.com/Fragile%20Test.html]. That means changes to the implementation may make your test turn red without any violation of the outside contract.
    Ciao
      Klaus

  • I need help instantly on this program please

    import java.util.*;
    public class D3
              private static int[] z = new int[100000];
    private static int first=z[0];
              private static int last=z[n-1];
              private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
              z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
              int binSearch(z;first;last;50000);
              int seqSearch(z;35467;n); //method call 4 key where key in the left half
              int binSearch(z;first;last;35467);
              int seqSearch(z;89703;n); //method call 4 key where key in the right half
              int binSearch(z;first;last;89703);
              public int seqSearch(int z[];int key;int n)
         long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z[i]=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
         public int binSearch(int z[];int first;int last;int key)
         long start = System.currentTimeMillis();
         int count=0;
         if(last<first){
         count++;
         index=-1;
         else
         count++;
         int mid=(first+last)/2
         if(ket=z[mid]{
         index=mid;
         else
         if(key<z[mid]){
         index = binSearch(z[];first;mid-1;key);
         else
         index=binSearch(z[];mid+1;last;key);
         return index;
         long elapsed = System.currentTimeMillis() - start;
         System.out.print("Execution Time:" + elapsed);
         System.out.print("# of Basic Operations:" + count);
    // if anyone could tell me whats wrong with my code i'd be greatful...the program is supposed to perform binary and sequential search on a sorted array of 100000 numbers.once on an item in the middle of the array once on the right side of it and once on the left side...i also need to count the number of basic operations for the same number in both sequential and binary to see whats better.and i need to check the time...plz i need help now,,,

    "Guide to a first-time poster"
    you need to add exclamation marks to signify how urgent it is
    e.g.
    i need help instantly on this program please!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    capital letters is better
    I NEED HELP INSTANTLY ON THIS PROGRAM PLEASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    starting the italics on line 1, better again
    import java.util.*;
    public class D3
    private static int[] z = new int[100000];
    private static int first=z[0];
    private static int last=z[n-1];
    private static int n=100000;
    public static void main(String args[])
    Scanner input=new Scanner(System.in);
    for(int i=0;i<z.length;i++)
    z=2*i;
    int seqSearch(z;50000;n); //method call 4 key where key=mid
    int binSearch(z;first;last;50000);
    int seqSearch(z;35467;n); //method call 4 key where key in the left half
    int binSearch(z;first;last;35467);
    int seqSearch(z;89703;n); //method call 4 key where key in the right half
    int binSearch(z;first;last;89703);
    public int seqSearch(int z[];int key;int n)
    long start = System.currentTimeMillis();
    int count=0;
    int ans=-1;
    for(int i=0;i<n;i++)
    if z=key
    count++
    {ans=i
    break;}
    return ans;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    public int binSearch(int z[];int first;int last;int key)
    long start = System.currentTimeMillis();
    int count=0;
    if(last><first){
    count++;
    index=-1;
    else
    count++;
    int mid=(first+last)/2
    if(ket=z[mid]{
    index=mid;
    else
    if(key><z[mid]){
    index = binSearch(z[];first;mid-1;key);
    else
    index=binSearch(z[];mid+1;last;key);
    return index;
    long elapsed = System.currentTimeMillis() - start;
    System.out.print("Execution Time:" + elapsed);
    System.out.print("# of Basic Operations:" + count);
    and what about the dukes, offer 10 (never to be awarded, of course)
    do this, then sit back and watch the replies roll in.

  • Error while usind Private Method of a global class

    HI All..
    I created a global class (ZLINE_GLOBAL) which has TOT_DATA private method. I have to call this private method in my report, I know that using Friend class we can do this.
    But it is not working and showing the same error  "  METHOD "TOT_DATA" is unknown or Private or Public..
    code i tried is
    CLASS c2 DEFINITION DEFERRED.
    CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
      PUBLIC SECTION.
        METHODS : m1.
      PRIVATE SECTION.
        METHODS: m2.
    ENDCLASS.
    CLASS ZLINE_GLOBAL IMPLEMENTATION .
      METHOD m1.
        WRITE : 'Public Method C1'.
      ENDMETHOD.                    "M1
      METHOD m2.
        WRITE : 'Private Method C1'.
      ENDMETHOD.
    ENDCLASS.
    CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL.  "my friends are here, allow them access to my (C2's) private components
      PUBLIC SECTION.
        METHODS :m3.
    ENDCLASS.
    CLASS c2 IMPLEMENTATION.
      METHOD m3.
        DATA : obj TYPE REF TO ZLINE_GLOBAL.
        CREATE OBJECT obj.
        CALL METHOD obj->TOT_DATA.    "here Iam calling Private method of global class
      ENDMETHOD.                    "M3
    ENDCLASS.
    START-OF-SELECTION.
      DATA obj_c2 TYPE REF TO c2.
      CREATE OBJECT obj_c2.
      obj_c2->m3( ).
    can anybody help me on this..
    Murthy

    Hi Murthy,
    Replace TOT_DATA with M2, you do not have any method by name "TOT_DATA" in your code.
    CLASS c2 DEFINITION DEFERRED.
    CLASS ZLINE_GLOBAL DEFINITION FRIENDS c2.
      PUBLIC SECTION.
        METHODS : m1.
      PRIVATE SECTION.
        METHODS: m2.
    ENDCLASS.
    CLASS ZLINE_GLOBAL IMPLEMENTATION .
      METHOD m1.
        WRITE : 'Public Method C1'.
      ENDMETHOD.                    "M1
      METHOD m2.
        WRITE : 'Private Method C1'.
      ENDMETHOD.
    ENDCLASS.
    CLASS c2 DEFINITION FRIENDS ZLINE_GLOBAL.  "my friends are here, allow them access to my (C2's) private components
      PUBLIC SECTION.
        METHODS :m3.
    ENDCLASS.
    CLASS c2 IMPLEMENTATION.
      METHOD m3.
        DATA : obj TYPE REF TO ZLINE_GLOBAL.
        CREATE OBJECT obj.
        CALL METHOD obj->M2.    "here Iam calling Private method of global class
      ENDMETHOD.                    "M3
    ENDCLASS.
    START-OF-SELECTION.
      DATA obj_c2 TYPE REF TO c2.
      CREATE OBJECT obj_c2.
      obj_c2->m3( ).
    Regards,
    Chen

  • Help with a java program

    Hello. I'm posting in these forums because I really don't know where else to go. I have been trying for the past several days to figure out how to go about writing my program but to no avail. The project requires reading many lines each containing several different elements from a datafile named "DATA". A few examples of some lines from that file:
    Department number/Number of units received/Date on which the shipment arrived/Expiration date/Name of Object
    0 78 02/03/2001 02/12/2001 apples
    0 26 06/03/2001 06/10/2001 lemons
    3 62 03/06/2001 03/14/2001 hamburger
    What we have to do with this data is read all of it from the file, separate all the different elements, and based on input from the user, sort everything and print it out to the screen. If the user enters 03, the program will show everything that arrived and expired within the month of March, sorted by date.
    It is a pretty basic program, but my problem is that I have no idea how to go about reading in this data, putting it into a vector (probably the easiest method) or separating the different elements. I've gone to websites and looked through my textbooks but they didn't help much. If anyone has any resources that could help for writing such a program, or if anyone could offer help in writing the program, I would really appreciate it. I can also show what I've managed to write so far, or more details on how the program should work. Thanks in advance.
    Matt

    since im not a pro like some of the guys on here :),
    and believe me thiers people here, who could write your whole app in a hour.
    anyways my advice , would be to do a search on the forums for useing.bufferReader()
    i think you would need to read the file in with bufferreader then split up each line useing the stringTokenizer and then use some algorithm to compare
    the values and split them up into your vector arrays as needed.
    thier is also fileinputStream i think you can use that too.

  • Input Method Program

    Hi all!!!!!!!!!!
    I am new to Java. I have been written a chinese input method program by visual basic. However, I would like to rewrite it in Java so that it can be used in all OS platform. I would like to ask how to do the following things in Java.
    1. Receive all keyboard input although my program is out of focus.
    2. Send chineses character to other program that is on focus.
    Please give me some clues or information. Thank you very much !!!!!!!!!!!!!!1

    Ive done something recently with another alphabet type you can download it from here and then install it on your system font folder;-
    http://www.ethiopar.net/Amharic/download.htm
    Then try out this program - its a fully working program - though I've cut out a lot from the full program that won't be of much use to you ie: the jdbc/ database + search parts plus there are 2 other Panels. This is a keyboard and mouse application - Hope it may help and give you some ideas for your project
    good luck!
    Sue xxx
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class AmharicKeyboard extends JFrame implements ActionListener {
    String []str ={"h","h#","�","�","�&","H","l","l#","l!","l@","L","/","/#","/!","/@","?",
    "m","m#","M","s","s#","s!","s@","S","r","r#","R","v","v#","v!","v@","V",
    "q","q#","q!","'","q@","Q","b","b#","b!","b@","B","t","t#","t!","�","t@","T",
    "c","c#","c$","c!","c@","C","~","~#","~!","`","~@","^","n","n#","n!","n@!","N",
    "x","x#","x!","x@","X","�","k","k#","k!","k@","K",",",",#",",!",",@","<",
    "w","w#","W",";",";#",":","z","z#","z!","z@","Z","y","Y",
    "d","d#","d!","d@","D","j","j#","j!","j@","J","g","g#","g!","U","g@","G",
    "-","-#","-!","-@","_","=","=#","=!","=@","u","[","[#","[!","[@","{","e","]","]#","]!",
    "}","f","f@","F","p","p#","p!","p@","P"};
       String word;
         JButton b[] = new JButton[str.length];
       Font amharic = new Font("VG2 Main",1,16);
    public AmharicKeyboard() {
       super("Amharic Translations and Keyboard");
       Container c = getContentPane();
         c.setLayout(new BorderLayout());
       Panel panel = new Panel();
       for (int i=0; i<=str.length-1; i++){
                   b= new JButton(str[i]);
                   b[i].setFont(amharic);
                   b[i].setForeground(new java.awt.Color(255,20,45));
                   b[i].setBackground(new java.awt.Color(20,40,150));
                   b[i].addActionListener(this);
                   panel.add(b[i]);
    c.add(panel);
    public void paint (Graphics g) {
              super.paint (g);
              Graphics2D G = (Graphics2D) g;
    G.drawString(word, 50, 500);
              G.setFont(amharic);
    G.drawString(word, 50, 520);
    public void actionPerformed(ActionEvent evt){ }
    public static void main (String []args){
         AmharicKeyboard applctn = new AmharicKeyboard();
         applctn.setSize(800,600);
    applctn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
         applctn.setVisible(true);

  • Help with a simple program.

    I need some help writing a simple program. Can anybody help??
    thanks to all.
    2. HTML Java Source Code Reserved Word Highlighter
    Write a program that inputs a Java source code file and outputs a copy of that file with Java keywords surrounded with HTML tags for bold type. For example this input:
    public class JavaSource
    public static void main ( String[] args )
    if ( args.length == 3 )
    new BigObject();
    else
    System.out.println("Too few arguments.");
    will be transformed into:
    <B>public</B> <B>class</B> JavaSource
    <B>public</B> <B>static</B> <B>void</B> main ( String[] args )
    <B>if</B> ( args.length == 3 )
    <B>new</B> BigObject();
    <B>else</B>
    System.out.println("Too few arguments.");
    In a browser the code will look like this:
    public class JavaSource
    public static void main ( String[] args )
    if ( args.length == 3 )
    new BigObject();
    else
    System.out.println("Too few arguments.");

    Here is something that may get you started...
    import java.io.*; 
    import java.util.*; 
    public class HtmlJava{
         public static void main(String arg[]){
              if(arg.length!=1){
                   System.out.println("Usage java HtmlJava sourceFile");       
              else
                   new HtmlJava(arg[0]);
         HtmlJava(String source){
              try{
                   BufferedReader sourceReader=new BufferedReader(new InputStreamReader(new FileInputStream(source)));
                   BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(source+"Html.txt")));  
                   Vector keywords=new Vector();
                   addKeywords(keywords);
                   String line;
                   StringTokenizer tokenizer=null;
                   String word;
                   while((line=sourceReader.readLine () )!=null){
                        tokenizer=new StringTokenizer(line);
                        while(tokenizer.hasMoreTokens()){
                             word=tokenizer.nextToken();
                             if(keywords.contains(word)){
                                  writer.write(""+word+" ");
                             else{
                                  writer.write(word+" ");
                        writer.write("\r\n");
                   writer.close();
                   sourceReader.close(); 
                   System.out.println("Output File written to "+source+"Html.txt"); 
              catch(Exception ex){
                   ex.printStackTrace();      
         private void addKeywords(Vector keywords){
              keywords.addElement ( "abstract");
              keywords.addElement( "boolean");
              keywords.addElement( "break");
              keywords.addElement( "byte");
              keywords.addElement( "byvalue");
              keywords.addElement( "case");
              keywords.addElement( "cast");
              keywords.addElement( "catch");
              keywords.addElement( "char");
              keywords.addElement( "class");
              keywords.addElement( "const");
              keywords.addElement( "continue");
              keywords.addElement( "default");
              keywords.addElement( "do");
              keywords.addElement( "double");
              keywords.addElement( "else");
              keywords.addElement( "extends");
              keywords.addElement( "false");
              keywords.addElement( "final");
              keywords.addElement( "finally");
              keywords.addElement( "float");
              keywords.addElement( "for");
              keywords.addElement( "future");
              keywords.addElement( "generic");
              keywords.addElement( "goto");
              keywords.addElement( "if");
              keywords.addElement( "implements");
              keywords.addElement( "import");
              keywords.addElement( "inner");
              keywords.addElement( "instanceof");
              keywords.addElement( "int");
              keywords.addElement( "interface");
              keywords.addElement( "long");
              keywords.addElement( "native");
              keywords.addElement( "new");
              keywords.addElement( "null");
              keywords.addElement( "operator");
              keywords.addElement( "outer");
              keywords.addElement( "package");
              keywords.addElement( "private");
              keywords.addElement( "protected");
              keywords.addElement( "public");
              keywords.addElement( "rest");
              keywords.addElement( "return");
              keywords.addElement( "short");
              keywords.addElement( "static");
              keywords.addElement( "super");
              keywords.addElement( "switch");
              keywords.addElement( "synchronized");
              keywords.addElement( "this");
              keywords.addElement( "throw");
              keywords.addElement( "throws");
              keywords.addElement( "transient");
              keywords.addElement( "true");
              keywords.addElement( "try");
              keywords.addElement( "var");
              keywords.addElement( "void");
              keywords.addElement( "volatile");
              keywords.addElement( "while");
    }Hope it helped

  • Are private methods inherently final?

    You can�t override a private method, so is it inherently final? Will the compiler treat it like a final? I�ve heard that final methods may be inlined by the compiler but haven�t really been able to produce a test to show the advantage of inlining. I know in theory it trades speed for program size, but, if it does work, is it really that much faster? I�m guessing CPU local cache probably eliminates or at least reduces to negligible time the overhead of swapping out the instruction stack to perform a �jump.�
    Thanks for your thoughts. Mostly trying to figure out when to use final methods.

    You can�t override a private method, so is it
    inherently final? Given that that is exactly what the JLS says it would
    suggest that the answer is yes.
    http://java.sun.com/docs/books/jls/second_edition/html
    /classes.doc.html#38958
    I believe the invocation (byte code) is different as
    well (but I didn't look it up) so the VM could
    certainly easily do something with it.Actually, I don't think this is 100% accurate.
    You can replace a private method in a subclass with the same signature (name, arg list) with the same return type. In fact, this is true even if the private method is declared final. It is only when the final method is public (maybe protected and package, I'm not sure) that the compiler complains when you try to extend it.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Overriding private methods

    Is it possible to override private methods??
    class A {
    private void print() {
    System.out.println("Hello Super");
    class B extends A{
    public void print() {
    System.out.println("Hello Sub");
    class C {
    public static void main(String args[]) {
    A a=new B();
    a.print();
    According to overriding rules the sub class method should not be more restrictive than the super class method. SO we are making it public (From private).
    So the above code is an example of overriding but when compiled it gives error.
    Please explain why??

    Oh wait, I had a second look and compiled & ran your program. This is the error message:
    A.java:16: print() has private access in A
    a.print();
    ^
    1 errorYou are trying to call a private method, so you get an error. You can't make private methods public by subclassing.

  • Help with an array program

    I can't see how to calculate the lowest hours, highest hours, and average hours worked.
    These three values should be outputted each on a seperate line.
    I just can't figure this out.
    Any help please.
    This program will show the employees
    hours. It will have one
    class.It will use an array to keep
    track of the number of hours the employee
    has worked with the output to the monitor
    of the employees highest, lowest, and the
    average of all hours entered. */
    import java.util.*;
    import java.text.DecimalFormat;
    /*** Import Decimal Formating hours to format hours average. ***/
    public class cs219Arrays
         public static void main(String[] args)
              Scanner scannerObject = new Scanner(System.in);
              int[] employees ={20, 35, 40};
              int employeesHighest = 40;
              int employeesLowest = 20;
              double employeesAverage = 35;
              int[] firstEmployee = new int[1];
              int[] secondEmployee = new int[2];
              int[] thirdEmployee = new int[3];
              System.out.println("This program will accept hours worked for 3 employees.");
              System.out.println("Enter hours worked for employee #: ");
              System.out.println(".\n");
              employeesAverage = scannerObject.nextInt();
              for(int count =20; count <= 40; count++)
                             DecimalFormat df = new DecimalFormat("0.00");
                             System.out.println("pay: " employeesAverage " lowest " employeesHighest " Highest hours " employeesLowest " Lowest hours "+df.format(employeesAverage));
                             System.out.print("\n");
                             employeesAverage++;
    }/* end of body of first for loop */
              for(int count =20; count <= 40; count++)
                                       employeesAverage = employeesAverage + employeesHighest + employeesLowest;
                                       DecimalFormat df = new DecimalFormat("0.00");
                                       System.out.println("pay: $" employeesAverage " lowest " employeesHighest " Highest hours $" +df.format(employeesAverage));
                                       System.out.print("\n");
                                       employeesAverage++;
    }/* end of body of second for loop */
              for(int count =20; count <= 40; count++)
                                       employeesAverage = employeesAverage + employeesHighest + employeesLowest;
                                       DecimalFormat df = new DecimalFormat("0.00");
                                       System.out.println("pay: $" employeesAverage " lowest " employeesHighest " Highest hours $" +df.format(employeesAverage));
                                       System.out.print("\n");
                                       employeesAverage++;
    }/* end of body of third for loop */
              System.out.println("\n");
              DecimalFormat twoDigits = new DecimalFormat("0.00");
              /*** Create new DecimalFormat object named twoDigits ***/
              /*Displays number of hours, employees hours and average hours.*/
              System.out.println("You entered " + employeesAverage + " number of hours.");
              System.out.println("Your number of hours are " + twoDigits.format(employeesAverage));
              System.out.println("\n\n");
    }     /*End of method for data.*/
    {     /*Main method.*/
    }     /*End of main method.*/
    }     /*End of class cs219Arrays.*/

    Want help?
    Use the code formatting tags for starters. http://forum.java.sun.com/help.jspa?sec=formatting

  • Muse Private Beta program

    Hi there,
    Is it possible to still join the Muse Private Beta program? I tried joining but received a message stating that I'd be notified when Muse Beta is available. My work associate was able to join the private beta and is now running off that muse version. I need to make edits on one of our client websites and don't think I'll be able to do that if I don't have the same muse version as my associate. Is that correct? Is it possible to join the private beta so that we are using the same version?
    Thank you!

    Hello,
    Check this related post: http://forums.adobe.com/message/5687723#5687723
    Hope this helps.
    Cheers
    Parikshit

  • Calling package private method

    Suppose you have a class called A:
    org.blah.A
    |
    --org.blah.blahblah.B
    (B extends A)
    But class B is in another package than A
    So if I do the following
    A a = new A();
    B b = (B) a;and if class B has package private methods how can I call them by downcasting to B? What is a work-around?

    Tutorial:
    public is the most generous of the four modifiers. A public class, method, or variable may be used in any Java program without restriction.
    private is the most restrictive of the modifiers. A private variable or method may only be used by an instance of the class that declares the item.
    (read none) is the friend or default modifier. A class's default feature is available to any class in the same package.
    protected vars and methods are available to all classes in the same package as the class that declares them. Moreover, they are available to subclasses of the declaring class even if the subclass resides in a different package.

  • Class Private Methods

    I'm doing a number of instrument drivers in LabVIEW 8.20 and am using the OO features which so far I'm really liking.
    At present I have my class with various methods in it that are called from a TestStand sequence, but there are some methods that are only called from within the class i.e. private methods - is there any way of defining a method as being private to other methods in the class?
    I noticed that on one of the instrument driver examples in the help that one of the class sub-folders had a little red key on it that looked as though it was indicating that files within this folder were private - is this what I'm looking for and how would I do that?
    Many thanks in advance for any responses,
    David Clark
    CLA | CTA
    CLA Design Ltd
    Hampshire, England

    I've found out how to do it :-
    (from help file)
    Setting the Access Scope of Member VIs
    You can set the access scope of a member VI to control user access to the member VI. Complete the following steps to set the access scope of a member VI.
    In the Project Explorer window, right-click the LabVIEW class icon for the class whose member VI access you want to change. The Class Properties dialog box appears.
    Select Item Settings from the Category list.
    To customize the access scope of items in the LabVIEW class, select an item from the Contents list on the Item Settings page.
    In the Access Scope section, select from the following options:
    Public—Any VI can call the member VI as a subVI.
    Protected—Only VIs within the same class or a descendant class can call the member VI. Protected member VIs display a dark yellow key glyph in the Project Explorer window.
    Private—Only VIs within the same class can call the member VI. Private member VIs display a red key glyph in the Project Explorer window.
    Repeat steps 3 and 4 for all items for which you want to change the access scope.
    Click the OK button to close the Class Properties dialog box.
    David Clark
    CLA | CTA
    CLA Design Ltd
    Hampshire, England

Maybe you are looking for