Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 02-26-07   #1 (permalink)
nVidia Enthusiast
 
ModeX's Avatar
 
intel nvidia

Join Date: Oct 2006
Posts: 348

Rep: 6 ModeX Unknown
Unique Rep: 6
Trader Rating: 0
Default java-constructors-super-mE nEed HelP b4 I gO InSaNE!

I am currently teaching myself java through the All in one for dummies book...

I try to make sure that I can use what I'm studying before I move on to the next chapter.

But I've hit a road block considering my learning style and they were pretty vague on constructors.

They only gave examples that wouldn't compile

My questions are:

1. Is this the constructor ()? (if not what is it?)
2.What is with the default setting of the constructor?(they were vauge...)
3.HOW THE HECK DO YOU YOU USE SUPER WHEN THE MAIN METHOD IS STATIC?!?!?!?!?!?!?!?!?!?!?!?!?
__________________
"We are all prophets, that is why we make so many mistakes"

"One who wears a mask wants to become someone else
one who wears a mask somewhere other than the face wants to become many"

"The truth is a lie"

"There are only a few free people in the world, the insane"

System: The System
CPU
e6600
Motherboard
asus striker extreme
Memory
2gb supertalent pc2 6400
Graphics Card
Evga 8800 gtx
Hard Drive
maxtor
Sound Card
stock
Power Supply
coolermaster 550watt
Case
Thermaltake Kandalf (Modded)
CPU cooling
big typhoon
GPU cooling
8800 tx evga
OS
xp professional
Monitor
1920*1200 ress sony
ModeX is offline   Reply With Quote
Old 02-26-07   #2 (permalink)
Intel Overclocker
 
cgrado's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Sugar Land, Texas
Posts: 4,965

Rep: 229 cgrado is acknowledged by manycgrado is acknowledged by manycgrado is acknowledged by many
Unique Rep: 175
FAQs Submitted: 1
Folding Team Rank: 254
Hardware Reviews: 1
Trader Rating: 1
Default

1.
2.
If you are going to construct an object, you need to declare it as well as instantiate it with paramaters.
Object name = new Object(parameters);
Different objects require different parameters. look at the java api.

Let's take a look at the StringTokenizer class.
String coolio = "cool string";
StringTokenizer st = new StringTokenizer(coolio);

the new StringTokenizer st is given a value of a new StringTokenizer that uses the string coolio to get it's value. what it does is break down the string into tokens. the default delimiters (or what it uses to break the string into tokens) are space and some other characters. so if want to use the object's method "nextToken" you can :
String a = st.nextToken();

this will set the String "a" equal to the value of the first "token" which is "cool"
and
String b = st.nextToken();
will set b = "string";
__________________
Quote:
Originally Posted by TwIsTeDbOi View Post
What's next, banning mirrors because, oh no god forbid, if we see ourselves naked we're gunna be traumatized?
I'm like the inquirer, take everything i say with a grain of salt.
SLi Zone PSU listing- check to see if your PSU is SLi certified.
BF2 stats BF2142 stats
My Guide to BF2 Unlocks

System: Immortal
CPU
E6600 44G 3.240GHz
Motherboard
Asus P5B-deluxe
Memory
2GB PQIturbomem 667(800mhzballistix soon)
Graphics Card
eVGA 8800GT (650/950)
Hard Drive
1x 400GB Seagate 7200rpm/16mb cache
Sound Card
X-fi Xtremegamer
Power Supply
610w PCP&C silencer
Case
TTArmor w/side fan
CPU cooling
Custom Watercooling
GPU cooling
Stock EVGA
OS
Windows XP Home/Ubuntu
Monitor
NEC MultiSync LCD1970GX
cgrado is offline I fold for Overclock.net cgrado's Gallery   Reply With Quote
Old 02-26-07   #3 (permalink)
nVidia Enthusiast
 
ModeX's Avatar
 
intel nvidia

Join Date: Oct 2006
Posts: 348

Rep: 6 ModeX Unknown
Unique Rep: 6
Trader Rating: 0
Default

1. Let me see if I understand, a constructor is only needed when you create a new object or new instance of an object?
__________________
"We are all prophets, that is why we make so many mistakes"

"One who wears a mask wants to become someone else
one who wears a mask somewhere other than the face wants to become many"

"The truth is a lie"

"There are only a few free people in the world, the insane"

System: The System
CPU
e6600
Motherboard
asus striker extreme
Memory
2gb supertalent pc2 6400
Graphics Card
Evga 8800 gtx
Hard Drive
maxtor
Sound Card
stock
Power Supply
coolermaster 550watt
Case
Thermaltake Kandalf (Modded)
CPU cooling
big typhoon
GPU cooling
8800 tx evga
OS
xp professional
Monitor
1920*1200 ress sony
ModeX is offline   Reply With Quote
Old 02-26-07   #4 (permalink)
Programmer
 
intel nvidia

Join Date: Jul 2006
Posts: 194

Rep: 11 mjoc13 Unknown
Unique Rep: 10
Trader Rating: 5
Default

Quote:
Originally Posted by ModeX View Post
1. Let me see if I understand, a constructor is only needed when you create a new object or new instance of an object?
Pretty much.
A constructor is used when you created a new object to predefine local values. for example if we have an object called 'System' our class can look as follows.

public class System {
private int ramAmount;
private int cpuSpeed;

//constructors
public Sytem() {
//this is the default constructor, does nothing
}

//assignment constructor
public System (int newCpuSpeed, int newRamAmount) {
ramAmount = newRamAmount;
cpuSpeed = newCpuSpeed;
}

...other class methods etc
}


