First Program and Some Tips

Complete Step By Step Java for Testers Java Concepts - Data Types
14 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.87
List Price:  €120.23
You save:  €34.35
£74.39
List Price:  £104.15
You save:  £29.76
CA$138.18
List Price:  CA$193.46
You save:  CA$55.28
A$153.39
List Price:  A$214.75
You save:  A$61.36
S$128.92
List Price:  S$180.49
You save:  S$51.57
HK$779.80
List Price:  HK$1,091.76
You save:  HK$311.95
CHF 80.49
List Price:  CHF 112.70
You save:  CHF 32.20
NOK kr1,009.67
List Price:  NOK kr1,413.58
You save:  NOK kr403.91
DKK kr641.01
List Price:  DKK kr897.45
You save:  DKK kr256.43
NZ$170.65
List Price:  NZ$238.92
You save:  NZ$68.26
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,159.63
List Price:  ৳17,023.97
You save:  ৳4,864.33
₹8,813.74
List Price:  ₹12,339.59
You save:  ₹3,525.84
RM422.70
List Price:  RM591.80
You save:  RM169.10
₦152,684.73
List Price:  ₦213,764.73
You save:  ₦61,080
₨28,172.18
List Price:  ₨39,442.18
You save:  ₨11,270
฿3,233.20
List Price:  ฿4,526.62
You save:  ฿1,293.41
₺4,116.73
List Price:  ₺5,763.58
You save:  ₺1,646.85
B$546.03
List Price:  B$764.47
You save:  B$218.43
R1,779.46
List Price:  R2,491.32
You save:  R711.85
Лв167.77
List Price:  Лв234.89
You save:  Лв67.11
₩139,375.48
List Price:  ₩195,131.24
You save:  ₩55,755.76
₪336.41
List Price:  ₪470.99
You save:  ₪134.57
₱5,711.89
List Price:  ₱7,996.87
You save:  ₱2,284.98
¥14,830.67
List Price:  ¥20,763.54
You save:  ¥5,932.86
MX$1,876.23
List Price:  MX$2,626.81
You save:  MX$750.57
QR364.02
List Price:  QR509.64
You save:  QR145.62
P1,342.46
List Price:  P1,879.50
You save:  P537.04
KSh12,918.70
List Price:  KSh18,086.70
You save:  KSh5,168
E£4,854.20
List Price:  E£6,796.08
You save:  E£1,941.87
ብር14,292.55
List Price:  ብር20,010.15
You save:  ብር5,717.59
Kz91,186.39
List Price:  Kz127,664.59
You save:  Kz36,478.20
CLP$96,831.31
List Price:  CLP$135,567.71
You save:  CLP$38,736.40
CN¥713
List Price:  CN¥998.24
You save:  CN¥285.23
RD$6,296.92
List Price:  RD$8,815.94
You save:  RD$2,519.02
DA12,990.59
List Price:  DA18,187.34
You save:  DA5,196.75
FJ$226.12
List Price:  FJ$316.58
You save:  FJ$90.46
Q765.93
List Price:  Q1,072.34
You save:  Q306.40
GY$20,890.84
List Price:  GY$29,248.01
You save:  GY$8,357.17
ISK kr12,333.76
List Price:  ISK kr17,267.76
You save:  ISK kr4,934
DH908.31
List Price:  DH1,271.67
You save:  DH363.36
L1,670.58
List Price:  L2,338.87
You save:  L668.29
ден5,277.34
List Price:  ден7,388.49
You save:  ден2,111.14
MOP$802.43
List Price:  MOP$1,123.43
You save:  MOP$321
N$1,761.48
List Price:  N$2,466.14
You save:  N$704.66
C$3,674.73
List Price:  C$5,144.77
You save:  C$1,470.03
रु14,082.30
List Price:  रु19,715.79
You save:  रु5,633.48
S/353.21
List Price:  S/494.51
You save:  S/141.30
K416.61
List Price:  K583.27
You save:  K166.66
SAR375.17
List Price:  SAR525.25
You save:  SAR150.08
ZK2,374.72
List Price:  ZK3,324.71
You save:  ZK949.98
L436.04
List Price:  L610.48
You save:  L174.43
Kč2,099.65
List Price:  Kč2,939.59
You save:  Kč839.94
Ft33,821.21
List Price:  Ft47,351.04
You save:  Ft13,529.83
SEK kr945.93
List Price:  SEK kr1,324.34
You save:  SEK kr378.41
ARS$136,092.68
List Price:  ARS$190,535.20
You save:  ARS$54,442.52
Bs690.01
List Price:  Bs966.04
You save:  Bs276.03
COP$400,414.31
List Price:  COP$560,596.05
You save:  COP$160,181.74
₡50,481.69
List Price:  ₡70,676.39
You save:  ₡20,194.69
L2,617.73
List Price:  L3,664.93
You save:  L1,047.20
₲721,217.97
List Price:  ₲1,009,734.02
You save:  ₲288,516.04
$U4,006.62
List Price:  $U5,609.43
You save:  $U1,602.81
zł365.33
List Price:  zł511.47
You save:  zł146.14
Already have an account? Log In

