Chad McAte

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

Recent posts by Chad McAte

Ok so neither class was defined with a package statement. Ok so default access modifier only pertains to packages, I proved that using eclipse. After creating my project and to seperate packages the IDE was stating getBottles() is not visable.

So why am I able to access int getBottles() when a package is not declared. I know its not proper if this was a stand alone class not to specify public or private just trying to understand why this happening.

6 years ago
Ok not sure but doesn't seem like int getBottles() is defaulting to package-private. Was trying to prove it by putting class files in separate folders



Programming\Java\Packages\A javac -cp .
C:\Programming\Java\Packages\B>javac -cp C:\Programming\Java\Packages\A
java -cp C:\Programming\Java\Packages\A;C:\Programming\Java\Packages\B StartBeerSong

And the program compiles without an access error. Is there something else Im missing about access modifiers?

6 years ago
From what I'm reading if you don't specify an access modifier the default is package private.

when I declared a method private int getBottles() and try to access it via  main class I receive  getBottles() has private access in BottlesOfBeer. Which is fine.

Now when I don't specify a modifier, such as int getBottles(), I do not receive the access error. System.out.println(newBeerCount.getBottles()); and it prints out no errors

Does the default package private only for declaring Class modifiers. Everything I have read thus far states that it is the default for classes, fields and methods.

Ok as far as packages go. Both BottlesOfBeer.class and StartBeerSong.class reside in the same folder which I created. Have not declared either class as being part of a package.

Does java treat a folder whether declared a package as a package? So being that my folder Java contains both these classes, it is not generating an access error because these classes are in the same folder.

6 years ago
Is it common to leave Activity Name set to the default MainActivity when creating a new project vs something more descriptive like MyAppMainActivity or MyAppStart ect...
6 years ago
I  brought up the book reference because they say one thing and then do another. IE class names should start with an uppercase letter yet they use all lower case letters in their class definitions like public class myclass .
No Im referring to the usage of numberOfWatts. Everything is numberOfWatts. class variable, method parameter variable. So what I am asking is whether that it's proper coding practices vs

private int "numberOfWatts"; //wattage

public void setNumberOfWatts(int "watts") // To me this seems to create some kind of separation from class code and arguments passes to its methods via objects.  
this."numberOfWatts" = "watts";              //

Sorry if this is  little confusing this is week 1 for me and all my terminology isn't greatest, just don't know how else to word it

6 years ago
Is this really common uses of variable names in classes: ie numberOfWatts used for every declaration and parameters.
I have noticed they do this a lot also in java class explanation such as (Context context). Which as a beginner to programming
is really frustrating trying to understand the description when you see Context 20 times in the same sentence. Mainly want to no if
this is good programming practices. The book Im reading seams to contradict itself quite a bit like saying the naming conventions of classes should
start with an uppercase letter however all their examples you lower case for all their coding.

private int "numberOfWatts"; //wattage

public void setNumberOfWatts(int "numberOfWatts")
this."numberOfWatts" = "numberOfWatts";
6 years ago
why does this result in -128?
int a = 128;
byte b = 0;
b =(byte) a;

why does this result in 44
int a = 300;
byte b = 0;
b =(byte) a;

I think I understand the fact that you wouldn't cast this way. Just trying to understand the output. If I am correct you would use casting when you have something like this
              int a = 50;
              byte b = 0;
              b = (byte) a * 2;
Although 50 * 2 = 100 which is in the range of byte, the use of the operator automatically converts the expression to an interger. Thanks for whatever you care share.

6 years ago
Ok this is what I misunderstood. The book states while talking about packages, that if my class files where located in a subdirectory of my current folder Java would search the subdirectories automatically for the giving class.
What they meant is that once you point java to the directory that has the defined package folder it will search the package folder and all its subdirectories for the given class.

TYVM for the help.

7 years ago
Trying to work with packages to learn Access Modifiers and the ins an out.

<DIR>          A - //same as the package

How do I run this from command prompt.

From what I understood I would I would use javac from c:Programming\Java javac

then tried this

C:\Programming\Java\SCJP>javac -cp \A

C:\Programming\Java\SCJP>java -cp \A B
Error: Could not find or load main class B

what am I missing

7 years ago
Ok so what I have done so far using windows 10. Have created a environmental variable to point the jdk.

C:\Users\mcatee>echo %java_home%
C:\Program Files\Java\jdk1.8.0_131

Then added this to my path variable

Wow so frustrating now it works. HAHA Ok gonna post this anyways. The problem I was making was switching back and forth from
the GUI to change variables and then going back the console(command prompt) and trying to run the commands, javac. Each time you change a variable in the
GUI you need to close the console and reopen. Watched three different videos, each was different, which had me changing the variables.
Talking about path and classpath ect... really jumbled my brains a bit.

If I finally understand this please correct me if Im wrong.
Path variable simply tells the computer where the java.exe and javac.exe are located. So when the command is executed if that
.exe file doesnt exist in the current folder it then checks all the path variables for that .exe.

Ok now for CLASSPATH if I finally understand this corrected this is just java related, not system related. Use classpath when
multiple class files are located in different locations ie different folders. So like the path variable for the system, Classpath tells
Java where to locate the needed Class files.

Do I have all this correct now TY

What a frustrating 4 hours
7 years ago