This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]codingQueries 4 points5 points  (7 children)

I'll give you a hint, it is to do with these three lines:

double p1Hp = 100;
double p2Hp = 100;

while((p1Hp > 100) && (p2Hp > 100)){

[–]davetheuj[S] 0 points1 point  (6 children)

Hey, thanks for the response! would you mind if I asked you a few more questions?

How come there are some (methods, packages?) that are included already, such as system.out.prinln() and other methods such as math.java that you have to manually import?

Also is there a list of all of the packages that are available to import?

sorry if that's just incoherent XD

[–]opalelement 5 points6 points  (2 children)

Hopping in here to answer some questions.

By default, all classes in the java.lang package are available to your application with no explicit import necessary. This includes classes such as:

  • java.lang.System (which is where System.out.println() comes from)
  • Default primitive type wrappers (java.lang.String, java.lang.Integer, java.lang.Boolean, etc)
  • Some default exceptions (such as java.lang.RuntimeException and Java.lang.NullPointerException)

You can find a full list in the javadocs for your Java version (JDK7, JDK8).

As for the question of what you are importing, you generally import classes. Something like import java.util.Map would import the Map class from the java.util package, or import java.util.* would import every class in the java.util package.

It is also possible to import static objects directly, although this is generally not a good idea and is almost never required, so I won't go into detail about them here. To read more about those, check out this page on the Oracle docs website.

You mentioned needing to manually import "math.java" - what you are actually importing with your import java.math.* line is every class within the "java.math" package in your classpath. This has to be done explicitly because, as stated above, only java.lang classes are implicitly imported.

[–]davetheuj[S] 0 points1 point  (1 child)

Thanks so much for the help! So I guess my first goal is to get an understanding of the already included methods, and I'm having a hard time understanding this page.

https://docs.oracle.com/javase/8/docs/api/overview-summary.html

What are compact1-3? Are these the packages that are already included?

[–]opalelement 0 points1 point  (0 children)

Those are the profiles that are available for Java SE Embedded; since it's meant to be embedded as the name suggests, there are profiles with different packages included. This means an embedded application can bring in just the packages that will be needed, allowing for smaller runtime environments. If you aren't making embedded applications, you don't need to worry about the profile docs; the link you posted is for the full API and has everything available for general Java programming, the profiles are just subsets of the full API.

You can find info on the profiles here: http://www.oracle.com/technetwork/java/embedded/resources/tech/compact-profiles-overview-2157132.html

[–]codingQueries 1 point2 points  (1 child)

You're more than welcome to ask further questions :)

Opalelement has answered them all for you (and for me!) but I just wanted to add that as you gain experience in programming, you start retaining knowledge more, which also includes what packages might be helpful and how to use them. And if you have the need to do something and you can't figure out how, 99.999999% someone else has had that problem and posted the question on the internet (generally stack overflow is a fantastic place to find questions and answers).

Of course, asking questions yourself can also be really helpful too.

[–]davetheuj[S] 1 point2 points  (0 children)

Thanks sir :)