They will create our first application in Java language.
Be prepared to have fun.
Also in this lesson, you will learn what our console applications, how to compile Java code to get
bytecode and how to execute your first program from console.
Let's start.
So what a console applications console application is an application that takes input and displays output
at command line console with access to three basic data streams, standard input, standard output and
standard error.
These applications don't have any graphical user interface.
They are primarily used nowadays in learning purposes.
So console application is a lightweight application which might be easily run in console.
During this course, we'll learn tools which we have in GDP to create powerful applications, but the
same as learning as a human languages.
The first thing you learn is alphabet.
After that, no letters.
You can create words from words who can create sentences from sentences.
You can build a story.
The same is here will start from console applications to learn alphabet and words.
Here is what we are going to do today as a software engineer will create with you files with Java.
Extension will call this files source code.
This is exactly files where programming code written in Java will be stored.
After that will ask Java Compiler to compile source code to bytecode.
Java program will do this task.
Java will produce files with class extension and Java will execute our program.
What do you need to understand?
And remember that Shivam doesn't execute Java files.
Jivin executes class files properly.
This will help you in the future when you will troubleshoot issues in your real life project.
So now let's take a look how to create your first program, how to compile it and run theme.
Please don't be afraid.
You won't use common line to write your programs on a regular basis.
In the next, lessons will run special desktop applications designed to create programs.
But now I'd like to ask you again to open a common line wherever you want on your computer.
For example, for this lesson I created folder where I will create a program together with you.
Let's type seemed easier to open a common line probably using right now.
And you must be kidding me.
Why do we do this?
Why don't we just start work with applications which help us to create programs?
The answer is there are a few points to consider.
The first one you need to learn how to work with console at least some basics because sometimes not
always, but sometimes depending on which built tool you will use, probably you would need to work
with console.
And sometimes as software engineers you would need to write scripts which will call command line comments.
Real life example.
You would like to compile all Java files in your project in one archive, which will be deployed to
the Web server afterwards.
Right after compiling, you would like to run specific files, desk classes to be sure that tests are
not failing in case tests are succeed.
You finish your build process in case there are failures in the tests.
You don't proceed with your build.
That is one of the examples where knowledge of common line comments might come in handy.
The second point to consider Guice.
You had just started learning Java.
You need to understand what compilation process is, what is compilation error and how it is different
from runtime exception.
That's why I ask all my students to create program in Notepad and to run it and console at least once
in their lives in some conference on the first level of interview process of junior software engineers
where you have quizzes and tests, sometimes there are also questions related to common line.
We opened the common line to create file with Java extension, why we cannot just do mouse right click
and create file because you need to enable showing the file extension first in different Windows version.
It is done in a slightly different way.
And from default options, you can create file with the extension, which doesn't work for us.
So let's create file from console because it is easier and it's the same way to create file from the
terminal on different Windows versions actually.
Now at least a few ways.
How to create file from command prompt.
But let me show one to you.
Type the following notepad.
Hello World Dot Java.
When dialogue is popped up, click yes.
Now we see file with Java extension created here in case you have Mac just type like this.
Dutch Hello, World Dot Jalaa.
The file will be created.
Let's write our first program, we'll cover right now basic syntax so each Java file can have only one
public class or interface.
We'll cover more modifiers during all be topic.
But for now, just try to understand that in case class is public, client can access it from anywhere,
including our game, which needs to access this class.
The name of public class should be the same as the name of a Java file.
This is true.
In either case you would have compilation error Gervais's case sensitive.
So hello world written with Capital H at the beginning is completely different from Hello World with
H lowercase.
Java is a case sensitive because it uses a C style syntax case.
Sensitivity is useful because it lets you infer what the name means based on its case.
For example, the Java standard for class names is uppercase in the first letter of each word, for
example, like integer string, etc..
The standard for variable and method names is lowercase, the first letter of the first word and uppercase
and all other first letters.
No print, learn, Czech error, etc.
And the standard for constants is all uppercase was on this course, some constant like this.
So after hello, world, let's put curly braces here in Java, curly braces define SCOP.
Here is the scope of the class, in a few seconds, you'll see the scope of the method each otoscope
includes in their scope, zazz variable declared in the class scope is visible in the method scope,
but variables declared in the method scope not visible in Glasgow.
Now we need to create an entry point for our program by convention.
This method is publicly accessible, so let's type here public.
It is static.
We'll cover more what static is during or P topic.
It does return nothing.
That's why return type is void and it has name main by convention.
This method takes as a parameter array of strings in the next lessons will cover in details what arrays
are as of now.
Consider array of strings as a sequence of strings.
A parameter is a variable in the method definition.
When the method is called, the arguments are the data you pass into the methods parameters.
Hope this doesn't bring even more confusion.
I just want you also to learn the right wording to make your colleagues understand you.
Public static void main method, which takes array of strings, is our entry point to each Java program.
JVM knows that it should call exactly this method and begin program execution from this point.
Let's define scope of this method here in this method will write code which will print hello world text
to console output will write a system not out how to represent output.
Stream output stream has such behavior as printing to console print, to learn method prints to console
and terminate the line.
Each statement in Java ends with semicolon Prindle and can take strings as arguments that's postering
Hello World into it.
In Java, string literals are written inside double quotes and one more new word.
Literal.
Literal is a notation for representing a fixed value in source code.
Here we have string literal.
Now let's save this file.
Let's go back to the console and now let's compile our program, Javadoc Hello, world, that Java.
If you don't see any messages, that means compilation was successful and you can notice that new file
is appeared in our folder, this file has the same name as our Java file, but has different extension.
This file contains byte code for our Java virtual machine.
Now let's execute bytecode on our game.
Let's step Java.
Hello, world and press enter.
In this case, you don't need to specify extension for the file since Java expects only class files
and you see output here.
Hello world congratulations.
You have just written your first console application.
What are common mistakes?
You can see compilation error after calling Java and you can see runtime errors.
Let me reproduce it with you.
Let's pretend your name your public class incorrectly.
Not the same as Java filename.
Let's put capital G at the end and also let's pretend you did a typo in main method name.
Let's save the file.
Let's call Jack now.
We see compilation error, so code is not compiled to bytecode, always read these error messages,
they can help you to fix issues.
For example, like here, public class, hello world should be declared in the file with the same name.
We will just rename our public class.
Let's compile it one more time, but not forget to save the file before compilation process.
So now everything is OK and we don't see any compilation errors, and by the way, to call comments,
which I just used, I use up Arrow.
Let's run it again.
And here we have one time exception.
What does it mean, compile it?
But error happened during the program execution.
You try to find humane method, but couldn't hope this information will help you to troubleshoot issues
in case you will have once.
Let's recap one more time what we have learned today.
And now you know what console applications are.
You understand basic Java syntax.
You learn how to create hello world application in Java.
Also, you saw what compilation errors and the runtime errors are.
You can compile and execute your programs from the console.
And here's your homework.
Try to repeat everything what we did during the lesson by yourself.
Also, I'd like you to write that or shall file, which will compile your source code and we'll start
your Java application, try to do it by yourself with help of the Internet if needed.
And we'll check your homework in the next lesson together and read Java Code Convention from the link
here.
Pay extra attention to naming convention.
Java naming convention is a rule to follow as you decide what to name your intent to file, such as
class baggage, variable, constant method, etc. but it's not forced to follow.
So it's known as convention, not neutral.
These conventions, as suggested by several Java communities such as Sun Microsystems and Netscape,
all the classes, interfaces, packages, methods and fields of Java programming language and given,
according to the Java naming conventions, if you fail to follow these conventions, it may generate
confusion.