Curso de Java #04 - Primeiro Programa em Java - Gustavo Guanabara

1.19M views4172 WordsCopy TextShare
Curso em Vídeo
Aula completa disponível em http://www.cursoemvideo.com/lesson/primeiro-programa-java/ Como criar u...
Video Transcript:
Introduction ♫ Music ♫ Hello! Welcome to another lesson of their course of Java. My name is Gustavo Guanabara .
. . I'm your teacher .
. . And in the first three classes of the course, if you remember well We saw a very large theoretical basis.
In the last class, including, we installed the JDK package And now, in this class, we will make our first Java program! Yes! It is time that everyone expected It's time to put your hands dirty Open your NetBeans, and make your first program, which is the "Hello World!
", Right? Who is not my student, or who never took a course with me Do not know the curse, right? Legend has it that the curse of "Hello, World!
" The following is: If you are learning a new technology development And it does not appear on the "Hello, World! " You will never learn this technology Again I say, do not know if this is true But you will risk? I will not.
. . And it's important that I tell you something that time There are people who come directly in this class Digita there on YouTube, comes this fourth period Guys, this is the fourth class of a course You need to have knowledge of the first three So I say again, if you come now, you did not hear me say that Many people think Java difficult Many people have difficulty in Java And one of the great difficulties of Java, is you skip the first steps So do not skip the first steps, it is very important Click here O, here you will be redirected to a PlayList And in it, you will see all classes So, back there in the first class Watch It is the story of Java Then there how Java works It is important you know how to differentiate What is a JVM, which is JDK, which is JRE What is JIT, What is Java EE, Java ME, Java SE So it's important And then, in the last class, and showed how to install The JavaSE, JDK package with NetBeans If you have not attended previous classes That's what I just said is a mystery So back there and watch the lesson Without further ado If you are a smart grasshopper, and arrived here in evolution You're all ready to start your first program [Noise coffee cup being placed] So let's get ready here for the First Program All Java program can be comprised of packets Our programs will be made up of packages The first command you will have to give in your program, it is the package command Then you will use "package primeiroprograma;" This command is actually optional when you will make the First Program So I'll leave it half transparent here.
First command that every Java class has to have is precisely the class header Then I'll put it there, "public class" and the class name At the end of the line you realize there I opened a key ({) Important is that you on the bottom line, skip a few lines, close this key. (}) and there if you already know C, or did our course of PHP, you are already familiar with this key thing. the keys in the languages, in various languages, are blocks, then all is among key opens and closes key, is a block, all you have here in the middle [of the key] is considered a block then a Java class is a Block Within the Class Pack we will create a method, which is the main method Main in English is "main" And then you should be with a guy like O  [Bulging eyes] "Our command that did not understand anything!
" Do not worry you will not even need to decorate it right I'm going to show a trick for you But so do I have memorized: is "Public static void main" Among relatives I put String, open and close brackets, args, It is not that hard, opens and closes block with practice you will get, but if you do not want or need you, I guarantee to you so if you have the cheapest possible English course or if you read anything in English you know certain words, for example: "Package" package is package; the word "class" means Class; and the word "main", as I have said means primary. so I have a main method, within a "PrimeiroPrograma" class, which is part of the package "PrimeiroPrograma" I will repeat to you that is learning watch, from the bottom up, read the below red upwards I have a main method Which is within the class "PrimeiroPrograma" Which is part of the package "primeiroprograma" It was clear? You want me to repeat?
Back video It is important that you understand this hierarchy I have methods Classes consist of methods, and I can have multiple classes within the packages I have a method in a class, and the class is part of a "class packet" It was clear? This is how it works in Java. This is a major step for you to build your program Now an important thing, do not know if you noticed, you've probably noticed It is that some things are written with a capital letter, other tiny and you're thinking .
: "Ahh whatever . . .
" No, do not so much! There is difference of upper and lower case in Java, it will differentiate is a mistake you forget to put a capital letter, or just tiny, I'll show you how it works the technical naming identifiers in Java. Basically works as follows if you are here to realize my "package" was written all in lower case already the name of my class is the first case written letters are two words, "PrimeiroPrograma," and these words are divided actually identifiable through the first capital letter the "main" for example, on the bottom line, okay entirely in lowercase we see here the first command that you really will have to learn this command will write something on the screen the command to write on the screen is: System.
out. print ( "Hello, World"); and if you notice, System's with a capital letter. Then set and this command that is in yellow System.
out. print in brackets in quotes, Hello, World and point-and-comma at the end This is the command you will need to decorate so far So, no need, no worries about others, we're just focusing on capitalization sensitive because it is a basic course, but watch the command that appears in yellow and we saw have to replicate it. "Replicate where Guanabara?
" In your NetBeans you installed last class [Noise coffee cup being placed] I'm already here in my operating system environment here I will open my apps I will come in NetBeans and I will open the NetBeans. You open there on your system as needed will be displayed this screen 'loading', wait a few seconds the first 'loading' usually takes a little longer but she saw it was quick We have opened the main screen of NetBeans The first thing we'll do is create a new project To create a new project, realize where my NetBeans was in Portuguese, he identified . .
. the language of my operating system, I can come in File -> New Project or if you pay attention here, you can click the "yellow piece of paper" that's here Then I click here, New Project or there File -> New Project This my new file via being "Java" "Java Application", which is what has already been marked I'll click Next, and I will call: PrimeiroPrograma the name of my project will be PrimeiroPrograma and I put the first P in capital the first letter of each word in capital letters without much space between them, may not have room I'll leave here marked the creation of my main class and I click Finish few seconds will pass, he's creating our file system and he saw to create here in the corner our first project notice the following in my class, everything's with java is my class you'll notice here: public class PrimeiroPrograma all those lines that are gray, they are comment lines then we'll see in more detail, but they follow more or less the same pattern PHP language or C language if you already know, if you do not know has no problem everything in gray are comments so I have to PrimeiroPrograma class and I got my package PrimeiroPrograma so I'm just, if I delete here, you do not need to delete but . .
. they are comments at the moment are kind of useless I will delete here, no need to delete your okay, and only for didactic issues So I'm doing here, I'm with the package, the public class and the public static void main So this is how I spoke with, you need to decorate those commands? No!
because the IDE already entered for you, remember what I said last class, one of the great advantages of IDE she is alone create commands for you, okay there, but you will say, "But it's bad because he created alone" is not right, do not need it, all right already created there, you remember the right command System. out. print and between brackets and quotation marks "Hello, World!
" Even in that it will help you, watch, remembering that the System is with a capital S already now you will see why. Inside the main block I'll put: System by the time I hit "point", it will now give me some suggestions . .
. Err, in, out . .
.   in my case is "out" "Score" Which method? "Print" and "String" I'll give 'enter', it will already suggest 'null', I do not, I will open quotes, quotes when I open it will now close and I will write: Hello, World!
ai count how many letters you had to press, the command is great? Yes, but you just typed: System. the 'out' I did not have to type, I just chose and I 'enter' put the "dot" typed p, I chose 'print' I wanted, which is the 'print' and 'String' gave 'enter' and he has written to me, so this is so, the IDE makes it NetBeans will help you with that, obvious that other IDEs will facilitate you, Eclipse, the InteliJ will help you in the same way, but in this class, I have to choose one, my focus was on NetBeans My justification is the IDE that is distributed officially by Oracle, then right Choose this there, and there is another advantage of the IDE, with I told you once you had to open a window, write your code he has written most, I just wrote a line here by typing a few letters then you had to close the program, save, close the program, compile entering a terminal, if it did not come back, not now, I just press a button I will use the mouse and this finger, this one With this finger I pointed out to you, I will come here, and I just hit play That's it, no need to save does not need anything, he has saved, he has done all At the bottom of the screen if you pay attention he wrote "Hello, World", and then: BUILT WITH SUCCESS [Sound of blowing] A finger .
. . Java is difficult?
Is not difficult, people is that difficult, and I will show a wonderful trick that NetBeans has My command is: System. out. print I'll delete it here right?
You authorize me? I'll write in lowercase: 'Sout' 'Sou't would be "System out" . .
. press the "Tab" key on your keyboard It's magic . .
. he has written, if I write: sout it will automatically put "System. out" You will use the "println" which is like the "print" actually "print" he writes on the screen and "println" writes and jumps down line If you took the course Algorithm, and you have to have done, is: write, and escreval I'll tell you, do not stop there, you will say: "This command" static public void main strings args " !
? Is difficult, "Yeah, but pay attention: public static void main . .
. public static void main I will delete this whole block're . .
. If you allow me . .
. lowercase: PSVM (public static void main) press the Tab Java is difficult?   At where?
I will put the 'sout' here, press Tab Have you ever played the 'System. out' . .
. 'Hello, World! ' I will run, press play he will write: Hello, World!
. . .
Realize here that he wrote "SUCCESSFULLY BUILT" below this because I used the 'println' in place of 'print', if I write only 'print' and apart from play, CONSTRUCTED will be on the side, if I put 'println', all in tiny it gets down Eh eh . . .
let's continue, because . . .
can not afford, it is not difficult So back where we stopped on the slides, it is as follows: You realize then that the arrows are pointing them, primeiroprograma; all lowercase PrimeiroPrograma with the first capital letter and the System with a capital S it makes sense, and it has a name, it has to do with: Camel (Marcelo Camelo) sorry, this is not camel I mean: Camel Camel, one that goes up and down, up and down his back that's how it will work When we want the name of a class, e. g. I'm going to name my class: MyClass then Note that the M and C are in uppercase even to exaggerated Capital letters will be as if the camel humps my capital M, then down Class C capital, then down.
The name given to this technique is CamelCase, or camel box technique. It is important that I say here that java is entirely Case Sensitive. So he's sensitível the box.
high or low box. Box high for the beginning of the word and lower case for other letters. And you will say, "Gee pear there, have time there that everything was in tiny .
. . .
. . There are times when tava the first capitalized, I was confused!
" I will show you how the CamelCase works! The CamelCase technique uses some rules: Whenever I have the first letter capitalized such as: AlunosCursoEmVideo Note AlunosCursoEmVideo there are 4 words the first letters are capitalized. Where the first letter is capitalized it indicates a class or an interface.
has no error, the first letter capitalized and the rest using CamelCase or is class or interface is for our course here, only class, we will not see this interface basic course But whenever it appears, it appeared the first capital letter you can be sure closed the eye and speaks thus: is a class You can tattoo it makes a tattoo: the first capital letter is class but writes upside down, for when you look the chest to read If the first letter is lowercase and other words are as CamelCase it can be an attribute, a variable or a method And no worries about this theory now more forward you will see what is an attribute which it is a method, which is a variable parameter which is And then you'll come back in this class and say: "Aaahh, then this is it! " Only here to showing and demonstrating CamelCase so you hit the eye, you will know what it is, or an attribute, or a variable or parameter or it is a method. Let's see some examples As an example of attribute I can mention here the nomeAluno as variable: mediaPrimeiroBimestre Method as: lancarNotaAluno realize then that the first letter is always lowercase and other words will use the CamelCase the first letter capitalized and the rest lowercase If I put nomeAluno capitalized automatically it is a class or interface as it is an attribute, lowercase first letter If you find words only with tiny, you can be sure, it is the package name for example alunoscursoemvideo the low alunoscursoemvideo is the name of a package the AlunosCursoEmVideo, the first from above, is the class name And you can also find all capital letters which will set the name of a constant, such as VALOR_DE_PI, which is always constant He gave to understand how the basic rules of CamelCase?
First letter capitalized and the rest in CamelCase: class or interface First lowercase and the other in CamelCase: variable, attribute, or method parameter All lowercase: package, All capital letters: constant It was clear? If you want more forward you can repeat this lesson always remember that it is the class 04 - First Program in Java is then just you go back and check there, but with practice you will get used So let's work the code we saw earlier. Here is the code that we have assembled.
Even you have to run and got rid of the curse. Very important that. To get rid of the curse is not only attend class and see working.
You have to do your. I got rid of my! If lyre of yours, send over there!
For example I can say the following: primeiroprograma, the first line all in lower case: package name PrimeiroPrograma the second line: First Capital Letter Class The main, on the third line: small letters. Method Then you will say, "But Guanabara, all lowercase letters is package name. " main is one word if I had: mainProcedure or mainMethod main with "m" tiny method with "M" capitalized.
Right! When one palvra: all lowercase. which will set up which is a method that is here, look the presence of the word "void" indicates that it is a method, and mean void "empty" further ahead you via better understand Note the line that is yellow: System is the first letter capitalized Take a look down, lé in your tattoo that is written First letter capitalized what is it?
It can not be something else, or is class or interface is, as I said in our basic course, only class And something very criticized in Java are your commands rather extensive But I will justify this extension, with a simple way Java was not made for computer only the System. out. print does not mean "write on the computer screen is "write anything", we will look better this command As I said earlier Java is compatible with various types of system For example, the cell, including those older .
. . or you do not remember when you entered the game snake .
. . those ugly games from your mobile old first appeared that Java cup, and was a long time charging.
You know what it was? Your JVM starting to work! Now you know.
So let the most basic review of English class . . .
alfabetizável When I put System I mean system and system for Java can be any system not necessarily a well screen, or well screen can be inclusive, this here, this here is a system, and is completely different from this So why do I need to indicate SYSTEM Soon after I put 'out' which is output. And again, the output of each system is slightly different. For example: The output of a clock can be a small display.
This one for example is a system. Pressed here . .
. Look at his output. And unlike this output.
I can not say that output is always a screen. The output can be a "displayzinho" so . .
. So if the clock run Java, the 'System. out' is this small screen.
Then we have 'print' which is PRINT or SHOW. And each system with its output set has a way to print. Get the idea now because the commands are great?
I need to explain this. It is my system, having an output which will print. So in the case of old cell, the 'System.
out' is the screen it. If the computer is the monitor. And in the case of the watch and its display.
'System. out' are those red squares. '.
print' Is a method (as it is in lower case) is going to write each of these screens:! 'Hello, World' It was clear? But the big problem is this, looks like he's our 'Hello, World'.
Our "Hello, World" is in 'System. out. print' this screen 'print'.
This this terminal screen. Ugly as hell, neh ? !
So I did for you other three forms of 'Hello World'. Pay attention! All made in Java.
The first was using a graphical interface that generated this first program. Look, now we are already in a "small screen". Has the 'Me Press'.
When I press . . .
Hello World! I made another too, which is very similar but uses a different form of development. It looks like the other, neh ?
! 'Me Press' Pressed . .
. Hello World! These two visually appear, but were made with different techniques.
These techniques you will see here in the Video Course. The third technique is the one you'll like. I will show you.
. . .
. . In my view!
[Coffee noise being placed cup] As I told you . . .
This one is the Android system. The Android system was made in 'C' language, but the applications of it are done in Java. Then I come here .
. . .
. . I created some applications .
. . Between them.
. . .
. . The 'Hello World!
'. Look that! It is more or less the same system previously .
. . .
. . With the 'ME TIGHTEN' .
. . When I press, he writes the 'Hello, World!
'. Included is compatible with face screens. The button not gone there.
All this, done with Java! [Baruho coffee cup being placed] And then, like it? Then so are different systems, methods are somewhat different developments.
But they are all based on a single thing . . .
Java! So this is encouragement that I have to give to you. You learn to program in Java, you can plan for everything.
Desktop, mobile systems, wearables, for smaller systems, portable systems . . .
So Java it is sensational. A complete language. And so it has more complete commands.
And it is these more complex techniques that we will see in the next class. In class next week. I hope you have practiced this class.
It's no use you just watch the video . . .
. . .
Sit down and stay that way, oh! "Okay, I know Java! " No use will not work that way.
So you have to take a study, practice, see how it works. In our case here, these first four classes are the first steps. We're still in its infancy in Java.
In the next lesson, we will learn how libraries and APIs. For example: Swing and JavaFX. So we can continue the basic part of Java.
So the next lesson we will do . . .
You know these two 'Hello World! ' we put here on the screen? Next week, I'll teach you guys how to do them.
And as that is geared for that theory. How do we use API's. How we use external libraries to further enhance our programs.
I hope you're enjoying the course. There are people thinking it is too slow . .
. People! It is a course for beginners.
It is a course for those who never come close to Java. But you have a job during that week. It is reviewing the course Algorithms.
So here oh! www. cursoemvideo.
com Accesses there, will the Course in Algorithm Video and there watch the first classes. No use you trying to learn Java if you do not know algorithms. If you are our student PHP you know it.
But if you fell parachute here, like hell all that I said. All working together. Java developing for multiple platforms.
Running on Windows, running on Linux, running on Mac . . .
Did you like it? So your first step is not to learn Java. Your first step is to know and algorithms.
Here oh! Has Course in Algorithm Video. There you will study!
So you have a week to give their complements. If you are more or less in college ta suffering a little with Algorithm? Take a look there on the course, has also certified.
It makes classes all cute. See you next class. With this, you need the next class already have everything installed, practiced .
. . All the tools, all working cute and the concept of algorithm.
This is your homework, we'll see you in the next class! By clicking here, as always, you will subscribe to the channel. By clicking here you will get the Playlist of all classes.
You are seeing this already here a while ago. Then just click that you will be taken directly to these areas. Do not forget to always practice, do not forget to keep on studying.
Do not forget to show people this class. That's a good lesson to show who ta coming. Get there, publish on your Facebook, your Twitter, your Instagram .
. . Wherever you want!
"I'm watching the class, the link is this one oh! Go on and studying my mate! " That's what we'll see.
We will see growing number of students the Course In Video has. A big hug to everyone, small grasshoppers, we'll see you in the next class!
Copyright © 2024. Made with ♥ in London by YTScribe.com