Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: basic java

  1. #1
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default basic java

    hi!!!! every one

    my doubt is!!!!

    wats the use of wrapper classes in java???

    why we neeed to change the primitives to objects!!!! cant we perform operatios and calling of function using primitives!!!!

    pls explain with example!!!

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    What's your problem/question?

    btw... cut down on the exclamation and question marks...
    I die a little on the inside...
    Every time I get shot.

  3. #3
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default classes

    my doubt is!!!!

    wats the use of wrapper classes in java???

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I can say it in this way.

    The wrapper classes are normal classes that extend the Object superclass
    Can you understand that.

  5. #5
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default

    That i know that it extends the Object class!!!!
    I am asking wats the use of Wrapper classes!!! i we ar making primitive data types as wrapper!!!

  6. #6
    mrbharatmehta is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Default

    Hi vijay,

    The concept of Wrapper classes is used to allow us to store primitives into collections. For example:
    Suppose you wish to make a List of integers. In this you can use the corresponding wrapper class for integers i.e Integer to store the value of the your primitive integer.
    <CODE>
    List<Integer> vijayList= new ArrayList<Integer>();
    </CODE>

    Also wrapper classes can be used to parse primitive data values from a string . like

    <CODE> int vijayInt = Integer.parseInt("123");</CODE>

    I hope that suffice. For rest of the methods in the Wrapper classes you can refer to Java API documentation

  7. #7
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default

    thanks i have one more doubt!!!

    import java.util.Scanner;
    class ScanNext {
    public static void main(String [] args) {
    boolean b2, b;
    int i;
    String s, hits = " ";
    Scanner s1 = new Scanner(args[0]);
    Scanner s2 = new Scanner(args[0]);
    while(b = s1.hasNext()) {
    s = s1.next(); hits += "s";
    }
    while(b = s2.hasNext()) {
    if (s2.hasNextInt()) {
    i = s2.nextInt(); hits += "i";
    } else if (s2.hasNextBoolean()) {
    b2 = s2.nextBoolean(); hits += "b";
    } else {
    s2.next(); hits += "s2";
    }
    }
    System.out.println("hits " + hits);
    }
    }


    If this program is invoked with
    % java ScanNext "1 true 34 hi"


    it produces
    hits ssssibis2

    how this works!!!! how we got this as output!!! pls explain!!

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Vijay... you really should learn to communicate correctly when writing in the forum:
    • Stop putting so many exclamation marks (!!!) after your sentences. It seems like you are demanding attention and it could be misunderstood and people will get angry or just ignore you.
    • ALso, give your variable names some meaning... s, s2, etc... doesn't mean much and is confusing. Try str1, str2, intg, bool, etc... or something like that for names.
    • If I read your program correctly, it's working as you programed it. Try to debug it... just follow the your code and you will find out why you got that output (hint: look at what the while loops are doing)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Thumbs up Chris for you. I really looking into about naming conventions of variables in that code. Really hard to get an idea what's going on. Chris I guess lots of members who are trying to give an answer, are not run the code. Just go through the code and try to find where the error is. I do that most of the time. So naming variable in meaningful way is must.

  10. #10
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default

    ya sure!!!!

  11. #11
    Mara is offline Member
    Join Date
    Mar 2009
    Posts
    6
    Rep Power
    0

    Default

    many people have already asked to STOP PUTTING EXCLAMATION MARKS .. the variables you have named make it confusing to explain it

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agrees with others above. Vijay, could you tone it down a bit?

  13. #13
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default

    what is the use of making strings in java as immutable?

  14. #14
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default

    one more doubt ,why is String class in java marked as final?

  15. #15
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Strings and more strings

    Answers are probably in this link:
    String (Java Platform SE 6)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  16. #16
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    wrapper/final/immutable...

    These questions are getting at Java (and I would guess other language) syntax and idiom (usage). I would recommend reading a textbook - or Wikipedia which is often good at supplying an overview.

    Googleing it for you reveals Wrapper_class and Final_(Java). Both articles are full of references to allied topics. If nothing else they should provide you with some way of framing a specific question - whether some specific opinion of yours is correct, what the meaning of some specific assertion is etc.

  17. #17
    vijay24805 is offline Member
    Join Date
    Mar 2009
    Posts
    15
    Rep Power
    0

    Default

    What is serialization? can anyone give a good example to explain that?

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    You are asking questions in a hurry. Did you read anything before ask questions like this? Just like this, you cannot learn Java anyway. You must read more about theories in Java and do some examples.

  19. #19
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Yeah... asking and asking and absolutely no thanks for the answers so far. The OP's 'tude is quite demanding.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  20. #20
    Rooneyz is offline Member
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    25
    Rep Power
    0

    Default

    Quote Originally Posted by CJSLMAN View Post
    • If I read your program correctly, it's working as you programed it.
    This one I ought to remember, simply genius ;)

Page 1 of 2 12 LastLast

Similar Threads

  1. Basic Java help, AIM?
    By jkswebsite in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 07:17 PM
  2. need very basic help with xml parsing in java
    By 2potatocakes in forum New To Java
    Replies: 7
    Last Post: 09-17-2008, 01:22 PM
  3. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 01:36 PM
  4. Help with basic shapes in java
    By carl in forum Java 2D
    Replies: 1
    Last Post: 08-01-2007, 12:40 AM
  5. Help, basic shapes using java
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 09:52 PM

Posting Permissions

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