Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChaz Hall
1,970 PointsI'm not comprehending the main structure of java.
I don't know why I'm having a tough time with the concepts of java structure. Source File->Class File->Methods->Statements.
Can anyone ELI5? Maybe use the example of some type of game, in very simple terms?
1 Answer
jcorum
71,830 PointsA proper answer would be quite long. But I'll start with the first part of your question. When you code in Java you write text, usually in some IDE. That text is saved in a .java file. When you compile, the text is translated into byte code and saved in a .class file. When you run your code the JVM converts the byte code into machine language code. The rules are: the .java file must be named the same as the class name. So if you write a public class Student {...}
the file must be named Student.java
. And when you compile it the byte code file will be named Student.class
.
In Java methods must be inside classes. In some languages they are called functions
outside classes and methods
inside. But in Java they are all methods. You can't have functions (i.e., methods outside classes). Methods take 0 to n parameters as input, and may but do not have to return something. So methods can have parameters and a return type. They also have a code block, which is a set of one or more statements inside curly braces.