so in another part of our application we can create a new object system with (a) the default constuctor or (b) the preassignment values.
a) System myNewRig = new System();
b) System myNewRig = new System(3600, 2); - where 3600 is cpu speed, 2 is ram. You can have many constuctors to handle different cases.

I hope this example helps, i find it easier to looks at example or actually do the work on your own.
__________________
Relax and enjoy life!

System: My System
CPU
C2D e6400
Motherboard
eVga 680i - T1
Memory
2x1GB Gskill HZ
Graphics Card
eVga 8800 gts sc 320
Hard Drive
wd 320 sataII, WD 250 PATA
Sound Card
OB
Power Supply
Corsair HX620W
Case
Coolmaster Elite
OS
Win XP pro sp2
Monitor
Sammy 19 ws LCD
mjoc13 is offline   Reply With Quote
Old 02-26-07   #5 (permalink)
nVidia Enthusiast
 
ModeX's Avatar
 
intel nvidia

Join Date: Oct 2006
Posts: 348

Rep: 6 ModeX Unknown
Unique Rep: 6
Trader Rating: 0
Default

Quote:
Originally Posted by mjoc13 View Post
Pretty much.
A constructor is used when you created a new object to predefine local values. for example if we have an object called 'System' our class can look as follows.

public class System {
private int ramAmount;
private int cpuSpeed;

//constructors
public Sytem() {
//this is the default constructor, does nothing
}

//assignment constructor
public System (int newCpuSpeed, int newRamAmount) {
ramAmount = newRamAmount;
cpuSpeed = newCpuSpeed;
}

...other class methods etc
}


so in another part of our application we can create a new object system with (a) the default constuctor or (b) the preassignment values.
a) System myNewRig = new System();
b) System myNewRig = new System(3600, 2); - where 3600 is cpu speed, 2 is ram. You can have many constuctors to handle different cases.

I hope this example helps, i find it easier to looks at example or actually do the work on your own.
Ty for the example it's starting to make a bit more sence. One more thing do you know anything about the super method for constructors cause it throwing me for a loop
__________________
"We are all prophets, that is why we make so many mistakes"

"One who wears a mask wants to become someone else
one who wears a mask somewhere other than the face wants to become many"

"The truth is a lie"

"There are only a few free people in the world, the insane"

System: The System
CPU
e6600
Motherboard
asus striker extreme
Memory
2gb supertalent pc2 6400
Graphics Card
Evga 8800 gtx
Hard Drive
maxtor
Sound Card
stock
Power Supply
coolermaster 550watt
Case
Thermaltake Kandalf (Modded)
CPU cooling
big typhoon
GPU cooling
8800 tx evga
OS
xp professional
Monitor
1920*1200 ress sony
ModeX is offline   Reply With Quote
Old 02-27-07   #6 (permalink)
Programmer
 
intel nvidia

Join Date: Jul 2006
Posts: 194

Rep: 11 mjoc13 Unknown
Unique Rep: 10
Trader Rating: 5
Default

Quote:
Originally Posted by ModeX View Post
Ty for the example it's starting to make a bit more sence. One more thing do you know anything about the super method for constructors cause it throwing me for a loop

Sure, the 'super' call is relating to the objects parent or extending class.
If the example i gave was like the following:

public class System extends Server {
private int ram;
private int cpuSpeed;
//constructor
public System (int newRam, int newCpuSpeed) {
super(false); // since this is a home PC we know is not a server...
ram = newRam;
cpuSpeed = newCpuSpeed;
}
}

public class Server {
private boolean isServer;

//constructor
public Server (boolean newIsServer) {
isServer = newIsServer;
}
}

Since System extends server, it also holds the values which are in the Server class. By using super, we can write those values which are not directly in our system class. As you progress you java development, you will find this is very useful especially when using swing frames and panels.

Hope it helps, sorry for the bad formatting, but it's the forum text parser
__________________
Relax and enjoy life!

System: My System
CPU
C2D e6400
Motherboard
eVga 680i - T1
Memory
2x1GB Gskill HZ
Graphics Card
eVga 8800 gts sc 320
Hard Drive
wd 320 sataII, WD 250 PATA
Sound Card
OB
Power Supply
Corsair HX620W
Case
Coolmaster Elite
OS
Win XP pro sp2
Monitor
Sammy 19 ws LCD
mjoc13 is offline   Reply With Quote
Old 02-28-07   #7 (permalink)
nVidia Enthusiast
 
ModeX's Avatar
 
intel nvidia

Join Date: Oct 2006
Posts: 348

Rep: 6 ModeX Unknown
Unique Rep: 6
Trader Rating: 0
Default

could you redo that example with the static main method, what originally through me off was in NetBeans it said that I couldn't use super because it was non static and it referenced a static method. ty again!
__________________
"We are all prophets, that is why we make so many mistakes"

"One who wears a mask wants to become someone else
one who wears a mask somewhere other than the face wants to become many"

"The truth is a lie"

"There are only a few free people in the world, the insane"

System: The System
CPU
e6600
Motherboard
asus striker extreme
Memory
2gb supertalent pc2 6400
Graphics Card
Evga 8800 gtx
Hard Drive
maxtor
Sound Card
stock
Power Supply
coolermaster 550watt
Case
Thermaltake Kandalf (Modded)
CPU cooling
big typhoon
GPU cooling
8800 tx evga
OS
xp professional
Monitor
1920*1200 ress sony
ModeX is offline   Reply With Quote
Reply



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



All times are GMT -4. The time now is 02:04 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.41528 seconds with 8 queries