A simple question from a beginner

how do i check for a null reference? eg:
String val = null;
// do some stuff with a hashtable...
// now want to check if val is still null
if (val.equals(null)) // this is where i get a NullPointer Exception
System.out.print ("val is still null!");
thanx in advance

if (val == null) ...

Similar Messages

  • Very simple question from a beginner

    I am currently doing a little exercise, but I ran into a problem. I have written a class that supports operations on rational number. The fields are two long variables, one each that stores the numerator and denominator.
    I have made add, subtract, multiply, and divide methods...
    1. what I need help in is: beingh able to store the rational number in reduced for, with the denominator always positive
    2. constructing a toString method, equals method, and compareTo method.
    3. it also says "make sure the toString method correctly handles the case in which the denominator is zero by throwing an exception.
    I have been working on this for a long time now, an I am stuck at this point.
    I know this will be very simple for you guys and gals, but I am a beginner. Please offer some input, advice, and/or some code to help me get past this problem.
    Thanks so much,
    Jason

    ok, here is what I have so far
    public class Rational {
         public long num, den;
         public Rational(long n,long d) {
              this.num = n;
              this.den = d;
         public static void main(String args[]) {
              Rational r = new Rational(1,2);
              Rational s = new Rational(3,4);
              Rational rmuls = r.multiply(s);
              Rational rdivs = r.divide(s);
              Rational radds = r.add(s);
              Rational rsubs = r.subtract(s);
              r.print();
              s.print();
              rmuls.print();
              rdivs.print();
              radds.print();
              rsubs.print();
         public void print(){
              System.out.println(this.num+ "/" +this.den);
         public Rational multiply(Rational t){
              long n;
              long d;
              n = this.num*t.num;
              d = this.den*t.den;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational divide(Rational t){
              long n;
              long d;
              n = this.num*t.den;
              d = this.den*t.num;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational add(Rational t){
              long n;
              long d;
              n = (t.den*this.num)+(t.num*this.den);
              d = t.den*this.den;
              Rational answer = new Rational(n,d);
              return answer;
         public Rational subtract(Rational t){
              long n;
              long d;
              n = (t.den*this.num)-(t.num*this.den);
              d = t.den*this.den;          
              Rational answer = new Rational(n,d);
              return answer;
         //public int compareTo (Rational t)??????

  • May be slightly simple question from a new Mac user: Why can't I quit safari? I cannot quit it from top menu bar neither to do it from dock? All other apps are working normally.

    May be slightly simple question from a new Mac user: Why can't I quit safari? I cannot quit it from top menu bar neither to do it from dock? All other apps are working normally.

    Or you can actived the right button on your magic mouse and click on they icon in the dock. then you select "stop" and it's out of your dock.
    Greetings
    *update: Sorry, my mistake! I didn't read your message correct! Sorry for the inconvience!

  • A few simple questions from a new Iphone user

    Hi a few simple questions, just got an iphone 2g - 2nd hand so not really sure what to expect. Anyway I guess my first question is about mine sometimes being a little slow - when I look at contacts and sometimes when sending a txt it slows down/freezes a little - normal?
    Secondly Edge - I havent used it much but when I have its been painfully slow, is this normal - is it always really slow - cause I had read despite not being 3g Edge was actually pretty fast - what exactly is data roaming by the way? I mean I have been switched off as basically I dont wanna use the internet till next month when they change my contract to one I get unlimited access on - is that right?
    Im having a problems syncing videos to it - it just wont sync some but will others and Im not sure why - theyre same file type and they used to sync to my ipod touch but now they wont for some reason
    Cheers

    I have the origina iPhone.
    Downloaded 2.0, synced phone with everything UNchecked. Installed 2.0. Synced with all the options checked to reload my data. The iPhone has been great. Noticed a little lag when I opened contacts. Installed the new upgrade, and everything is back, no lag.
    Edge is Edge and nothing more. It is slow compared to a strong 3g signal. But is liveable most of the time. Heavy traffic can slow it down to barely usable.
    My four wheel drive club has a web site with a large photo section. I was standing out in the middle of parking lot in San Jose, Ca and showing a friend some photos. It opens up a page of small picts to choose from. Select a print and it enlarges, He was amazed at how fast they appeard. Especially given the quantity of photos.

  • Simple question from jsp newbie

    Hi friends,
    I am learning jsp now. Reading documents and implementing simple applications. But i want to ask a question that is opposite to my logic.
    Now, i am a textfield control on jsp as textField1. I have created this control from Palette. in java code i am writing "textbox1." but there is no action, no intellisense while pressing ctrl + space.
    How the control is accessing from java code? Maybe my logic with visual studio .net. but i want to learn jsp logic.
    Thanks.

    technologyMan wrote:
    I am learning jsp now. You´re actually at the JSF forum here.
    Now, i am a textfield control on jsp as textField1. You are? Really?
    I have created this control from Palette. in java code i am writing "textbox1." but there is no action, no intellisense while pressing ctrl + space.
    How the control is accessing from java code? Maybe my logic with visual studio .net. but i want to learn jsp logic.Uh, just write code accordingly? You can use h:commandButton/h:commandLink for that.
    Anyway, if you want to start with JSF, I can recommend you the following sources:
    Java EE tutorial part II, JSF starts at chapter 10: [http://java.sun.com/javaee/5/docs/tutorial/doc/]
    Good kickoff tutorial: [http://balusc.blogspot.com/2008/01/jsf-tutorial-with-eclipse-and-tomcat.html]
    The JSF taglib documentation: [http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/]
    The JSF API documentation: [http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/overview-summary.html]

  • Basic Perl questions from Perl beginner now using Leopard

    Question: I used to dabble in Perl programming (beginner!!) and want to continue my dabbling with my new iMac running Leopard.
    Which Perl do I need to install?
    Where do I get it from?
    What tricks / concerns are there in the installation?
    What's the best source of information (books?, internet?) for learning about using/programming Perl on Leopard?
    Any other advice that you believe would be helpful would be appreciated.
    Many thanks!! D

    I used to use MacPerl as well, it's even better now that Perl is pre-installed and native.
    The two thing that took me the most time to figure out are:
    Line endings. All my old scripts had carriage return - line feed as end of line delimiters.
    On linux they have to be line feed '\x0A'. You do that by setting it in your text editor. I use BBEdit or Text Mate to write perl, although I'm pretty sure that using TextEdit will work, and will have line feed line endings.
    Setting the script's executable bit. A script file needs to have a bit set in the linux filesystem to tell linux it's executable. You do that by opening the terminal and typing chmod +x then drag your script file into the terminal and pressing return.
    That's detailed here:
    http://www.oreilly.com/pub/a/mac/2003/11/07/scripting_osx.html
    Also there are 2 main ways to run your script.
    One is by opening Terminal and +typing perl+ then dragging your script into the terminal window and hitting return. if you want to do it this way the very first line in your perl script needs to look like this:
    #!/usr/bin/perl
    The other way (which is only slightly easier) is by dragging your script into the terminal window and hitting enter, no typing perl every time. To do this the very first line of your perl script needs to be:
    #!/usr/bin/env perl
    Another huge tip is if you are in the Terminal window hitting command-up arrow will show you the last command you typed in, so you can hit enter and re-run it.
    Other than that stuff I can't remember any differences between regular linux perl and Leopard perl. I still refer to the Camel book I bought 15 or so years ago.
    So type into a text editor:
    #!/usr/bin/perl
    use strict;
    use warnings;
    print "Hello World\n";
    Then save the file as Hello.pl
    open terminal and type *chmod +x*
    drag Hello.pl into the terminal and press return
    Type perl into the Terminal
    drag Hello.pl into the terminal and press return.
    and it should print.

  • Question from a beginner

    Hi, all, I'm new to JSP and JavaBeans. Now I have to develop a web site with these technology.
    My first question is:
    Can I just put all database access(query, update, delete...) into JavaBean and create a bean for every table I have. Is this a good idea or I'd better follow the MVC model? Am I able to call a method in such a bean to access database?
    I've tried it, but I got a "NoSuchMethodError".
    Thank you so much.

    Using beans is a pretty good way to display database content in your jsp - it's certainly better than having all your code in JSP scriptlets (ie. between <% ... %> tags). The idea is to have as little actual java code in your jsps (separate presentation from business logic).
    The ultimate goal is an MVC architecture. Struts (http://jakarta.apache.org) is a framework which helps you to set this up and takes a lot of the pain out of setting up your own.
    HOWEVER ... I'd say that if you're just starting out with java and jsp then an MVC framework might confuse the hell out of you and your colleagues. If your app is not too complex then you might prefer to start off simply using beans in your pages until you get up to speed with all the other jsp issues. It's virtually impossible to get your jsp webapp architecture perfect the first time round, so perhaps set your sights on a simple model.

  • Few simple questions from newbie

    I'm new to Java, but i've worked a lot with action script... it didn't help a lot :) Here are my few beginner questions:
    What does: public, static, abstract, void... and other things mean in front of the class name?
    How can i call variables from another classes: if i have one class that does one thing and stores the result in a variable, how can i use that variable from a different class?
    How can i call the input window to enter the value for variable? I've tried with importing "io.inputstream" library, and used the "extend" thing, but i still cant call the input window?

    I came to Java from ActionScript too, and I must say having ActionScript as your first programming language does NOT make it easy to learn other languages. I was incredibly lost when starting with Java.
    What does: public, static, abstract, void... and
    other things mean in front of the class name?You'll find all that in the Java Tutorial
    How can i call variables from another classes: if i
    have one class that does one thing and stores the
    result in a variable, how can i use that variable
    from a different class?To use the variable from another class, you need to make a call to the class. Let's say you're in ClassB; you would make a call to a ClassA variable by doing something such as:
    ClassA.myVar.myMethod();
    How can i call the input window to enter the value
    for variable? I've tried with importing
    "io.inputstream" library, and used the "extend"
    thing, but i still cant call the input window?I recommend reading the tutorial before you try anything like that.

  • Just a simple question from a noob

    Hey guys
    im just working on my website, im not doing anything complicated just simple stuff.
    I just want to add a @facefont and change /edit the rules to just let me change the font. I wish it were as easy as just changing it with the property inspector but ive come to figure out that it doesnt work that way. Every time ive asked this question ive been referred to websites that have a 4 page guide on fonts,but this rarely helps me. im just looking a direct on how to do this. BTW im working with a preloaded template from dreamtemplate so everything is already formatted.
    problems: whenever i try to change the font and save it nothing saves but the font size, i want to add @facefont and change the font
    thanks in advanced

    Using Custom Web fonts is a bit more complex than you realize. 
    http://alt-web.com/Articles/Custom-Web-Fonts.shtml
    To make things simple, I recommend using one of the Free Edge Web Fonts.  Simply copy & paste code into the <head> tags of your HTML page. 
    EXAMPLE:
    <!--Edge Font-->
    <script src="http://use.edgefonts.net/pt-sans-narrow:n4,n7:all;league-gothic:n4:all.js"></script>
    Then define the font in your CSS code:
    h2 {font-family:pt-sans-narrow, "Arial Narrow", sans-serif;}
    h3 {
    font-family: league-gothic, Impact, Haettenschweiler, "Franklin Gothic Bold", "Arial Black", sans-serif;
    HTML code:
    <h2>This is Heading 2 - pt-sans-narrow</h2>
    <h3>This is Heading 3 - league-gothic</h3>
    Nancy O.

  • Question from a beginner, really need help

    I am starting to do a little programming these days. The question is about the (program file) format to provide to the end users.
    I can use "javac" "java" to compile or run my code in a command prompt window, or use some development tool. But I do not expect the users of my program to install the jdk (or other software) in order to run the program. How to deal with this?
    What is the usual last format of a Java Program?
    Hope I have made my question clear.
    Thanks
    Xiaohua

    It depends, a good solution is to pack it into a jar file and make it executable, but if you are new to Java (I have no idea how experianced you are) it might give you more trouble than it's worth in the beginning.
    You could distribute your .class file (the .java files are only source and can not be executed) and a .bat file which would contain the command to launch the applicaiton. That's how I would do it as a newbie.
    Check out an installer program like Inno Setup ( http://www.jrsoftware.org/isinfo.php ) if you want a neat way to distribute your files. You can specify a .bat file as being the one executed when the applicaiton is started, that way your program could be run from a start menu entry (sorry, I'm assuming that you are using Windows here, to maintain cross-platform abilities this won't work)
    Does this give you an idea? There are many ways to distribute an application. You should also read up on Java Webstart...

  • Few questions from a beginner

    hi there , i have a few questions first thing
    is it possible to make every connector that comes out of a specific shape the same color , im building a map where 1 shape gives of multiple connections, i want them all to be in the same color, and the connections coming from the second shape are all in
    a different color from the first shape
    second question: how can i select all the connectors that pass in a particular area
    i selected in the option select shapes partially in area, but it selects connectors that are NOT in the area that i selected
    thank you very much for your help

    There is no out of the box way for the first question but you can write a macro to do that. 
    Shape properties Shape.Connects and Shape.FromConnects can be used for selecting all
    outgoing connectors of a shape programmatically. And then appropriate formatting (colors) can be applied on selection by selection.

  • A question from a beginner

    I'm teaching a introductory programming course in java to some folks, and explaining variable lifetimes and the need for object member variables to store values longer than just a method call.
    So the example given was of a parameter being saved in a member variable
    The question arose, "Why can't you just specify the member variable as the parameter?"
    To which i gave the obvious reasons.
    When the class was over, i thought about it some more, and except for syntactic unpleasantries, there is no reason why this couldn't be done. Given that this is a common idiom, its odd that you can't do that.
    It's only not odd, because it's never been done before.
    Just thought it was an interesting thought that new-person thought produced.

    To paraphrase the JLS: When the method or constructor is invoked, the values of the actual argument expressions initialize newly created parameter variables, each of the declared type, before execution of the body of the method or constructor. The identifier may be used as a simple name in the body of the method or constructor to refer to the formal parameter. Taking your example:
    public class Foo {
      private int input;
      public void setInput( int Foo.input ) {}
    }Here you are not initializing any newly created parameter variables, and you have no identifier that may be used as a simple name in the body of the method or constructor to refer to the formal parameter. This breaks another part of the language specification which states that formal parameters are referred to only using simple names, never by using qualified names. You might also get into issues with the float-extended-exponent value set and the double-extended-exponent value set.
    Alternatively, you may just be suggesting that the compiler perform qualified name erasure to transform:
    public class Foo {
      private int input;
      public void setInput( int Foo.input ) {}
    }to:
    public class Foo {
      private int input;
      public void setInput( int input ) {
        this.input = input;
    }If this is the case, isn't syntactic sugar supposed to makes things "sweeter" to use? IMHO, this syntax isn't.

  • A few questions from a beginner

    Please don't hit me because of my questions...
    1. Is there a build in method (class or whatever) to increase an array size? I don't want to copy the array each time into a larger array and then setting the pointer of the new larger array to be the same as the old smaller array. I mean a method like Array.increase(param) or something like that.
    2. Is there a way to find out how many dimension an array has? A build in method like .length
    3. Can I convert a array into a vector? If yes, how?
    4. The Math.round() method accepts only one parameter which contains the double number to be rounded. But it does't have a second parameter by which I can tell the method to round a number to the second (third or whatever) number after the dot. Is there a method like that somewhere else or do I need to program it for myself?

    ::smack::
    there, now that's out of the way..
    1) No.. arrays are static in length, which is set upon instantiation. If you need a datatype to store multiple objects that will need to increase in size, you should use Vector.
    2) I believe I'm right in saying that there's not really a way to check that. A multidimensional array is basically an array of arrays. I guess you could know that if you got myarray[0] and did a check to find out what datatype it was, you'd know that if the index contained an array, it'd be 2D ... then you could check that array, etc. However, since you are declaring the array, and when passing the array, you'd have to specify what it was (ie public void foo(int[][][] my3dIntArray) ) you should never not know the dimensions.
    3) Yes. But you'll have to loop through your array and add items to the Vector.
    4) You're right, it doesn't. Now that you mention it though, I can't think of a method that does that.... but it shouldn't be too hard for you to work out your won.

  • Very simple question from a rookie

    Hi,
    I don't know how sequences work in OWB.
    I have a very simple mapping:
    1 (not empty) source table, 1 (empty) target table, 1 sequence.
    Source and destination are connected.
    The sequence.nextval is connected to the primary key. sequence.currval is not connected.
    When I run the debug mode an error occurs: "Could not find data for all sources and target ...". The "Test Data" shows that OWB has not found data for the sequence.
    Help!

    I use 10gR2 and OWB 10.2
    The tables and the sequence are deployed. They are in the database.
    There's something strange about this:
    Starting ("Start...") works.
    The debugging does not work.
    Problem nearly solved ...
    Message was edited by:
    user517859

  • Help Required::::Simple queries from a beginner's prespective for certi

    Hi All,
    I was preparing for the HFM certi.
    While, going through the bootcamp exercises, i have come across some problems which I have formulated as questions.
    PFB my queries for HFM .
    · There is a property called “Consolidation Rules” in Appsettings—It has values “y” or “N” or “R”…What is the significance of each of these.We have a Sub-Consolidate subrountine in the rules file..if we choose “Y” in Consolidation Rules ,does it pick up the subroutine written by us in rules file or does HFM perform its own default Consolidation?
    · Meaning of ICP Entities Aggregation Weight.Its usage.
    · Node Security is an option at App Settings level—how is it used to define access at user/group level?
    · Concept of the “IsConsolidated” Property with Accounts
    · In Scenario, Property called “Zero View for Adj/Non Adj”
    Thanks,
    ColDFirE

    hi
    You are right about Consolidation rules.This option specifies whether consolidation rules are supported. Specify one of these values:
    Y to use the rules written in the Consolidate()routine in a user-defined rule.
    R to derive the proportional value in the Value dimension. Note that the proportional data is not stored.
    N to use the default consolidation and eliminations.
    IsConsolidated
    Determines if the current Account dimension member or a specified account member is a
    consolidated account. This function can be used in these types of rules:
    ● Calculation
    ● Translation
    ● Consolidation
    ● Allocation
    Ex:HS.Account.IsConsolidated("Account")
    ZeroViewForAdj
    Specifies how to interpret missing, adjusted data values for the period.This attribute is required. Specify YTD or Periodic.
    i guess admin guide can cover all your question
    read http://download.oracle.com/docs/cd/E12825_01/epm.111/hfm_admin.pdf
    regards
    alexander

Maybe you are looking for

  • Developing a year planner! major problems!

    Hi there, I've been trying to develop a year planner and have had a few design issues with it. the year planner should show all the dates, months etc at the same time.Without using the calendar class in the api i can't see a way of doing this. 5 week

  • Configuration of Letter of Credit

    Hi all, I have difficulty configuring letter of credit. can somebody help me with the steps for configuration of letter of credit. thanks in advance

  • How to go back to frame 1 when the timeline reaches a certain frame?

    I have a timeline that has some label frames at the very end of the timeline. During the timeline a user will hit a button on a frame and will jump to one of the label frames. On the label frame is another button that when clicked - returns the user

  • Why does SunOne 6.1 call servlet init() method twice on startup

    Hi, SunOne6.1 sp 5 is running my servlet's init() method twice when I put load-on-startup in the web-xml file. Is this a known problem and is there a work around as no amount of synchronising seems to work. I'm running 2.3.dtd for the default_web.xml

  • All browsers crashes all the time randomly

    Hello, I encounter an issue with my all internet browsers. I recently restored my computer to the factory settings (by installing windows from the DVDs) and I have issues with the all the internet browsers. I installed all the updates and the latest