Mike McManus

Greenhorn
+ Follow
since Mar 23, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike McManus

Hello - on page 24 of the guide there is a code example of initializing a date object and I have the following questions:
First the "today" variable is defined as a reference of type Date This is just declaring the type of the variable, not creating an instance of the object - right?
At this point, today should be null, correct?
Then we run I understand that this statement will create an instance of Date and point the today reference to it, but I am not sure how.
When you execute new shouldn't it be executing on a class, not a method?
If we wanted to run the method from the Date class, wouldn't the code look like I've tried this and it won't compile.
What am I missing here?
Any help would greatly be appreciated.
7 years ago
Paul - thank you for the link to the code table. Now this makes more sense, every letter represents a numeric equivalent. So the TOUPPER method is really just calculating an offset ('A' -'a') to apply to the character that is passed in. So in reality it is:
Back to the original question about float vs. double. I now understand that this is because:
1) the compiler determines the appropriate data type for the value (in this case - 102.0)
2) because the compiler determined that the value is double, it cannot evaluate it into a float variable unless an explicit cast is done or using the 'f' suffix on the value.
3) and that there is a data type progression based on the size of the data type. You can normally evaluate from a shorter data type into a longer one, but not vice versa.
Thanks for everybody's help on this.
And the journey continues...
7 years ago
Junilu - even with your example it still does not make sense to me. In your example of a method that converts a character to upper case, how does the "math" in your example work?
As stated previously, it just looks to me like a letter 'A' adding to the character variable ch and then subtracting another letter 'a' - nothing in that makes sense to me as to how this is math and how you get from lower case to upper case.
As far as imagining how I'd do this without math - there is a limited number of letters in the alphabet, how about doing this with arrays? Find the the lower case value and return the corresponding upper case value - this makes sense to me, it's simple, and does not use this goofy "math".
Perhaps it is just because I haven't been exposed to it, but I still cannot wrap my head around using alphabetic characters in a math equation. Under what circumstances?
7 years ago
I am sorry, but I just don't get this. No calculator I have every used allowed me to use alphabetic characters. Math is math - numbers vs. numbers. Not numbers vs. letters.
Your example shows adding 'A' to ch and then subtracting 'a' - ALL character / alphabetic characters!!! This is not math! This is gibberish. Who knows what the result will be? How can you count on it?
I was able to figure out that in the previous example of 50000 / a = 515 that a = 97 (roughly) this is algebra. But where can i find that a lower case 'a' is ALWAYs = 97 (roughly) - and why would i want to?
In the real world, why would you ever want to do math with apples and oranges - numbers and letters?
7 years ago
I have found a link that describes "data type promotion" here: http://www.java2s.com/Book/Java/0020__Language-Basics/The_Type_Promotion_Rules.htm
But how in the heck can a character value of 'a' be converted to a numeric value??? Why would you want to? This doesn't make sense to me.
One example they have is dividing 50000 by 'a' = 515. Really? What the heck is this? This is akin to dividing 500 miles by 'apple' it just doesn't make sense as to why this is allowed.
7 years ago
On the next page of the study guide / Study Tips there is a list of 5 initializations of a float variable.
Why does compile?
If the compiler is determining the data type, why would this one work? Wouldn't it define this as a short or int?
Why does it think that this is a float data type?
The problem is that it seems that in order to pass the OCA/OCP tests that I will need to "think" like a compiler. So I need to understand what is happening here.
7 years ago
Okay, thank you Ajinkya
7 years ago
So, if I am understanding this correctly - instead of the compiler looking at the value and allowing it IF it meets the primitive data types attributes,
it is looking at the value and determining the data type to use regardless of the developer preference.
7 years ago
I am posting here because I "think" this is just a basic Java question.

I have just received my Scott/Jeane OCA8 study guide and am getting tripped up right out of the box.
In Appendix B/Study Tips there is an example of "trying it yourself" that says that the following line will not compile:

Okay, simple enough.
The "issue" is that the compiler cannot convert from double to float - okay
The correction is to do either;

or

But looking online, or at the Java Complete Reference, or at a Java textbook I cannot find WHY the original line would not work.
I have found many explanations of single precision vs. double precision - I get that.
Both of these data types hold floating point numbers.
The value being assigned to the variable is not so large that either data type could not hold it.
So why does it work for one and not the other?
What makes the compiler recognize the value of 102.0 as a double and not a float?
Why can't both data types be used with this value?

7 years ago
Thanks for the link, Paul.

However...
The part that talks about Firefox: I cannot find the plug-in the link mentions "Java (TM) Platform". I looked through all 190+ entries and it was not there. Also, I may have misspoke, my Firefox version is 44.0.2 - unsure if that is the latest for Win 7.
The part that talks about Internet Explorer: I followed the instructions and "allow scripting of Java applets" was already enabled (no changes made).
And I verified that "Enable Java content in the browser" is checked in the Java Control Panel.

So, following the instructions from the link you provided did not yield anything. I still cannot run the demos I mentioned.

Mike
8 years ago
Hello,

I have used java in the past, but not enough to be as proficient as I'd like to be. I have purchased the OCA and OCP study guides from Scott and Jeanne to help me step up my game.
That being said, I have just installed the SE 8 JDK (version 1.8.0_74) 64 bit on Windows 7, waiting for the study guides to arrive.
When I try to run either the Animator or Bar Chart example htmls from the demos.zip file, I get the following error:
alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag!
I get this error whether I try to run it in Internet Explorer or Firefox - both are the latest versions.
Any ideas as to what the problem/solution is?
This is probably a real basic question, but I could use any help you could offer.

Thank you,
Mike
8 years ago