Go Back   Gossip Rocks Forum > Daily Life > Computers and Technology


Login to remove all ads!
Old October 30th, 2005, 09:16 AM   #1 (permalink)
DisruptiveHair
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?
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 09:18 AM   #2 (permalink)
ReinaBikipatra
 
Posts: n/a
Default

kiss kiss little girl.
  Reply With Quote
Old October 30th, 2005, 09:24 AM   #3 (permalink)
DisruptiveHair
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?

Quote:
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));
}

}
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 09:29 AM   #4 (permalink)
ReinaBikipatra
 
Posts: n/a
Default

See swe'pea you are smarter than me. I don't know what the fuck that is.
  Reply With Quote
Old October 30th, 2005, 09:34 AM   #5 (permalink)
DisruptiveHair
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.'
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 10:28 AM   #6 (permalink)
dragonlady
Silver Member
 
Join Date: Oct 2005
Posts: 442
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.

Quote:
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
dragonlady is offline   Reply With Quote
Old October 30th, 2005, 12:10 PM   #7 (permalink)
SVZ
Do fish have boogers?
 
SVZ's Avatar
 
Join Date: Oct 2005
Location: Venus
Posts: 1,000,000,812
Default

The answer is 4!!
SVZ is offline   Reply With Quote
Old October 30th, 2005, 01:40 PM   #8 (permalink)
DisruptiveHair
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:

Quote:
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!!!!!!!!!!
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 03:38 PM   #9 (permalink)
moocow
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
moocow is offline   Reply With Quote
Old October 30th, 2005, 04:01 PM   #10 (permalink)
DisruptiveHair
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.
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 04:13 PM   #11 (permalink)
moocow
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.
moocow is offline   Reply With Quote
Old October 30th, 2005, 04:15 PM   #12 (permalink)
DisruptiveHair
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.
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 04:25 PM   #13 (permalink)
moocow
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.
moocow is offline   Reply With Quote
Old October 30th, 2005, 04:27 PM   #14 (permalink)
DisruptiveHair
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.
DisruptiveHair is offline   Reply With Quote
Old October 30th, 2005, 04:35 PM   #15 (permalink)
moocow
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.
moocow is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anybody know Java? cloud Computers and Technology 3 June 19th, 2006 10:48 AM


All times are GMT -5. The time now is 04:33 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8
Design by JP33