Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Any Java 2 gurus around?

  1. #1
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default Any Java 2 gurus around?

    I'm having to re-learn Java in preparation for diving back into US I.T.; my technical skills have atrophied since I've been away.

    I'm just looking at literals and operators and variables and all this other shit and I'm so ANNOYED by it!

    Someone tell me again why I have to keep writing public static void main?

  2. #2
    ReinaBikipatra
    Newbie

    Default

    kiss kiss little girl.

  3. #3
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default

    This is an example from the book. How retarded is this?

    public class Amoebamath {
    public static void main (String arguments[]) {
    int x = 6;
    short y = 4;
    float a = .12f;

    System.out.println("You start with " + x + " pet amoebas.");
    System.out.println("\tTwo get married and their spouses move in.");
    x = x + 2;
    System.out.println("You now have " + x);

    System.out.println("\tMitosis occurs, doubling the number of amoebas.");
    x = x * 2;
    System.out.println("You now have " + x);

    System.out.println("\tThere's a fight. " + y + " amoebas move out.");
    x = x - y;
    System.out.println("You now have " + x);

    System.out.println("\tParamecia attack! You lose one-third of the colony.");
    x = x - (x / 3);
    System.out.println("You end up with " + x + " pet amoebas.");
    System.out.println("Daily upkeep cost per amoeba: $" + a);
    System.out.println("Total daily cost: $" + (a * x));
    }

    }

  4. #4
    ReinaBikipatra
    Newbie

    Default

    See swe'pea you are smarter than me. I don't know what the fuck that is.

  5. #5
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default

    Quote Originally Posted by ReinaBikipatra View Post
    See swe'pea you are smarter than me. I don't know what the fuck that is.

    It's Java...it's a programming language, it's dumb. This is from Chapter 3 of Sams 'Teach Yourself Java in 21 Days.'

  6. #6
    Silver Member
    Join Date
    Oct 2005
    Posts
    478

    Default

    public static void main means that you are writing an executable program. So in the Amoebamath program, everytime you run it, every statement in the "main" function will be executed. You can have classes without a main method, though, like the following example.

    public class Point{
    int x;
    int y;

    public Point(int x, int y){
    this.x = x;
    this.y = y
    }

    public void getPoint(){
    System.out.println(x + " " + y);
    }

    public int getX(){
    return x;
    }

    public static int getDifference(int x, int y){
    return x-y;
    }
    }
    This does not have a main method, so if you try to run it, nothing will happen, because you have not provided any instructions for it to run. You could use the Point class in a program with a main method, if you wanted to. For instance:

    [qoute]
    public class Demo{
    public static void main(String args[]){
    Point p = new Point(2, 2);

    System.out.println(p.getX());

    System.out.println(Point.getDifference(4, 2);
    }
    }
    [/quote]

    So now when I run this program, I am actually running an executable program. By contrast, try running Point and you'll see that nothing happens.

    Static methods require an instance of an object to run. See Point's getX(); if I haven't created a Point object, then I don't have a Point to get x from. Imagine if I asked you the area of a circle that doesnt exist; it doesnt make sense to ask that question. Nonstatic methods dont require that an object be created. I wrote a method called getDifference, to which I provided two ints. The ints I provided had nothing to do with a Point object. Main methods are static because by definition they are run before any objects are created. Void means that the method does not return anything. Does that helpd clear things up? Good luck

  7. #7
    SVZ
    SVZ is offline
    Do fish have boogers? SVZ's Avatar
    Join Date
    Oct 2005
    Location
    Venus
    Posts
    1,000,003,609

    Default

    The answer is 4!!

  8. #8
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default

    Quote Originally Posted by dragonlady View Post
    public static void main means that you are writing an executable program. So in the Amoebamath program, everytime you run it, every statement in the "main" function will be executed. You can have classes without a main method, though, like the following example.



    This does not have a main method, so if you try to run it, nothing will happen, because you have not provided any instructions for it to run. You could use the Point class in a program with a main method, if you wanted to. For instance:

    public class Demo{
    public static void main(String args[]){
    Point p = new Point(2, 2);

    System.out.println(p.getX());

    System.out.println(Point.getDifference(4, 2);
    }
    }
    So now when I run this program, I am actually running an executable program. By contrast, try running Point and you'll see that nothing happens.

    Static methods require an instance of an object to run. See Point's getX(); if I haven't created a Point object, then I don't have a Point to get x from. Imagine if I asked you the area of a circle that doesnt exist; it doesnt make sense to ask that question. Nonstatic methods dont require that an object be created. I wrote a method called getDifference, to which I provided two ints. The ints I provided had nothing to do with a Point object. Main methods are static because by definition they are run before any objects are created. Void means that the method does not return anything. Does that helpd clear things up? Good luck

    Christ NO! Can you believe I have actually taken...and passed...not only a Java programming course, but a VB programming course as well, and I used to be able to do C as well?

    Christ, the expression 'use it or lose it' was NEVER MORE TRUE!!!!!!!!!!

  9. #9
    Gold Member moocow's Avatar
    Join Date
    Oct 2005
    Posts
    717

    Default

    Get yourself a java in 21 days book. I love those books. Lots of good examples and explanations.

    But yeah, non-web programming usually has a main function of some sort, otherwise it's just a library of functions

  10. #10
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default

    Quote Originally Posted by moocow View Post
    Get yourself a java in 21 days book. I love those books. Lots of good examples and explanations.

    But yeah, non-web programming usually has a main function of some sort, otherwise it's just a library of functions

    Yeah, I already have one...it said so in the original message. It sucks ass.

  11. #11
    Gold Member moocow's Avatar
    Join Date
    Oct 2005
    Posts
    717

    Default

    Quote Originally Posted by disruptivehair View Post
    Yeah, I already have one...it said so in the original message. It sucks ass.
    Hm. I must be overlooking it, all I saw was that you had a book, not what type.

    Is it a Sam's book? I can't remember which ones I have. I have several at any rate. Java2 in a nutshell is one I used for reference. You might look at "Java by Example", a Java bible, stuff like that.

  12. #12
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default

    Quote Originally Posted by moocow View Post
    Hm. I must be overlooking it, all I saw was that you had a book, not what type.

    Is it a Sam's book? I can't remember which ones I have. I have several at any rate. Java2 in a nutshell is one I used for reference. You might look at "Java by Example", a Java bible, stuff like that.

    It's the big purple hardback Sams one. It sucks ass.

  13. #13
    Gold Member moocow's Avatar
    Join Date
    Oct 2005
    Posts
    717

    Default

    Usually Sam's is good, but it can be hit or miss, depending on the authors.

    I'm personally having to do more .net programming. And as much as I didn't want to, having to learn VB, while vbscript I've been using for a while.

  14. #14
    Hit By Ban Bus! DisruptiveHair's Avatar
    Join Date
    Oct 2005
    Location
    UK, soon to be home in the USA
    Posts
    1,338

    Default

    Quote Originally Posted by moocow View Post
    Usually Sam's is good, but it can be hit or miss, depending on the authors.

    I'm personally having to do more .net programming. And as much as I didn't want to, having to learn VB, while vbscript I've been using for a while.

    The thing is, I don't want to be a programmer. Never have wanted to. I have to learn programming languages because moron managers think quality analysts need to know how to program, which isn't true. So there's already a mental block in my head to programming. I don't really care about it, so there's very little incentive to actually learn it. Plus, I busted my ass learning Java the first time and I'm not looking forward to doing it again. I'm on 'day 4' of the Sams book and I'm totally lost.

  15. #15
    Gold Member moocow's Avatar
    Join Date
    Oct 2005
    Posts
    717

    Default

    That's.. interesting. And wrong-headed of them. It's actually better in many ways NOT to consider the programming itself when you're performing analysis and upper level design. Better to have the black box/magic cloud idea when it comes to how things are done, rather than trying to design the underlying functionality.

    I hate it when systems designers try to build in the program design. I don't even think they should decide for the programmers ahead of time what language to use.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Anybody know Java?
    By burnt_toast in forum Computers and Technology
    Replies: 3
    Last Post: June 19th, 2006, 10:48 AM

Posting Permissions

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