Transcript

Hello all welcome to the first lecture for Java. So in this one, what we're gonna do here is, we will actually start with our very first program in Java programming language. And it's very exciting cause especially for beginners, where you have never done any programming, this is your chance to get started and jump onto Java. So the first thing I'm going to do here is bring up Eclipse. Eclipse is the ID that we want to use. So you should have installed it by now.

Now we're going to bring it up. It says workspace workspace means where our project will be stored. So we will be creating a project. We will be working with Java, we will have lot of files that we work with. So this is the location where these things will be saved. eclipse will suggest your default location, but you can definitely modify it you can select Browse, and you can select any location on your system that you really want where your projects to be saved.

You can check this out After you select a location if you want, so this will not ask you again. But I currently will always as I might have multiple workspace location. So this is my current workspace location users a Toma documents, and then workspace personnel. So this is the folder that I created. And I want my project to stay there. That's why it is showing up here.

So I'm going to click OK. And it should bring up Eclipse. And I'll show you I'll create the project and then we'll see it on the folder as well. So I do have a lot of projects or do not worry about it, we will start fresh. So let's talk about Java a little bit. What is Java, Java is a strongly typed programming language, and it's an object oriented programming language. strongly typed programming language means in which each type of data Is predefined as a part of programming language, data is all the variables, any fields that we create, like if so, there's going to be a lot of things like strings, integers.

And you might not understand these terms right now, but do not worry about them because we will cover everything in detail. So what I'm trying to say here is if I want to provide a name to something, let's say john, john is a name of a person. It has characters to match and right, it's a string. In normal language also, it's a string. So that should be defined as string. If I want to give grades to someone, let's say I want to give 90 marks out of 100.

That's an integer in mathematics right. So that data type should be defined as integer. So whatever the kind of data we want to store, the kind of value we want to store. Those kind of data should be used to store those values. So those kinds of data types should be used, right. So all it means all the variables defined within a given program must use one of those data types only.

This is a strongly typed programming language, I cannot create a string data type and assign a value 99 to it, right. So, that's what I'm trying to explain when I say a strongly typed object, or strongly typed programming language, and object oriented languages, where we can create objects. So do not worry about objects right now, because I have a complete lecture on that with a detailed explanation. You can think myself, your computer, yourself, your phone, everything is objects in real world. They all have behaviors and states and we will talk about them in one of the future lecture. So let's let's not make this as the complex Get it lecture, we just want to get started with simple things.

So first thing we want to do here is we want to click New, and create our first Java project. Hooray. Right. So here I'm going to give the name to Java project, I'm going to call it Java tutorial. And that's about it. So I'm just going to click Next to see if there is something it can offer.

Or let's go back. It's it's, by default, taking my one dot eight environment as the default. So that's Java Runtime Environment, which it's going to use I know and we can change it from the properties. So let's go next. And this is how it's gonna look Java tutorial, it's going to have a source folder automatically created. And let's click Finish.

So there you go. Java Tutorial project. Our first project is created JRE system library these this is the default Java Runtime Environment it's using and we can actually right click go to properties Go through Java compiler, and we can see all these things here, right? One dot eight, it's using by default, we can click this box. And if we want, we can change these things as well. So what I can do here is I can use like compliance setting is one dot seven, actually, because one dot seven is also compatible.

But let's not play around with that one nowadays is good enough. If we see any issues we can, we can think about it. But here is the runtime environment Java compiler settings. If you go to build path, on the libraries tab, you will see this JRE system library. This is the exact thing you are seeing on the left side. Always make sure you have this Java system library if you do not have it, you know where to go now, right?

You can go to properties and Java build path. If you do not have this, your programs will not work. So let's click OK and move forward. The first thing we want to do here is we want to create a packet So right click this src folder, SRC main source, and click on new. And click on package. Create a new Java package.

So what does it do, it creates folders corresponding to packages. So basically, it will not do anything other than creating folders. And those are kind of a folders. For explanation terms, what it's gonna do is, this is the place where we're going to hold all our classes, every class is gonna be residing inside the packet. So this is kind of a high level structure. So I'm going to say is like maybe, introduction.

If that's a good name, I don't know. It can be any name. It should just make sense. Depending on the program that we're trying to do. And in future lectures, we will create more meaningful names. So for now, let's just call it as introduction and click Finish.

