 Hey everybody, this is Brian. If you're watching this is our fourth video in the Java series and as promised We're going to be covering a little bit more about classes and what happens behind the scenes here So as you see we've got our project with our source folder our default package Remember anything that you don't define a package goes into the default package. There's start.java This is our actual code file and if you expand this out you can see that we've got Start which is the name of the class see the big C there and then main that's a method. So there's start and main Now public is an access modifier. You can have public private protected That determines who can see what will be covering access modifiers later But just know that you need an access modifier. You need to tell it who can see this So because this is the beginning of our program we want everyone to see it Class just says that this is a class now The typical structure of a class looks something like this class name bracket and bracket You don't always need an access modifier. I kind of lied to you. I know I'm sorry. I try not to do that, but In Java you need an access modifier for your class instance In a file start.java is the name of the file. You must have a class called start You cannot have start.java and call it Kitty Java won't like that Let's do public You see it's already complaining It's saying the public type kitty must be defined in its own file Now we can get rid of this access modifier and this is Allowed because this is not a public class. This is a default class So start is in its own file and we can have default classes in there defaults just an access modifier Now these brackets denote the start and stop of a code block that is a code block Anything in here is code that will be executed inside the kitty class Now we have methods Methods being like this public static void main If you've been with other languages like c++ or csharp or even visual basic, you'll kind of know what a method is It's similar to a subroutine and visual basic and you will say public whoops void test You see the structure is similar We have an access modifier. You can even take the access modifier away and give it the default access modifier Void means it's not going to return any data to return type Test is the name Let me pause this for a minute guys the cat's begging for my attention. Sorry about that. Now let i'm cat free. We can continue All right, where are we? Oh, yeah The void means it will not return anything. You must always return something or tell it explicitly You're not going to return anything from a method test is just the name And then your argument list we're not going to have any arguments. So this is just brackets and then your code block Now you can also Have arguments in here. It's like we will say int x So x would be an argument of an int type or integer. We'll go over variables another one Just once again showing you the basic structure Um, that's one of my pet peeves about java is it's Kind of difficult to jump right in because you have to understand the the framework and how everything glues together before you can actually start working in it But you have to work in it to understand it. It's kind of a chicken or the egg scenario That's why it's helpful if you know another language before you jump into java Even though most colleges are starting to teach java as a beginner course So let's just delete our kitty class. Sorry kitty. You just got deleted Um, these are comments And these are comments What's the difference here? Well, this is what's called a java doc comment the slash star star Whenever you do something like that, let's just do slash star star And you hit enter and you see it automatically adds author This is a java doc. You can run a program called, you know, ironically java doc and it documents your classes for you And it'll go through and pick out certain keywords like author or parameter And it'll tell you okay, the author of this is, you know, brian caron's the parameters are the arcs This is also a comment a comment There's two lines or whack whack as people call it and then whatever stuff you want to put in there the compiler Will not compile that you see how it's kind of complaining because this has got spell checking integrated into it Uh, pretty nice, huh? So we'll just say test And then system out print line hello world. Well, what are we doing here? Well System and this is the java lang system. This is a package that you are importing Automatically remember we were talking about packages And we're calling the out class And then we're calling the method print line which prints a line into the console And the parameters we are giving it is a string of hello world Now Let's discuss for a minute public static void banks. I know you're looking at this thing or what in the world is that That is a holdover from the old cc plus plus days the beginning of a program Needs to have this thing called the main method or the main function That's how the compiler or the executor knows Where your program starts It looks for the instance of the main program some language is going to only have one main Method for the entire program in java. You can have a main per class. So your program can start in any class It's very helpful for debugging situations Now that we've kind of gone through the structure of a class what's going on behind the scenes here you remember Start Application and then it's calling c program files, you know java w. What's going on? Well The compiler or java c Is actually grabbing the source file start dot java and compiling it into a class file and What is that if you go into your workspace here? You see there's metadata. This is added by eclipse And there's test. This is our project You got dot settings once again added by eclipse. You can see org eclipse, etc, etc And then there's bin source and then some more little files in here In bin which is short for binary you have start dot class. What is this? We didn't make this we made start dot java The compiler compiles your java files into class files that the runtime environment then executes All right, let's go back over that. That was a little confusing in the source folder You have start dot java. This is our java file the same thing we see in eclipse In the bin folder you have a class file. This is what the compiler creates Now if we try to open this let's select program from list Where's handy notepad here notepad You see a bunch of weird garbage Let's word wrap this. What is this? This doesn't look like anything that we typed Well, this is our class file. It's been compiled by the compiler What happens is java takes your your java files compiles them into a platform independent A little neutral language and then the runtime environment executes those So when you distribute your program, you're not distributing the source code. You're distributing the class file Now you can actually go back into the source and let's just Select program from list notepad Whoops notepad And you see there's your source code nice safe and sound Now just so you know This is not 100% secure secure this class people can use a decompiler Um, I think a popular one is jad or jad java application decompiler and they can actually Decompile your class file back into the original source code Highly illegal highly controversy, but I just want you to know it is possible People do it and other languages are not immune even you know c plus plus C sharp visual basic all those languages can be decompiled It's called reverse engineering something we'll probably cover Year or two from now when I start going over to hacker tutorials All right. Anyways, that's a totally different subject altogether Today you should be a little more familiar with classes and what they are the structure of a class Why we need this main method and how to print something out into the console Thank you for watching. I hope you found this video educational entertaining and as I said I am going after the sun certified java programmer certification. So expect to see a lot more of these