We are going to do some coding with object references.
Let's create a new class for this.
Right.
Click on the my first Java app, new Java class, let's call it object references app.
Enter.
At some space here.
Now let's go back to my first Java app, double click on the file.
And copy this line, the main method.
Go back to object references app and paste it here.
Hit enter after the colobus and intelligibly will add the pair of it and some space here, too.
Let's create one of each built in object references, data type that has a primitive version.
So bored with uppercase number of seats equals five and a semicolon, short horsepower.
Equals free to integer instead of end.
Price equals forty nine point nine and a semicolon long registration number equals and a random number
and an L to the end of those numbers and they semicon.
All right.
So the next one is a float fuel.
Consumption urban equals fifteen point five and a half and a semicolon now created double double fuel
consumption, precise
average equals fifteen point random numbers and a semicolon.
Two more primitives left.
So Boolean is damaged equals true and correct instead of char.
Energy efficiency
category equals simple quotes G and a semicolon.
There we go.
We added the primitives, let's add a string here, so string car type or car model equals double quartz
dodge
challenger Esbati Free Nanita and a semicolon.
As I said, we can create an object with the new keyword.
Let's create another variable with the same value.
So string.
Car type model with new keywords equals new.
String double quotes Dodge.
Challenger, SRT three ninety two.
All right, and a semicolon to the end of the line, both give us the same result.
But the one about is simple here.
And as you can see, grade the new string version, hooved your mouse over the new string text to see
what's the problem.
The new string is redundant and intelligent, offers us a option.
So to replace the argument, let's click on it.
So it made the line the same as the one before this.
Actually, you don't have to use the second version in case of string, but later we will use the new
keyword a lot.
For now, reverse the change with controversy or command the.
And let's leave it as it is, so now let's print out some of the values so as O u t or system that our
DOT printed on its enter.
Double quotes.
Number of seats, column space.
Plus, number of seats double the line.
Horsepower.
And replace the number of seats, variable name, horsepower loss.
HP.
Double the line again, we bring the price here, it's a price and a euro mark here
price and remove the rest top of the line.
Registration number.
Top of the line again.
Fuel.
Sorry, urban fuel.
Consumption.
Plus double cotes
liter per 100 km.
Top of the line again.
So it's going to be the precise, precise, average fuel consumption replace the variable name.
And we have four left to go, so.
The Boolean.
The car is damaged, plus is damaged and removed the rest.
Top of the line energy efficiency category.
And the last to the strings, top of the line.
Bar model, plus car type and double the line and card type.
With the new key word.
Well, if you keep your word, so that's it, let's run the code.
So as you can see, everything worked fine, there is no difference between the primitive version and
the object references version.
So the question is why we have the objects here.
For example, we can have cases when we need the float value of the price, which is a whole number
to show that there is no decimal part of that value.
And on the other hand, we don't want to store a flawed version and an integer version of the price
to show that we have to go to the price variable name.
Here, type in a dot at the end of the price variable name like this, and you can see the available
functions here, the function names are on the left and the return data types are on the right.
So we are going to need a function that returns a floating point number so we can go with the float
value or the double value.
Actually, both of them can do the job.
I'm going to go with the float value.
So hit enter.
Let's run the code again.
And as you can see, the price appears as a float number.
Now let's reverse it.
We want to print out the integer version of the precise fuel consumption.
So go to the end of the fuel consumption variable name.
I dot and choose one of the functions that returns a whole number, so bye to value short value, integer
value, even long value, you can do it.
I will go with the value.
Run the code again.
As you can see, Java chopped off the decimal part and didn't use any rounding, and we got the whole
number before we finish it.
I would like to show you some string functions.
Double the Kameda line and let's use.
Talked to uppercase here and changed the text as well with Case.
Top of the line again.
Now use.
To not work case.
With the lower case, and we can also check whether the two streams are equal or not, so double the
last line.
And at the end of the car type with new key words, place a dot.
And equals.
And variable name card type.
And changed the tax to car type variable.
Equals two car type with new key words.
And that's it, run the code again.
And as you can see, the string appears with an uppercase done with a lower case, and the last line
is Khatar Frebel equals toccata with new keywords is true.
So that's all I wanted to say about object references.
For now, I hope it was clear and useful saying the next lecture.