Now, here's my packets created. Now I'm going to right click New Add a class. This class, I'm going to name it as hello world. This is the most popular program in this world. Every programming language, we can start with the hello world. So let's print the Hello World in Java also.

And I'm going to select this public static void Main. Every class needs a main method, I'm going to click Finish. And here you go. So what the checkbox did is it automatically created this thing for us. This is a main method, if we did not check it, we will have to type it. So that was only for saving some time.

But we all need a main method. And in our we do have a methods lecture in future lectures, complete explanation about main method and other methods. So there's a lot of detail about this main method. So we'll talk about it later. For now, I really do not want to confuse you guys. Let's keep it very simple.

And these things are very important. So they need A lot of explanation. So there's complete different sections on public classes, we will, I will talk about classes and a lot more detail in future lectures, and these void keywords and all other keywords about the main method and other methods. So right now what we have is when we right clicked and we created a class, the first line is the name of the package where my class exists, which is introduction, then it created a public class HelloWorld HelloWorld is the name of the class and which is exactly same as the name of the file. Then it created a method called main. And that's it.

Now, inside this main method, we can do anything that we want to do, right? So if I want to print something right now, that's what we want to do. So I'm gonna use that statement. So system dot when I put dot, it's gonna kind of present me with the options not out dot print. ln. So print is also used to print and print ln means every time it's going to print on the new line.

So I'm going to use the print ln. And this is the syntax for printing anything in Java System dot out dot print, ln, you can use print also, but it will not go to the next line for the next print statement. So all the strings should go inside double quotes. This is very important. And inside it bacon print anything so hello world and Cantina Cantona's so this is our first print statement. There is a shortcut also, for most of you, it should work.

If it's not working, you'll have to check your Eclipse content settings, but it's c so if you type C so hit control and space. It will provide you this option. System dot out dot print ln it says at the bottom, hit enter Bow, it brings you the same thing, right. So just save some typing and this lot of shortcut shortcuts in Eclipse and we'll see them when we encounter them. So this is our first HelloWorld program. Now we can actually save the values in variables, and we can use them.

In our next lecture, we're going to cover variables. Also, variables are nothing but a way to create memory space to store our values. If I want to save this hello world, somewhere, I can create variables and save this value. So that's about it. We will talk about it. And one more thing I want to show you here is there are a couple of ways in Java to comment.

So I can comment like this. This is my first Java program. And I'm very happy right and other ways, slash and star Just hit enter, it's gonna put these things on its own. Let me just do it again. So that you can notice, slash and star and hit enter. It's gonna put one more Star.

And it's gonna reverse this order star and slash. This means a multi line comment, if you want to put like comment like this, this is my first and Java program. So which means we can actually put comments in multiple lines. So this is for a single line, this is for multiple lines. Comments in a programming language are something which will not be executed by the compiler. These are only for us to understand, and our colleague developers so that they can understand our code.

So it's very important to write good comments in any code. Now, let me just run this beautiful code. And let's see what happens right. So We will right click it, right click the file and run as Java application, this is the way to run. And there you go in the console. Here, this is the console, we will see our print statement hello world, right?

This is beautiful. And other ways we can play run from here from this green arrow, there is a small drop down, you can select this hello world. And this will run it. If you don't want to select this, if you click this, it will still run it what happens is, this remembers the last run program and whichever program was last run, it will run it right. So you can use this also, I usually prefer to right click and run as Java application because it is neat and clean way to make sure that I'm running the correct programs always try to do that. Another thing I wanted to cover in this lecture is that we may use a lot of concepts before We explained them, like, I just created a class, and I created a method.

But right now I'm just trying to show you how we can print something. And for explaining classes and methods there needs to, it needs to build a little bit more base so that you can understand those concepts. So that's why there's gonna be separate lectures in future. Future modules, right? separate explanations. So there's lots of things like if conditions for loops, and arrays and strings, there are a lot of things that we may use them before we explain them.

Sometimes because it's really important, it's not possible to demonstrate a concept without using another concept and that concept may not have been explained because it may not be possible to explain it without another concept. So in programming language, a lot of things are dependent on each other. So do not worry about any If you see it, and you think that I haven't explained about it, cause I will have a separate lecture on that particular concept. Like the same example here, I could not have explained how to print something without using classes and methods. But this is not the time to explain classes and methods. It's a much bigger concept.

So similarly, there's gonna be a lot of things. But I would just say keep calm, do not worry. I'm very reachable. Do let me know when you have any questions, any single thing you have, just post it, and I'll get back to you. So always, never hesitate, ask me questions, and you will have a great learning experience. All right, guys.

Thanks a lot for attending this one. I'm really excited and I'll see you in the next lectures. Thanks a lot.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.