Prabz Bhatia

Greenhorn
+ Follow
since Apr 14, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Prabz Bhatia

Joanne Neal wrote:
Actually that's wrong. Despite their name, constructors do not create objects, they only initialise them.
A child class will contain all the instance variables defined in the parent class, but an instance of the parent class will not be created, so when you call the parent constructor you are actuall still initialising the child class.
See section 12.5 of the Java Language Specification for full details of what happens when an instance of a class is created.



Seems like I sure have gotten that all wrong,
I apologize for the misunderstanding Campbell...
15 years ago

Campbell Ritchie wrote:I did say I thought my answer wasn't accurate.


Oh I thought you were talking about my answer...

Campbell Ritchie wrote:
Are you sure, Prabz Bhatia, that an object is created for each class in its inheritance hierarchy?



Yes, I am sure, objects for all non abstract classes upwards the inheritance tree are instantiated whenever an object is created... Proof can be had from the following example


won't work when you try to instantiate B, as B isn't passing a parameter to A's constructor.

It will have to be of the form:


Hope this helps...
15 years ago
That's not completely right.. whenever you instantiate an object, an instance of all objects EDIT: classes upwards the inheritance tree is also generated, automatically. It's a different matter altogether, whether those objects can be independently referenced or not...
15 years ago
However, if you wish to save states of variables between every class instantiation,(and share them) you could simply make the variables static, and directly access the variables.... no need of serialization for this limited purpose...
15 years ago

Nishant Arora wrote:I have tried to code but its not saving state of variable classLoadCount where is the problem??




Static variables aren't serialized... Static means "one per class" not "one per object".


So just remove the static keyword, and you can save the state of your object...
15 years ago
well you can serialize an entire object, i e store values of all instance variables in a file , and can load it at will. you can find a simple program in Head First Java . Google also helps...
15 years ago
That's because they would have no meaning without an instance of the class, an object.

"this" refers to the current instance of that class.
eg super refers to the object upwards the inheritance tree.


15 years ago
Hope that helped you work it out... Did it?
15 years ago
It is of utmost necessity to know all topics covered in HFJ. That's the sort-of-prerequisite for moving on to SCJP Study guide by kathy sierra...
Actually there are some topics that aren't covered in detail in HFJ, but are part of the exam..
I suggest you take it easy, and try 20-30 pages per day from HFJ, Slow and steady wins the race!
Don't think too much about the exam right now, HFJ is really fun, enjoy learning JAVA!!!
All the best!!
15 years ago
An easier and more efficient method would be to use an ArrayList.
Then you could use its inbuilt method to check for existence of an element:
public boolean contains(Object)




15 years ago
I've had some experience in this field,
If I may ask, What exactly are you trying to accomplish by using 2 sequencers simultaneously?

I mean If you 're trying to produce 2 sounds at once, you could use 2 different channels on the same sequencer and start them together...
15 years ago
This is all getting confusing....
First things first,
1. You need to have jdk installed to compile java files . Default Install directory is : "C:\Program Files\Java\jdkXXXXXX" where XXXXXX is the installed jdk version.
2. Set value of the PATH variable as follows:
To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:

Click Start > Control Panel > System on Windows
Click Advanced > Environment Variables.
Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
C:\Program Files\Java\jdk1.6.0_<version>\bin
PATH environment variable is a series of directories separated by semi-colons (;) and is not case sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
You should only have one bin directory for a JDK in the path at a time. Those following the first instance are ignored. If one is already present, update it to jdk1.6.0_<version>\bin.
If you are not sure where to add the path, add it to the right end of the PATH in the User Variables.
The new path takes effect in each new command window you open after setting the PATH variable.

3. To compile any java file, cd to the directory where it is located and type the command:
Directory>javac <yourFileName>.java

4. To execute a class file, cd to the containing directory and type:
java <yourClassName>


Hope this helps.....
15 years ago
Hehe...
myself got confused in this one at first...

when x==y, does it matter what it returns??? Because x and y are the same!!!..


15 years ago