How to write hasCode() & equals(0) methods in Compound Key Class

Hi Java Helpdesk,
I am wondering how to write the hashCode() and equals() methods that is mandatory when creating composite
@IdClass. Below is the combination of primary @Id keys that I would like to make up in a compound key class:
public final class PatientKey implements java.io.Serializable
    private String firstnameId;
    private String SurnameId;
    private String DateOfBirthID;
    private String Sex;
    public int hashCode()
    public boolean equals(Object otherOb)
}The Order application in Java EE 5 Tutorial (page 841) is made up of only 2 primary keys.
Thanks,
Jack

Hi,
Thanks for your very brief response and I had a look at both EqualsBuilder and HashCodeBuilder from the URL links you have provided. These methods may improve the comparison accuracy but I was more interested on how to implement the equals() and hashCode methods when comparing 3 or more primary keys in order to make up a primary key class. Below is my first attempt to compose the PatientPK primary key class:
1. public class PatientPK implements java.io.Serializable {
2.
3.     private String firstName;
4.     private String lastName;
5.     private String dateOfBirth;
6.     private Char sex;
7.
8.     public PatientPK() {}
9.
10.   public PatientPK(String firstName, String lastName, Date dateOfBirth, Char sex)
11.   {
12.       this.firstName = firstName;
13.       this.lastName = lastName;
14.       this.dateOfBirth = dateOfBirth;
15.       this.sex = sex;
16.   }
17.
18.   public String getFirstName() { return this.firstName; }
19.   public void setFirstName(String firstname) { this.firstName = firstName; }
20.
21.   public String getlastName() { return this.lastName; }
22.   public void setLastname(String lastName) { this.lastName = lastName; }
23.
24.   public String getDateOfBirth() { return this.dateOfBirth; }
25.   public void setDateOfBirth(String dateOfBirth) { this.dateOfBirth = dateOfBirth; }
26.
27.   public Char getSex() { return this.sex; }
28.   public void setSex(String sex) { this.sex = sex; }
29.
30.   public boolean equals(Object obj)
31.   {
32.       if (obj == this) return true;
33.       if (!(obj instanceof PatientPK)) return false;
34.       PatientPK pk = (PatientPK) obj;
35.       if (!firstName.equals(pk.firstName)) return false;
36.       if (!lastName.equals(pk.lastName)) return false;
37.       if (!dateOfBirth.equals(pk.dateOfBirth)) return false;
38.       if (!sex.equals(pk.sex)) return false;
39.       return true;
40.   }
41.
42.   public hashCode()
43.   {
44.       return firstName.hashCode() + lastName.hashCode() + dateOfBirth.hashCode() + sex.hashCode();
45.   }
46.}Please advice whether both these equals() and hashCode() implementations are correct.
Thanks in advance,
Jack

Similar Messages

  • How can i call a main method  from a different class???

    Plzz help...
    i have 2 classes.., T1 and T2.. Tt2 is a class with a main method....i want to call the main method in T2......fromT1..is it possibl..plz help

    T2.main(args);

  • How to interpret result of outcode method of Rectangle2D.Double class

    I am trying to use Rectangle2D to determine position of a point with respect to a given rectangle.
    Here is my code
    Rectangle2D.Double rect = new Rectangle2D.Double(10,10,50,50);
              System.out.println(rect.outcode(10,10));
              System.out.println(rect.outcode(10,9));
              System.out.println(rect.outcode(9,10));
              System.out.println(rect.outcode(50,50));
              System.out.println(rect.outcode(60,60));
              System.out.println(rect.outcode(61,10));
              System.out.println(rect.outcode(61,61));
              System.out.println(rect.outcode(61,45));
    Here are the results
    0
    2
    1
    0
    0
    4
    12
    4
    I can understand when result is 0 then the point is either inside or on the Rectangle2D.Double object
    I can assume if output is 1,2 3 or 4 it can be mean out_left, out_top, out_right, out_bottom but sometimes i get values like 5,9, 12 etc which I cannot figure out. What I can assume for these values
    Any pointer to this will be helpful
    Thanks Shantanu

    Any time you see constants defined in powers of two you can suspect
    that they may be added to form unique sums.
    So these, found in the Constant Field Values of Rectangle2D
    public static final int OUT_BOTTOM = 8
    public static final int OUT_LEFT   = 1
    public static final int OUT_RIGHT  = 4
    public static final int OUT_TOP    = 2may indicate that something like this is possible/useful:
    OUT_TOP                =  2    // N
    OUT_TOP + OUT_LEFT     =  3    // NW
    OUT_LEFT               =  1    // W
    OUT_LEFT + OUT_BOTTOM  =  9    // SW
    OUT_BOTTOM             =  8    // S
    OUT_BOTTOM + OUT_RIGHT = 12    // SE
    OUT_RIGHT              =  4    // E
    OUT_RIGHT + OUT_TOP    =  6    // Ne
    CENTER                 =  0    // inside

  • How to write this assignment in oom way(long)

    i try to write a new class, but i am not very sure if there is only one new class, I shall write a Movie class or a Ticket class?
    this is my Movie class, if I also want to write a new Ticket class. and still i don't know how to write
    because the Ticket class uses some of the attributes of the Movie class such as start time, Movie.name, as in this situation the relation
    between Ticket and Movie is still aggregation, or become a generalization?
    and how to represent that a Movie can have many Tickets? I shall write a buy-ticket method inside the Ticket class or Movie class.
    (are there any thing not right with this movie class? thanks)
    ============================
    class Movie
         String name;
         String startTime;
         String [] coupleChair=new String[11];//start from 1 to 10
         String [] singleChair=new String[11];//start from 1 to 10     
         public Movie(String str1st)
              this.name=str1st;
         public Movie(String str1st, String str2nd)
              this.name=str1st;
              this.startTime=str2nd;
         public String buyA_Single_Ticket()
              int i=1;
              do
                   if(this.singleChair!="sold")
                        this.singleChair[i]="sold";
                        return "You seat is Single Seat No."+i+"\n Enjoy the movie :)";
                   else i++;
              while(i<=10);//when i==11 jump out
              return "Sorry, all Single seats have been sold Out";
         public String buyA_Couple_Ticket()
              int i=1;
              do
                   if(this.coupleChair[i]!="sold")
                        this.coupleChair[i]="sold";
                        return "You seat is Couple Seat No."+i+"\n Enjoy the time ;)";
                   else i++;
              while(i<=10);//when i==11 jump out
              return "Sorry, all Couple seats have been sold Out";
    }//end class
    ============================
    this is the question
    A small ABC cinema has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a Java application to assign seats on each movie show on the day (capacity: 20 seats for 1 movie).
    Your program should display the following alternatives: ��Please type 1 for couple seat section�� and ��Please type 2 for normal seat section��. If the user types 1, your program should assign one seat in the couple seat section (seats 1 �C 10). If the person types 2, your program should assign a seat in the normal seat (seats 11 �C 20). Your program should also prompt for the movie time and movie name.
    Your program should then display:
    I.     The person��s seat number
    II.     Whether it is a couple seat or normal seat of the cinema
    III.     Time, date, movie name
    Your program should never assign a seat that has already been assigned. When the normal seat section is full, your program should ask the person if it is acceptable to be placed in the couple seat section (and vice versa). If yes, make the appropriate seat assignment. If no, print the message ��Next show is in 3 hours time.��
    (it is just a small test on my OOM learning, I know it is not necessary to make it so complex.)

    Break down your problem into discrete chunks. The more you practice this, the more your initial thoughts will resemble the eventual objects that you will create.
    Let's take address a few of your issues:
    What has the start time? Is it the ticket or the movie? (Hint: Would someone ever print you out a ticket with a different start time than the movie's?)
    If ticket and movie share some attributes, then you can either use inheritance or composition/delegation. In this instance, what makes more sense to you? Is a ticket a movie or vice versa? Or is a ticket simply related to a movie?
    If a given object can contain several instances of another object, you will want to use either an array or a collection, probably List in this instance.
    Why is there no Theater object? A movie may play at multiple theaters. Each theater has a capacity (in terms of total seats and number already booked). This does not really have anything to do with the movie. It is the Theater that you are booking. It may also have which movies are showing at which time.
    Your notion of 'couple' booking seems strange. Why not have a concept like 'consecutive seats required'? That way, your design is more flexible and you can still accomodate couples.That should get you started. Best of luck.
    - Saish

  • How to refer to enclosing instance from within the member class?

    Hi
    How to refer to the enclosing instance from within the member class?
    I have the following code :
    import java.awt.*;
    import java.awt.event.*;
    public class MyDialog extends Dialog
         public MyDialog(Frame fr,boolean modal)
              super(fr,modal);
              addWindowListener(new MyWindowAdapter());
         public void paint(Graphics g)
              g.drawString("Modal Dialogs are sometimes needed...",10,10);
         class MyWindowAdapter extends WindowAdapter
              public void windowClosing(WindowEvent evt)
                   //MyDialog.close(); // is this right?
    In the above code, how can I call the "close()" method of the "Dialog" class (which is the enclosing class) from the inner class?
    Thanks in advance.
    Senthil.

    Hi Senthil,
    You can directly call the outer class method. Otherwise use the following way MyDialog.this.close(); (But there is no close() method in Dialog!!)
    If this is not you expected, give me more details about problem.
    (Siva E.)

  • Calling a method from a different class?

    Ok..
    I been trying for hours... but im stumped.
    How can I get this to work?
    (Note: I cut this code down from over 600+ lines of code.. I left in a REALLY raw framework that shows where the basic problem is.)
    public class Client extends JPanel implements Runnable {
    // variable declarations...
        Socket connection;
        BufferedReader fromServer;
        PrintWriter toServer;
        public Client(){
    // GUI creation...
    // Create the login JFrame
        Login login = new Login()
        public void connect(){
        try {
                //Attempt to connect to the server
                connection = new Socket(ip,port);
                fromServer = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                toServer = new PrintWriter(connection.getOutputStream());
                //Launch a thread here to read incoming messages from the server
                //so I dont block on reading
                new Thread (this).start();
        } catch (Exception e) {
            e.printStackTrace();
        public void run(){
            // This keeps reading lines from the server
            String s;
            try {
                //Read messages sent from the server - add them to chat window
                while ((s=fromServer.readLine()) != null) {
                txtChat.append(s);
            } catch (Exception e) {}
        public static void main(String args[]){
            // some init frame stuff
            frame = new JFrame();
            frame.getContentPane().add(new Client(),BorderLayout.CENTER);
         frame.setVisible(true);
    class Login extends JFrame {
        JPanel pane;
        public Login() {
         super("Login");
         pane = new JPanel();
         JButton cmdConnect = new JButton("Connect");
            pane.add(cmdConnect);
         setContentPane(pane);
         setSize(300,300);
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         cmdConnect.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent ae){
              // I want to connect to the server when this button is pressed.
              // How can I call the connect method in the Client class?
    }

    Your posted code shows Login as an inner class. So one way to solve your problem is.
    1. Make an instance variable to hold the instance. For example, after "PrintWriter toServer;" add "private Client client;"
    2. In the Client constructor, add a line "client = this;"
    3. In the Login actionPerformed(), use "client.connect();"
    Another way is to have Login keep a reference to the Client that created it.
    1. Add an instance variable to Login "private Client client;"
    2. Change the Login constructor "public Login(Client c) {"
    3. Add a line in the constructor "client = c;"
    4. In the actionPerformed() "client.connect();"

  • How to write logout method

    hi
    how to write logout method..... i am new to programming
    protected void logOut(){
    asap

    When I posted my first reply, I was thinking of writing to an output log. Do you mean "logout" like in web applications???
    You don't need to write any special code for that. At the most, you would want to clean up the resources like connections, sockets,... created by the application. If you have some mechanism which retains some "login" information, you might reset it to some default value.
    Why don't you be specific with your question instead of writing in such a vague manner?

  • Dunno how to write JSP for login in......

    Can someone help mi on write JSP coding for login in page?i dun really know how how to write JSP coding. i m now doing a project on Private Driving instructor portal where people can register as trainee or instructor.now i want to write the JSP coding on the login page part.... when instuctor login it will go to a instructor's main page n if a trainee login it will go to a trainee's main page.Can someone help mi on this??? it's very urgent n important for mi.Please help mi.

    The easiest method I have found is to use a database to store the users details along with a flag indicating whether they are a trainee or an instructor. Upon logging in, you can use a bean to connect to the database and retrieve these values, then it is a simple matter of a jsp:forward tag to re-direct to the applicable page for trainee or instructor ...
    e.g.
    <pre>
    ***JSP PAGE ***
    <%@page language="java" buffer="32kb" import="jspclasses.customer.*" errorPage="./error.jsp"%>
    <jsp:useBean id="userBean" class="jspclasses.userInfoBean" scope="session"/>
    * Get user and pass from form variables. (if passed)*
    String user = request.getParameter("username");
    String pass = request.getParameter("password");
    * Retrieve fullname from session object. (if exists)*
    fullname = (String)session.getValue("fullname");
    String fwdPage = (String)session.getValue("fwdPage");
    if (fullname==null) {
         try {
         * If no session has been established then attempt to create one using *
         * the values passed through via form. If no values have been passed *
         * through then variables will equal null as opposed to empty strings. *
         * If null is evident, catch with NullPointerException. *
              if (user.equals("") || pass.equals("")) {
                   fullname = "Not";
              } else {
                   * Send values to method which validates users *
                   userBean.setUserInfo(user,pass);
                   * If an error was encountered within userBean the error *
                   * instance variable will != null. *
                   if (userBean.error == "") {
                        fullname = userBean.getFullname();
                   } else {
                        * Error was encountered so we set fullname to "Not", if *
                        * user was entered we re-display value and we instantiate *
                        * error variable to error value of userBean. *
                        fullname = "Not";
                        if (user!=null) uservalue=user;
                        error = userBean.error;
                        //out.println("Error is not null:<br>"+error+"<br>");
                   if (fullname!="Not") {
                        session = request.getSession(true);
                        session.putValue("fullname",fullname);
                        session.putValue("email",user);
                        session.putValue("user_id",userBean.getUserId());
                        session.putValue("user_type",userBean.getUserType());
                        session.putValue("sessionid",session.getId());
                        session.setMaxInactiveInterval(12000);
    ***END JSP***
    *** START BEAN ***
    public void setUserInfo(String user, String pass) {
    String stmtString = "";
    ResultSet rs = null;
    // Check to see if a valid connection is available
    getConnection();
    // If getConnection returns null then
    // connection successfully established
    if (error.equals("")) {
    try {
    // Create SQL string to be sent to database
    stmtString = "select * from serv_user where email = '" + user + "' and password = '" + pass + "'";
    // Execute SQL
    rs = stmt.executeQuery(stmtString);
    // Specify estimated rows to be returned
    rs.setFetchSize(1);
    // If a row is returned get first and last name
    if (rs.next()) {
    user_id = ((rs.getString("USER_ID")!=null)?rs.getString("USER_ID"):"");
    ("USER_TYPE_ID"):"");
    first_name = ((rs.getString("FIRST_NAME")!=null)?rs.getString("FIRST_NAME"):"");
    last_name = ((rs.getString("LAST_NAME")!=null)?rs.getString("LAST_NAME"):"");
    business = ((rs.getString("BUSINESS_NAME")!=null)?rs.getString("BUSINESS_NAME"):"");
    address = ((rs.getString("ADDRESS")!=null)?rs.getString("ADDRESS"):"");
    suburb = ((rs.getString("SUBURB")!=null)?rs.getString("SUBURB"):"");
    state = ((rs.getString("STATE")!=null)?rs.getString("STATE"):"");
    postcode = ((rs.getString("POSTCODE")!=null)?rs.getString("POSTCODE"):"");
    hom_phone = ((rs.getString("HOM_PHONE")!=null)?rs.getString("HOM_PHONE"):"");
    bus_phone = ((rs.getString("BUS_PHONE")!=null)?rs.getString("BUS_PHONE"):"");
    mob_phone = ((rs.getString("MOB_PHONE")!=null)?rs.getString("MOB_PHONE"):"");
    fax = ((rs.getString("FAX")!=null)?rs.getString("FAX"):"");
    email = ((rs.getString("EMAIL")!=null)?rs.getString("EMAIL"):"");
    pass_hint = ((rs.getString("PASSWORD_HINT")!=null)?rs.getString("PASSWORD_HINT"):"");
    else {
    error = "User <b>"+user+"</b> does not exist with specified password.<br>Please try again.";
    } // END : ResultSet = true
    } // END : TRY
    catch (SQLException sqle) {
    error = "<b>Error accessing database:</b><br> "+sqle.toString()+" - ORA:"+sqle.getErrorCode();
    catch (Exception e) {
    error = "<b>Error occurred in method setUserInfo()</b><br> "+e.getMessage();
    } // END : CATCH
    finally{
    closeConnection();
    try{
    rs.close();
    }catch(SQLException sqle){
    } // END : IF
    } // END : METHOD
    } // END : BEAN
    ***END BEAN***

  • How do I create a new method?

    My application has the following code in one class:
    private void updateSexField() {
    String chosen = textChoice.getSelectedItem(); String theSex = theData.lookupSex(chosen);
    sexField.setText(theSex);
    private void updateAgeField() {
    String chosen = textChoice.getSelectedItem();
    String theAge = theData.lookupAge(chosen);
    ageField.setText(theAge);
    and this code in the other class:
    public String lookupSex(String text) {
    for (int i = 0; i <= top; i++)
    if (text.equals(person.getSurname()))
    return person[i].getSex();
    return ("error");
    public String lookupAge(String text) {
    for (int i = 0; i <= top; i++)
    if (text.equals(person[i].getSurname()))
    return person[i].getAge();
    return ("error");
    The idea is that the correct sex and age, corresponding to a particular person (with a particular 'Surname') are returned back (or 'got'). Thes items are then placed in a text field in my program. There is actually several things being 'got' (only two are listed here but the code is identical). The big question is - How can I adjust the program so that a single method (or two) can perform each of these functions without having to write out the code over and over for each thing I want 'got', if you know what I mean.
    Any advice, based on this limited description, would be much appreciated.
    Cheers,
    DJPesto

    class Person {
        private final Hashtable attributes = new Hashtable();
        Person(String age, String sex) {
            attributes.put(PersonAttributes.AGE, age);
            attributes.put(PersonAttributes.SEX, sex);
        public Object getAttribute(PersonAttributes key) {
            return attributes.get(key);
    class PersonAttributes {
        // this class implements a typesafe enum pattern
        // that can be used as keys in a Hashtable
        private final String attribute;
        private PersonAttributes(String atribute) {
            this.attribute = attribute;
        public String toString( ) {
            return attribute.name;
        public boolean eqauls( ) {
            return attribute.equals();
        public int hashCode( ) {
            return attribute.hashCode();
        public static final PersonAttributes AGE =
            new PersonAttributes("AGEATTRIB");
        public static final PersonAttributes SEX =
            new PersonAttributes("SEXATTRIB");
    }

  • How to write a sql query to retrieve data entered in the past 2 weeks

    Hi,
    I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
    Thanks in advance.

    This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
    Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
    I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate".

  • Can anyone share with me how you  write Javadoc?

    Can anyone share with me how their companies write Javadoc?
    Are your developers solely responsible for it? Do your technical writers own it or review it? How do you make sure it's good?
    Right now, my software developers are mostly responsible for writing all the API info and it's of poor quality and really lacking details. I don't mean spelling/grammar-type problems. My developers just don't seem to "get" what information to include, no matter how many guidelines or checklists I give them.
    A very simple example is:
    * Gets the status
    public java.lang.Integer getStatus() {...}With no indication of what status values may be returned and what the values might mean.
    How do you ensure that what you write is actually useful? Please help!
    I'm aware of the method Sun recommends, but I want to know what others do.
    Thank you

    Hi,
    Well, concerning the question what a good API documentation should be. Just imagine, you are a programmer and you want to use that API. You need to know how it works. There can be only three ways to find it:
    (1) The API documentation
    (2) Probing experiments. Even a good documentation may not describe everything. Sometimes, the only way to understand certain things you particularly need may be guessing something, writing a code basing on it and see how it works. Then, guessing something again, more precisely now, and so on. Even a very good documented API (for instance, javax.swing) may require that sort of approach to be able to use it eventually.
    (3) At last, when source codes are available, one may look at them and try to understand precisely, what a particular method actually does.
    I think the better the API documentation the less one may need to endeavor those two last steps. There is actually a limit about it. Without any proper explanation at all, one may never be able to use a particular API, neither after probing it nor after looking at source codes (that is not to say the sources may be simple unavailable at all).
    Concerning how to write the API documentation, that's mostly the question of managing your team. I think, basically, the original source of the ultimate information about everything implemented in the projects are those very programmers (developers) and, probably, some software architects. But those guys normally are not especially eager to write any documentation (especially developers). That your example just demonstrates it. It seems, your programmers just wrote that "Gets the status" for you to make them leave in rest after that. In addition, the programmers normally have such a sort of work and activity that does not match particularly well with the writing literature and doing their main job simultaneously. You should not enforce them to do that!
    To write a good documentation, you will need to engage a technical writer. That's normally a guy with some programming background. However, writing some literature is actually what he does the best. (Sometimes, such people do something else about written word beyond the technical writing.) The job of that guy would be to write the documentation. This will take from him (or her) two basic things:
    (1) The ability to understand the whole software system (that's where his programming background will be needed!);
    (2) To communicate with the programmers who have developed the stuff and to obtain from them all the necessary information they know. That may require some personal (verbal) communication with them, because asking them to write everything again will only result in the same "Gets the status" explanations. However, to be successful in this, the technical writer needs to have some explicit management approval behind him. Otherwise, some of the guys will avoid speaking to him at all (saying they lack the time). So, the management should assign them the necessary priority for such communications.
    Particularly big projects may even need to have the whole team of technical writers.
    Anyway, writing docs is a hard work. But it is extremely important! The good documentation may both increase your sales and eliminate lots of expense on further support of your customers.
    Regards,
    Leonid Rudy
    http://www.docflex.com

  • How to write an element in a  JTable Cell

    Probably it's a stupid question but I have this problem:
    I have a the necessity to build a JTable in which, when I edit a cell and I push a keyboard button, a new Frame opens to edit the content of the cell.
    But the problem is how to write something in the JTable cell, before setting its model. Because, I know, setCellAT() method of JTree inserts the value in the model and not in the table view. And repainting doesn't function!
    What to do??
    Thanks

    Hi there
    Depending on your table model you should normally change the "cell value" of the tablemodel.
    This could look like:
    JTable table = new JTable();
    TableModel model = table.getModel();
    int rowIndex = 0, columnIndex = 0;
    model.setValueAt("This is a test", rowIndex, columnIndex);
    The tablemodel should then fire an event to the view (i.e. JTable) and the table should be updated.
    Hope this helps you

  • How to write data to an XML file present under application server

    frnds: can ne one tell me, how to write data in to a file, which is present under a application server
    Ex: i want to write a string data in to a file test.txt which is present under "http://localhost:8080/<some_webapp>/test.txt"
    Note:i have deploted a service<some_webapp> under Tomcat/webapps dir

    Very simple. A servlet can writes to that file if it has the good rights.
    In the servlet get (or post) method, use a code like this:
    import java.io.*;
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
    try {
    String filePath = this.getServletContext().getRealPath("/text.txt");//See http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletContext.html#getRealPath(java.lang.String)
             PrintWriter writer = new PrintWriter (filePath);
            //or BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
            writer .println("aString");
           writer.flush();
            writer .close();
        } catch (Exception e) {
           e.printStackTrace();
    }Hope That Helps

  • How to throw exception in run() method of Runnable?

    Hi, everyone:
    I want to know how to throw exception in run() method of interface Runnable. Since there is no throwable exception declared in run() method of interface Runnable in Java API specification.
    Thanks in advance,
    George

    Thanks, jfbriere.
    I must add though that if your run() methodis
    executed after a call to Thread.start(), then
    it is not a good choice to throw anyRuntimeException
    from the run() method.
    The reason is that the thrown exception won't be
    handled appropriately by a try-catch block.Why do you say that "the thrown exception won't be
    handled appropriately by a try-catch block"? Can you
    explain it in more detail?
    regards,
    George
    Because the other thread runs concurrently with and independently of the parent thread, there's no way you can write a try/catch that will handle the new thread's exception: try {
        myThread.start();
    catch (TheExceptionYouWantToThrowFromRun exc) {
        handle it
    do the next thing This won't work because the parent thread just continues on after myThread.start(). Start() doesn't throw the exception--run() does. And our parent thread here has lost touch with the child thread--it just moves on to "do the next thing."
    Now, you can do some exception handling with ThreadGroup and uncaughtException(), but make sure you understand why the above won't work, in case that was what you were planning to do.

  • How to write-ups in Asset accounting?

    Let me give a senario first:
    asset APC : 10000 $
    capitalized and APC date: 2000/01/01 (YYYY/MM/DD)
    old depreciation method: straight-line, 10% rate, useful life is 10 years.
    Now suppose the time is 2002/01/01, company changes the asset useful life to 5 years, in the aim of completely depreciate the asset 3 years later, the problem is the net value of that asset is 8000 $ by the old depreciation method.
    new depreciation method: straight-line, 20% rate, useful life is 5 years.
    To make the new method possible, the net value of that asset should be 6000 $ now, which means I need to manually post the 2000 $( 8000-6000) as write-ups. I define a new depreciation area and a new transaction type( write-up for new method) in the system, but when I execute T-code ABZU, two messages pop up, one is that " you can not post write-ups " , another is " Contact your administrator (table error) ", detail information below:
    <i><b>1.</b></i>You cannot post write-ups
    Message no. AA402
    Diagnosis
    None of the areas to be posted in accordance with the transaction type entered manages one of the depreciation types entered or cumulative values.
    Procedure
    Check the transaction type.
    <i><b>
    2</b></i>
    Contact your system administrator (table error)
    Message no. AA380
    Diagnosis
    Inconsistency between the specifications for transaction type 700 and for the depreciation areas in chart of depreciation SHDE.
    Depreciation area 32 is defined (in Customizing), so that it is required to take over values from area 01.  However, one of these ares cannot be posted to, due to the specifications in transaction type 700.  This combination is not allowed.
    Procedure
    In Asset Customizing, maintain the specifications in transaction type 700 for the depreciation areas that can be posted using this transaction.
    I want to know whether using write-ups to deal with this business senario is right or not ? And if it's the right way , how to solve the aforementioned problems and make it happen?
    Thanks in advance and points will be awarded to those who give the leads.

    Hi,
    I am having the same error which you have posted, please let me know if you have any sujections.
    I have this error when i try to post write-up in ABZU
    You cannot post write-ups
    Message no. AA402
    Diagnosis
    None of the areas to be posted in accordance with the transaction type entered manages one of the depreciation types entered or cumulative values.
    Procedure
    Check the transaction type.
    So please help me in solving this. Thanks in advance

Maybe you are looking for

  • Is there a way to convert files incompatible with Apple OS to some format that will be viewable in Finder?

    I do a lot of machine embroidery. In moving from a PC to Mac, I've learned that none of my current embroidery software is compaitible with Apple OS. I'm happy to maintain those programs on a Windows laptop, but would really like to be able to view my

  • Pen drive + mov = ??

    exported a movie from final cut express up at school and put It on my flash drive. I got home and tried to copy it to my mac and it said insuficient privelages. Then ejects the drive. I try using vlc, fce, and fcp but to up avail. I bet that if I try

  • How to convert an Interactive report to ALV report..please give a example..

    Hi experts, How to convert an interactive report to ALV report..plz suggest me an example... thanks in advance, Varsha.

  • 2011 i7 Macbook Pro with Windows 7 SP1, can't get it to work

    2.2 GHz Macbook Pro 2011 17 inch OCZ Vertex 3 Mac OS X 10.6.8 2nd HD instead of optical drive I bought a downloadable version of Windows 7 SP1 from Microsoft and burned it to a disk. I have tried probably 25 times to install via Bootcamp, but I alway

  • HTA Tools?

    Are there any HTA tools written with PowerShell?   I want to create a custom HTA file within CM2012 to do our Windows 7 deployment and I know PowerShell so I wanted to use a PS HTA.    And either way can any of you direct me to a useful HTA tool?   m