Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Object Oriented question. - Page 3
Page 3 of 3 FirstFirst 123
Results 21 to 29 of 29

Thread: Object Oriented question.

  1. #21

    Re: Object Oriented question.

    Why not use numbers for error codes i.e. -1, -2, -3, then create a separate class to handle your error codes and return the appropriate strings?


  2. #22
    Guest

    Re: Object Oriented question.

    Yeah I believe mjb0314 has the right idea. Chop the problem into pieces, don't make one method do everything.

  3. #23

    Re: Object Oriented question.


    All right I'm getting ahead in Java. I came across a problem that I haven't found a solution to yet. In the following code I'm returning the value of "a". But how can I return the value of both "a" and "b"?
    Assuming Java is the same as C, you need to define a structure. Let's look at how C handles structures down at the assembler level. When a function returns a struct, it actually returns an address pointing to the struct in the eax register. (C can only return values in that register, and therefore can't return more than one value.) Then C can look at that address to see the values. If, for instance, the first value in the struct is an integer, it's simply the first two bytes of the struct. If it's an array, however, it's an address pointing to yet another part of memory. But naturally both functions have to know how the struct is constructed, so you either have to define it in both of them, or globally. In this situation, it should be quite safe to define it globally. (And when I say define the struct, I mean to specify what it contains, not to actually declare one.) Since Java is very similar to C and C++, I would think that you could do it the same way.

  4. #24
    Mentor
    Join Date
    Jun 2001
    Posts
    1,672

    Re: Object Oriented question.

    Actually, from what I've read is that the big difference in Java is that you can pass variables only by value and never by reference.

  5. #25
    Guest

    Re: Object Oriented question.

    Yep that's right, instead it uses (what I call) pass by Object if you need to do what pass by reference does.

  6. #26
    Mentor
    Join Date
    Jun 2001
    Posts
    1,672

    Re: Object Oriented question.

    I think I figured it out:
    Code:
    import java.sql.*;
    
    public class PrSQL {
       private Driver drv = null;
       private Connection conn = null;
       private ResultSet rs = null;
       private String LastError = "";
    
       public PrSQL() {}
    
       public long selectRecords(String query) throws Exception {
          long numberOfRows = 0;
          try {
             Pr.G.stmt = conn.createStatement();
             rs = Pr.G.stmt.executeQuery(query);
             rs.last();
             numberOfRows = rs.getRow();
             rs.beforeFirst();
          }
          catch (SQLException e) {
             LastError = "SQLState: " + e.getSQLState() + "<BR>Problems with SQL: " + e.getMessage();
          }
          return numberOfRows;
       }
    
       public String ErrorMsg() {
           return LastError;
       }
    }
    I created the LastError variable that my method sets if there's an error. I also created the ErrorMsg method that returns this variable, so I can call this method to see if there was an error before I go on with the program. I think I'm slowly getting this stuff. Thanks for everybody's input.

  7. #27

    Re: Object Oriented question.

    If you can't pass by reference, how are you supposed to pass an array or struct? That seems quite limited.

  8. #28
    Associate
    Join Date
    Dec 2001
    Posts
    17

    Re: Object Oriented question.

    a method is just a function that operates on an object. the object may be in the form of a struct ( in C) or class (in java and c++).

    so lets say you have an object called A_BUTTON. and the button holds one variable, INT Clicked. you would also write a function to do the operation of clicking that object.
    implemented in C:

    typedef struct { // an object
    int Clicked;
    } A_BUTTON;

    void Button_Action( A_BUTTON *button) { //a method
    if (button->Clicked == 1) button->Clicked = 0;
    else button->Clicked = 1;
    }

    int main() {
    A_BUTTON newbutton; //declaration
    newbutton.Clicked = 0; // should be in a constructor method
    Button_Action( &newbutton); //action
    return 0;
    }



    in C++:

    class A_BUTTON { //an object
    int Clicked;

    void Button_Action(); //notice method here
    }

    void A_BUTTON::Button_Action() { //method defined out here (could be inside the class)
    if( Clicked == 1) Clicked = 0;
    else Clicked = 1;
    }

    int main() {
    A_BUTTON newbutton; //declaration
    newbutton::Clicked = 0; //initiation should be a method of its own
    newbutton::Button_action(); //operation
    return 0;
    }

    notice that in C++ you do not need to pass any values to the methods.

    Button_Action is a method. It's sole purpose is to perform action on the object A_BUTTON. of course you would write a Constructor method to initiate the values inside the struct first.

    in java and c++ the method may be encapsulated within the class while in C, the method is just another function floating around. You can see that it is more elegant when writing object oriented code in a language that is designed for OO but that it can be done in a language that is not. i.e. java vs C. i do my gtk programming in C.

  9. #29
    Mentor
    Join Date
    Jun 2001
    Posts
    1,672

    Re: Object Oriented question.

    If anyone else is interested in getting started with Java, I suggest you start with this tutorial:
    http://www.ejbfactory.com/technology...technology.htm

    It uses a no-nonsense approach and starts with the basics and goes step-by-step with simple examples that's easy to follow.


Similar Threads

  1. object file not supporting kernel version
    By misbah_khan in forum Linux - General Topics
    Replies: 1
    Last Post: 11-27-2006, 07:02 AM
  2. Testing through Shared Object File of Code
    By honey bee in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 07-27-2006, 12:19 PM
  3. libXmu.so: cannot open shared object file: Too many levels of symbolic links
    By shupi in forum Linux - Software, Applications & Programming
    Replies: 0
    Last Post: 07-04-2006, 05:18 AM
  4. libXmu.so: cannot open shared object file
    By shupi in forum Linux - General Topics
    Replies: 0
    Last Post: 07-02-2006, 09:49 AM
  5. Possible to get different object files from the same source code & toolchain?
    By josaiah in forum Linux - Software, Applications & Programming
    Replies: 3
    Last Post: 10-17-2002, 02:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •