Java newbie help (type casting, 64bit unsigned Long)

Hi I am java newbie and need help on my project. I have a few questions. Can you put strings in a hashtable and test for their being their with the appropriate hashtable method? I want to test for equal strings, not the same object. Second question can you use all 64 bits of an unsigned long? java doesn't seem to allow this. Any packages that do?
Thanks,
Dave

Try casting it to Long instead of long. Long (capital L) is an Object, while long (lower case l) is not. You may also check to make sure the value isn't null. I would have thought that autoboxing would have worked here unless the value was null. But I am no expert on autoboxing.
Edit >> Checking for null ain't a bad idea but has nothing to do with the problem - this is a compile time problem. Sorry.
Also>> This code should work:
long cTime=(Long)session.getAttribute("creationtime");Edited by: stevejluke on Jul 1, 2008 11:00 AM

Similar Messages

  • Java newbie help: Need to change a graphic on screen

    Hello everyone. I'm a long time C/C++ programmer, and I've been thrust into the Java world when I inherited an incomplete project. If something I mention later on sounds stupid, it's probably because it came that way, or I'm trying to force it into what I know from old experience.
    FWIW, the project is being developed with Netbeans.
    What I'm after is how to change a graphic object onscreen from within the code, vs. with a device such as a mouse. I'm trying to emulate an LED indicator.
    What I've done so far is to try using the enable state, and defining GIFs to display. That didn't work.
    I've switched gears a bit, and tried something similar with the selected property, but that will only work if I hit the item with my mouse and click. Also, the item is defined as a jToggleButton.
    In general terms, what do I need to do to set this up for the displayed item to change without device input? I've been reading stuff about Buttons, ToggleButtons, Graphics, Images, and Icons, and I'm waaaaaay lost right now.
    To add to the frustration is that I've done something similar with Visual C++, and that worked as intended. Harumph.
    Help?!?

    FWIW, the project is being developed with Netbeans.
    In case you don't know, you can use any editor to develop java code.
    What I'm after is how to change a graphic object onscreen from within the code, vs. with a device such as a mouse. I'm trying to emulate an LED indicator.
    What I've done so far is to try using the enable state, and defining GIFs to display. That didn't work.
    What happend?
    I've switched gears a bit, and tried something similar with the selected property, but that will only work if I hit the item with my mouse and click. Also, the item is defined as a jToggleButton.
    Is this not what you wanted?

  • Help needed in data type casting

    I have a java program which will receive data and its type in the String format. During program execution, the data in the String data has to be converted into the respective data type and assigned to a variable of that data type so that it could be used in the program. Programmer may not know the type of data that the value has to be converted into.
    I really got struck up with this. This is a RMI application and one process node is sending the data to another node in the String format and the type of data it should get converted into so that it can be converted into the respective type and used for computation.
    Can you understand what I am asking for ....if you can pls help and it is highly appreciated

    I dont know whether i ahve expressed it correctly
    look at this code
    dataPacket sendtoNode = send.senDatatoNode(inputReq);
    String recnodnum = sendtoNode.nodeNum;
    String recvarnum = sendtoNode.varNum;
    String recvartype = sendtoNode.dataType;
    String recvalvalue     = sendtoNode.dataVal;
    int num;     int type;
    double result;
    // here in this case the result variable type is double
    if (recvartype.equals("int")){
              type = 1;
         result = Integer.parseInt(recvalvalue); will pose problem
         else
         if (recvartype.equals("double")){
              type = 2;
              result = Double.parseDouble(recvalvalue);
         else
         if(recvartype.equals("float")){
              type =3;
              result = Float.parseFloat(recvalvalue); will pose problem
         else
         if(recvartype.equals("Boolean")){
              if ((recvalvalue.equals("true")) || (recvalvalue.equals("TRUE")))
              type = 4;
              result = Boolean.parseBoolean(recvalvalue); will pose problem
         else
         if(recvartype.equals("char")){
              type = 5;
              result = (char)recvalvalue; will pose problem
    else
    if(recvartype.equals("String")){
         type = 6;
              result = recvalvalue; will pose problem
         else
         if(recvartype.equals("byte")){
              type = 7;
              result = Byte.parseByte(recvalvalue); will pose problem
         else
         if(recvartype.equals("long")){
              type = 8;
              result = Long.parseLong(recvalvalue); will pose problem
         else
         if(recvartype.equals("short")){
              type = 9;
              result = Short.parseShort(recvalvalue); will pose problem
         //forvarval varvalue = new forvarval();
         //varvalue.forvarval(recvartype, recvalvalue);
    // this has to be done after sorting the problem of type casting string result = recvalvalue;
    //result = value; //<this will surely give me a problem as i m assigning string to double>??
    send.host(result);
    System.out.println("result received and the result is " +recvalvalue );
    now i need to assign the converted string in to a variable and use in the compuation ..thts where the challenge n not in teh conversion process...

  • Unsigned Long in java

    Hi all,
    I have a code in C which i want to convert into java.. Iam facing problem because java does not support
    unsigned long.The code in c look like this:
    WCD.cardno = ( SerBuf[3]* 0x00010000UL+
    SerBuf[4]* 0x00000100UL+
    SerBuf[5]* 0x00000001UL);
    I want to convert this code into java. What i have done is something like this
    cardno = (tempBuffer[3]*0x01000000 + tempBuffer[4]*0x00010000 + tempBuffer[5]*0x00000100 +tempBuffer[6]*0x00000001);
    Can anyone help me out. This program is for serial port implementation.
    Thanks
    Kiran

    kiranJNI wrote:
    Basically how can we achieve unsigned long in java???In your case, this isn't going to be a problem for two reasons.
    AFAIK, there aren't any numbers where multiplying them as unsigned numbers is going to be different from multiplying them as signed numbers and still give a valid result. To make this easier, let's work with signed vs unsigned bytes. Negative numbers are those in the range 0x80 to 0xFF; these are the only numbers where the "value" of the byte differs between signed and unsigned. Now think of those numbers as unsigned numbers. The only unsigned numbers you could multiply them by and still remain within the range of a byte are 0 and 1. If you multiply by 2, the result is 0x100, which is larger than what a byte can represent. If the result will remain within the range of the data type, it don't think there are any numbers where signed and unsigned multiplication return a different bit pattern.
    Furthermore, your example doesn't even need multiplication. You're multiplying by powers of 2, so all you really need is a series of shifts and adds.

  • Urgent::Unsigned Long Requirement::Oracle Number(38) to Java conversion

    Hi,
    I have a Oracle field configured as NUMBER(38). The number in that field gets incremented sequentially and is currently around 5345232341.
    I am using callableStatement.registerOutParameter(1,java.sql.Types.INTEGER); which is working fine.
    But the problem happens when I am trying to retrieve the value and store it within my Program.
    I am using 'long' to do that but I presume I will hit a problem when the number crosses 9223372036854775807 (2^63-1). As we don't have unsigned long option in Java(unlike in C/C++), how do we achieve this? Please can somebpdy tell me the workaround.
    Currently, I am storing it as follows:
    long my_number = callableStatement.getInt(1);

    Currently, I am storing it as follows:
    long my_number = callableStatement.getInt(1);While reading the docs, you should probably also read about getInt(), because your current code is buggy.

  • JAVA primitive data types - Signed/ unsigned etc.

    1. Are the following data types signed or unsigned in JAVA?
    byte, short, int, long, float, double
    2. I have tried using "Integer" in place of "int" and the program runs perfectly. Why is this so when "Integer" is not a reserved word in JAVA?
    Thanks.

    And to answer your first question, byte, short, int, long, float and double are all signed.
    As a part of the core of the language, Sun developed a series of 'collections' classes; Vector, ArrayList, etc. All of these classes, in the days before generics, were able to store instances of the Object class or anything that derived from it. Therefore, to store an int, a float or a double value into one of these collections classes, it was necessary to wrap it up in an instance of one of those classes that derived from Number. These are the wrapper classes that the previous poster alluded to. Typically, the wrapper class has a similar name to the primitive data type but with a capital latter; int - Integer, double - Double, etc.

  • Could not type cast in java embedding

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    org.xml.sax.InputSource in = (org.xml.sax.InputSource) getVariableData("Invoke_1_getRoutingAndFrameJumpers_OutputVariable","getRoutingAndFrameJumpersResponse");
    Document doc = db.parse(in);
    In the above code I am trying to type cast the variable getRoutingAndFrameJumpersResponse into org.xml.sax.InputSource so that i can parse.
    I am not getting any error during compilation
    but I am unable to type cast some run time error is coming in the line were I am type casting but I am not able to see the runtime error.
    How can I see the runtime error in java embedding, how to type cast a variable into xml so that I can parse it.

    Hi Arun,
    Could you try using the bpelx:rename extension in an assign activity enables a BPEL process to rename an element through use of XSD type casting.
    <bpel:assign>
    <bpelx:rename elementTo="QName1"? typeCastTo="QName2"?>
    <bpelx:target variable="ncname" part="ncname"? query="xpath_str" />
    </bpelx:rename>
    </bpel:assign>
    Cheers
    A

  • Do week-long java courses help to understand java &  get a job?

    i tried searching for this topic before posting, but "courses" "classes" & "instruction" come up with a lot that has nothing to do with the topic at hand. :)
    like many others, i'm teaching myself out of a book (Deitel). so far i've been able to understand the material and create programs based on the exercises. however, i'm now into the meat of OOP with superclass, subclasses, how they interact and the like and i'm having a rough go of it. i can diagram and understand the abstract concept, but when i'm faced with an actual program example i have a difficult time following the interactions between classes.
    i'm considering taking one of those 5 day classes, but am wary of how much they will actually be able to cover in detail (not to mention the $$). has anyone here taken one of those classes and found them to be of great benefit to learning the OOP portion of Java? did it give you enough understanding to obtain an entry-level job?
    btw, i'm doing a pro bono project for a small company to get some real world experience. (i've heard that suggestion many times in regards to obtaining one's "experience" w/o a job)
    thank you all very much for your help.

    I took a week long course to learn Java. It worked I did learn the basics of Java but I did already know how to program in C and VB at the time. I found the AWT section of the class to be very valuable,cosidering I mostly write GUI. And the concepts of AWT mostly all apply to swing so that didn't set me back at all. Depending on the school it may help you to understand OOP. But be careful because most schools progress the class at the skill level of the majorty. So if you have 15 people in the class and 9 of them know nothing about programing your probably going to spend the week learning what a variable and a while loop do, you all pay the same tuition and they would rather 6 of you leave then 9 of you leave. If you have some prior programming knowledge I would recomend finding a class that caters to that.

  • Dynamic [Runtime] type casting in Java

    Hello,
    This is my requirement.
    I have a method that takes class name as a parameter.
    Ex:
    Object myMethod(String classname){
    Object xyz = getObject(); //userdefine method which returns some object
    /*<b>I need to typecast above object with the class name passed as the method parameter</b>*/
    /*<b>How can i type cast this object</b>*/
    Object obj = (classname) xyz;
    return obj;
    In the above example, how can i dynamically typecast the object with class whose name is passed as the method parameter?

    Hello,
    This is my requirement.
    I have a method that takes class name as a parameter.
    Ex:
    Object myMethod(String classname){
    Object xyz = getObject(); //userdefine method which
    returns some object
    /*<b>I need to typecast above object with the class
    name passed as the method parameter</b>*/
    /*<b>How can i type cast this object</b>*/
    Object obj = (classname) xyz;
    return obj;
    In the above example, how can i dynamically typecast
    the object with class whose name is passed as the
    method parameter?Perhaps a little more background on the project (what you are trying to do) will help the experts here answer?
    /*with a class that takes a noarg constructor*/
    public Object getObject(String classname) throws Exception
      //might want to get a bit more specific with which exceptions it will throw
      return Class.forName(classname).newInstance();
    }Do I think this sometimes is indicative (perhaps even more often than not), of a possible design flaw? Yes..
    It gets a little trickier if you have constructors (you have to create a Class object representing the string with the .forName(..) ..and then use some reflection to determine constructors and then a bit of logic to determine which of those to use...)
    ~Dave

  • Type casting in Java

    Hi,
    Can we do explicit type casting vigorously in a java class? Im in a situation that i've to do explicit casting 40 to 50 times in a class. Is there any overhead for JVM or any performance issue with this?

    Why do you cast so often? It's sounds like a weird design. Casting is pretty cheap.
    Kaj

  • Unsigned Long declaration in JAVA ?????

    Hi,
    Java doesnt allow unsigned declaration.
    I have a 'C' program which does the following:
    unsigned long someLongInteger; //in C
    someLong>>18;
    SomeLong<<14;
    SomeLong>>=14;
    When I did the same thing in JAVA by declaring someLongInteger as long, it gives me a different result.
    Is that because it is considering java Long as signed??
    Is there any work around this?
    I appreciate your reply
    Thank you.

    Depending on what you are trying to do, the unsigned right shift operator (>>>) may be of use for this situation.
    - K
    Hi,
    Java doesnt allow unsigned declaration.
    I have a 'C' program which does the following:
    unsigned long someLongInteger; //in C
    someLong>>18;
    SomeLong<<14;
    SomeLong>>=14;
    When I did the same thing in JAVA by declaring
    someLongInteger as long, it gives me a different
    result.
    Is that because it is considering java Long as
    signed??
    Is there any work around this?
    I appreciate your reply
    Thank you.

  • Java type casting interesting query

    In java semantics
    1) float var1=10.5; // is wrong it should be written as
    float var1=(float)10.5; //type casting->double to float
    or
    float var1=10.5f; //type casting
    but
    2) byte var2=10; // here int to byte type casting should be there according to previous eg.
    But this is correct.
    Why the 2nd one is correct???

    >
    I suspect the reason is, that the compiler can check whether it will fit in the second case.
    You can't accidentally type
    byte b = 128;Whereas with floating point numbers you could accidentally be losing precision, imagining that you're using doubles, when in fact you are using floats. So the extra cast is needed so you understand you're losing precision.

  • 64bit unsigned int - j????

    I have a 64bit unsigned int in a datastructure generated by a native method.
    What would be the best java type to cast it to, before returning the value?
    Thanks,
    Than

    BigInteger is the only java "datatype" that can handle this if you need to access the unsigned value within your Java code. None of the primitive datatypes will work as they are all signed.
    The other alternative is to split the integer into 2 4 byte words and store them both in jlongs

  • Parsing binary file- unsigned longs

    Hello everyone.
    I'm currently trying to write a quick parser for a binary file format (ASF). However, java's handling of bit shifting and lack of unsigned types is driving me completely mad.
    How can I represent an unsigned long?
    How can I set the bits for it anyway? It seems that the shift operator can't shift more than an int's worth (it just loops around and starts adding to the other bits- weird).
    Thanks in advance.
    Simon

    ejp wrote:
    But why in the world does the following code also do nothing?
    long x = 45 << 32;
    Try long x = 45L << 32;
    The answer appears to be that java uses ints to represent all constants, but this presents some serious problems- namely- how on earth do you get a number bigger than an int into a long?With 'L'. Same as in C or C++. In Visual Basic it's '&'. There's generally something.Where did that come from? Why have I never seen anything like that before?
    If I do long x = 0x7FFFFFFF; all is well, but if I do long x = 0x80000000; I get FFFFFFFF80000000, which isn't what I asked for.Actually it is exactly what you asked for. You've overlooked several facts: (i) Java longs are 64 bits; (ii) you specified a negative 32-bit constant; (iii) the rules of every programming language I can think of provide for sign-extension when going from a shorter to a longer type.Right. It makes sense now that I know how to specify long constants.
    As someone pointed out signed/unsigned is actually the same, so long as you interpret it correctly. So to avoid the total stupidity of using twice as much memory for everything I've decided that I am actually going to use the correct types.They're not the correct types. As I pointed out in an earlier post, your 'unsigned longs' must be coming from C or C++ where they are generally 32 bits, so using a 64-bit Java long is incorrect.Where they came from doesn't matter. The spec doesn't say it's a "long"- it says that this particular value is 64bit, and that all values are unsigned. So I do need a Java long.
    WHY IN THE WORLD IS JAVA "INTELLIGENT" WHEN DOING THINGS BITWISE? WHICH BRAIN DEAD IDIOT THOUGHT THAT UP? That is broken and is asking for trouble.It is you who is asking for trouble here. The rules of Java are consistent and in conformity with the practice in other programming languages. You've just overlooked several relevant facts.I think I've worked out where I was going wrong here. When doing something like
    int i;
    long x;
    x = x | i;The i is converted to a long before the bitwise operation, so it's not the bitwise operation that's the problem, it's the conversion between int and long?
    It's not Java whose stupidity is the issue here ;-)That wouldn't surprise me.
    Thanks.

  • Type Casting Exception

    I have an attribute CategoryId in my VO of type oracle.jbo.domain.Number. I am trying to use the expression of Boolean item in JHS as #{row.CategoryId != 4}
    Here is the generated JSF code:
                          <af:column id="s141NewItem3Col" noWrap="true" width="100"
                                     rowHeader="false">
                            <f:facet name="header">
                              <af:outputLabel value="CAtIDDeq4" showRequired="false"
                                              id="ol18"/>
                            </f:facet>
                            <af:inputText id="s141NewItem3"
                                          value="#{row.CategoryId != 4}"
                                          label="CAtIDDeq4" required="false"
                                          readOnly="#{((pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn']))) or ((!pageFlowScope.ContractRightCategoriesTable.newRow) and (!(jhsUserRoles['RM, ADMIN, AllButTitl, AllButAdmn'])))}"></af:inputText>
                          </af:column>I am getting the run time exception as "Can not convert 4 of type class oracle.jbo.domain.Number to class java.lang.Long"
    I am wondering how the row.CategoryId is treated as Long?. PLease advise. Also, will I be able to use type casting expressions in J Headstart/JSF Expression Language?
    Thanks, Pradeep

    I am trying to set disabled property of an item SubCategory dynamically based on CategoryId value. I guess the transient attribute will not work for newly created records as the transient attribute will be null for newly created records before save is performed. However, the expression #{row.bindings.CategoryId.attributeValue.value== 4 ? false : true} is working fine. row.bindings.CategoryId.attributeValue seem to be returning Long and, row.bindings.CategoryId.attributeValue.value might be returning a Number.

Maybe you are looking for

  • Stopping duplicate entries

    Post Author: snowmansmartie CA Forum: General Hi Guys, Ok I'm going to try my best to explain my situation.  I have written a report that links to a MySQL database which stores information about sales, in other words an invoicing/POS system. I have w

  • Not enough memory to run YAST

    Zen 6.5 sp2 I can neither PXE boot or boot from CD with any box that has an AMD processor. These also have Biostar motherboards. I get the following message "Your computer does not have enough memory to run YAST", machines have plenty of memory. Work

  • Clearcut image. distortion when importing into Aperture3

    I clear cut an image in PS then pasted it into a new transparent file. Reduced the image to 600 pixels high. Saved with "web and devices" with png-24 and transparency ticked. The preview looks perfect (see example). Hit save. Go to A3 and use the imp

  • Issue when opening cover

    I've had my MacBook Pro for 3 weeks now a love it.  However, I now have an issue. If I close the cover and reopen it later the screen comes on for a few seconds and then goes dark.  Up until now the screen stayed lit, I entered my password and I was

  • Using ABAP function calls in HANA

    Hi everyone, I am very new to the ABAP workspace. Is it possible to call ABAP function modules from the HANA database? We have a long raw field in a table that we would like to convert to text. Any help would be greatly appreciated! Thanks, Anu