• Home
  • Oracle
  • Oracle Java (Oracle Java Certification) Dumps

Pass Your Oracle Java Certification Easy!

100% Real Oracle Java Certification Exams Questions & Answers, Accurate & Verified By IT Experts

Instant Download, Free Fast Updates, 99.6% Pass Rate.

Oracle Java Bundle

$99.99

Oracle Java Certification Bundle

Java SE 8 Programmer

Includes 234 Questions & Answers

Java SE 8 Programmer II

Includes 207 Questions & Answers

Java EE 7 Application Developer

Includes 142 Questions & Answers

Oracle Java Certification Bundle gives you unlimited access to "Oracle Java" certification premium .vce files. However, this does not replace the need for a .vce reader. To download your .vce reader click here
Oracle Java Bundle
Oracle Java Bundle

Java SE 8 Programmer

Includes 234 Questions & Answers

Java SE 8 Programmer II

Includes 207 Questions & Answers

Java EE 7 Application Developer

Includes 142 Questions & Answers

$99.99

Oracle Java Certification Bundle gives you unlimited access to "Oracle Java" certification premium .vce files. However, this does not replace the need for a .vce reader. To download your .vce reader click here

Or Purchase Oracle Java Exams Individually

1z0-808 Java SE 8 Programmer $69.99
Add to cart
1z0-809 Java SE 8 Programmer II $69.99
Add to cart
1z0-816 Java SE 11 Programmer II $69.99
Add to cart
1z0-900 Java EE 7 Application Developer $69.99
Add to cart
Exam
1z0-808
Title
Java SE 8 Programmer
Price
$69.99
Exam
1z0-809
Title
Java SE 8 Programmer II
Price
$69.99
Exam
1z0-816
Title
Java SE 11 Programmer II
Price
$69.99
Exam
1z0-900
Title
Java EE 7 Application Developer
Price
$69.99

Oracle Java Certification Exams Screenshots

Oracle Java Product Reviews

Download Free Oracle Java Practice Test Questions VCE Files

Exam Title Files
Exam
1z0-808
Title
Java SE 8 Programmer
Files
14
Exam
1z0-809
Title
Java SE 8 Programmer II
Files
9
Exam
1z0-816
Title
Java SE 11 Programmer II
Files
2
Exam
1z0-900
Title
Java EE 7 Application Developer
Files
5

Oracle Java Certification Exam Dumps & Practice Test Questions

Prepare with top-notch Oracle Java certification practice test questions and answers, vce exam dumps, study guide, video training course from ExamCollection. All Oracle Java certification exam dumps & practice test questions and answers are uploaded by users who have passed the exam themselves and formatted them into vce file format.

Introduction to Objects

6. Initializing Data

So we've seen how to create objects, and we've seen how we can send it messages by accessing and setting fields, accessing methods, and so on. The next thing that we're going to do is just dive a little deeper into how objects are created, and that process is called instantiation. So we've seen that in order to instantiate an object, we use the new keyword. And we've also seen that some objects will allow us to pass in additional information arguments when we are trying to instantiate the object. If you think about a previous lecture, we saw an example of a string, and we saw an example of a customer. And in both cases, we were able to pass in some text known as a parameter, which we were using to pass in the argument. So we can do that when we create certain objects. And the reason for this is that it allows the object to be initialised with the required data. So think about if we were designing some sort of object; let's say we were designing a bank account. Maybe we would force the user to give an account number when it's created because it doesn't really make sense for us to have an account with no account number. So a lot of times, business rules and real-world processes determine what it is. We are going to insist that someone is present when they instantiate the object. The other option, of course, is that we don't accept anything. We just say "new customer" and just have the parentheses. We don't pass in any arguments. And then what would happen is that the user of that object would modify the data after the object was created. We saw an example of this in the previous lecture, where we saw the point object. And so we set MyPoint X and MyPoint Y. We did that after the point object was created so we could change what we had done with points and pass in some data. So now the people that created the point object for us to use, or rather created the point class, remember that a class is a blueprint, and we instantiate objects from that blueprint. So someone created the blueprint for that new point, and they've said, well, you can pass in two integers to us when you create the object. And then we'll make sure that that point is created with those two integers. The first one will be an x value, and the second one will be a y value. So that's what we're doing here. We're making a new point. Remember that the new keyword is necessary to create an object. We specify the type of object that we're creating, and we're passing in two arguments, two and five. And that's going to create a point object, which is being returned to us. And so then what we're going to do is assign that point object to a brand new variable. And that is the point variable that we've created here. So whenever we create an object with that new keyword, what we're really calling is a method, but it is a special method. It's called a constructor. And so here's an example of what a function Object() { [native code] } might look like. So this would be in the class. This would be in the blueprint. So we would make a method that looks like this. and so we'll talk more about the syntax a little later. But notice that it has the name "point." That's the type that we're trying to create. Notice that it doesn't have a return value. So that's something that's very special about constructors. Not only does it have to have the exact same name as the type, which is synonymous with class, so it has to have the exact same name, but it can't return any value. You don't even put "void." So a constructor's purpose is just to initialise a brand new object. So, to get to the point, they've said we'll take two parameters. We've got our param number one, which is an int, and we've got our param number two, which is an int. And so those are the parameters that this method accepts. We are passing in two and five. So two get assigned to param one, and five get assigned to param two. So now that the function Object() { [native code] } has these parameters, what they're going to do is assign them to the instance variables of the class. Now we're not looking; we don't see the whole class here, but you can imagine that this class has an int x and an int why? And so what they're doing now is taking paramone, whose value is two, and assigning that to X, and then taking the value of paramtwo, which is five, and assigning that to Y. So the constructor's whole purpose is that it must initialise the object when it's instantiated with the new keyword. And by the way, function Object() { [native code] } methods can only be called during instantiation. I can't just use the point operator that we've been talking about, so I can't use that point and say, Hey, let's call the function Object() { [native code] } again. You can't do that. The only time that the function Object() { [native code] } is going to be called is when you use the keyword new. And because of that, it's going to create a brand new object. You can never call a function Object() { [native code] } on an existing object. You can only call the function Object() { [native code] } for brand new objects. All objects have to have at least one constructor, but they can have many more if we need them. and the reasons for flexibility. So let's look at a couple of examples of how we would have some flexibility with multiple constructors. So imagine we've got a type of customer, and we want to give people that use this customer type—those that are going to instantiate objects from our customer type—different ways to create them to initialise them. So here's an example where we're passing in four different strings. They're going to give us the first name, the city they live in, the phone number, and an email address. We might have another function Object() { [native code] } that we provide that says, you know, if you only pass in one string, then it will be the email address. Or we might have another one that has two different parameters. In this case, we're passing in two strings. The first string is the first name, and then the second string is the city. So as you can see, now we've got three different customer constructors, which gives us flexibility in how we want to build our object.

7. Creating Object Types - Part 1

The Java API includes a tonne of objects that we're able to use in our own programs. We've seen objects already in this class like String and Point; they're already built. All we have to do is instantiate them and then send them messages. Fantastic. But that's not enough. We're going to have to create our own object types at some point to suit the needs of our application. And at this point, you've already created an object type. Can you think of what that was? Well, of course it was. Hello, world. When we create a class called Hello, World, what we are doing is creating an object type. So specifically, class is really going to be the blueprint. And when we instantiate an object of a specific type, this is the blueprint that we are going to instantiate it from. So Hello World was the very first object type that we created. And an object type is called a class. So inside the class, that's where we're going to specify all the things that this object of this type can do. So we're going to specify the state that will be available and the behaviour that will be available as well. So you can think of the class as a template for object creation. I like to think of it as a blueprint for object creation, and then an object. When we say "new customer," new point," new string," what we're doing is making an instance of that class, an instance from that blueprint, and we can generate any number of objects from a single class unless the class has been written in a way to prevent that from happening. There is a design pattern called a singleton, which ensures that only one object is made. But generally speaking, when you make a blueprint or when you make a class, many objects can be generated from that single class. One note about classes is that you can only have one public top-level class. You may recall that when we were developing Hello, Worldclass, we had to say public class, Hello World. And there were no curly braces outside of that class. So it was at the very top level. If you think of your file as sort of a hierarchy, a tree, in this example I've got right below us a public class, Hello World, and then a helper class. These are two top-level classes; neither encloses the other with their curly braces. And there are no outside curly braces enclosing either of them. So they're both at the top. And when that happens in the same file, only one of those classes can be public, and the one that is called public is going to be the name of the file. So this particular file would be called Hello World Java. Now, when you first start learning Java, you're only going to have one class per file. In fact, that's going to be the majority of the time until you start getting into more advanced programming. But just keep that rule in mind. That's one of those things that they expect you to know for the exam. So let's take a quick look at an example of a car class. Alright? So what we're going to do is slowly create a class called Acar, and we're going to talk about it. And what I'm going to do now is just sort of build the shell of the class. I'm going to say public-class car. And remember, all of the code that's going to belong to this car will go inside the curly braces. So we're going to create this blueprint of a car type. So what I want you to do is just take a quick look at this, and then what I'm going to do is have you take a small quiz just to answer some syntax about the class that I've created right here. And after that, we'll come back, and we'll start adding more code to it.

8. Creating Object Types - Part 2

Alright, let's start by adding some state and behaviour to this class. Let's start with the state. What kind of things do we want to have in our car? We'll make it simple. We just want to have a colour and a type. Now Java gives us an object that we can use to store this kind of information, and that would be a string. So remember, the string is just text. So we'll make a string colour (we can't type color) and put a semicolon at the end. Remember, all of our statements end with a semicolon, and we'll have a string type. So now we've created two instance variables, and we call them instance variables because every time we create an object from this class, when we create an object from this blueprint, that object will get its own colour and its own type. And it will be distinct from any other car object that has been created because it will have a colour as well as a type. So that's the simplest way that we can create a type. We basically say whatever the type is, and then we also include some sort of name, some sort of identifier. But there are other things that we can do with our instance variables. We could add some modifiers to the left. We haven't really talked about modifiers yet, except for our example of main, but they modify either methods or fields. And so, for example, I could put the word public in front of this, and we'll talk about access modifiers later. But this simply means colour is available to all code in this program. We can also give it a default value. I can say that equals blue, so that's optional as well. But we're going to keep it simple. We're just going to have our string colour and our string type, and we'll deal with populating the values in a little bit. Now let's add some behavior, which means we're going to add some methods. So I'll use the simplest methods I can. We'll have one called Start, which will just print out a string that says "Get started." And then we'll have one that will print a description, which will actually print out the colour and type. So let's do the first one. Remember that a method has to have a return type in both cases. Here, I'm going to say void. I'm not returning anything after the statements inside of this method have been executed. So I'll just say void and we'll have our method called start, and all methods have to have parentheses even if you're not accepting any arguments. So I'm going to say "void start" and all methods must have curly braces as well. So, to get started, I'll just type out the system in print line. All right, if I had more statements then I could add them in between these two curly braces, but I don't. We'll leave it like that. And that's sort of the minimal method that you would use in terms of syntax; you would need the return type, which in this case is void, the parentheses, and then a set of curly braces. I mentioned another method that we're going to use, which is going to be print descriptions. So the print description is void. and in this one we're going to do the same thing that we did before. We're going to print this out, and we want the colour and type. I don't want it to print out that string literally; this is a colour and type. In fact, I just want to be this colour type. Let's get rid of that word. And so what I want to do is replace it so that this word colour actually takes the value from the instance variable and replaces it right here. And I want to do the same thing with type. I want to take whatever the type is; it's going to retrieve it from the instance variable up here and replace that down here. So, for example, if we've got a blue sedan that I wanted to say is a blue sedan, how would I do that? So this is what we do. First of all, let's fix up that sentence. This is a colour type. Eventually I will be able to complete a full sentence here in this lecture. So this is a colour type. How do I change that? So what I'm going to do is close off the string. So don't worry about the red underline. It's an illegal statement at the moment, but we're going to fix it. So it says this is A, and it's going to print out exactly what it says in the quotes. And now I'm going to use the plus sign. And when we're working with strings, the plus sign is a concatenation operator, meaning it's going to take the string and then concatenate it, or put it together with something else, some other value. So then I've got color. Now notice that I didn't put colour in quotes. So what will happen is that colors, the JVM, will try to resolve what is color, and it will look in this method and say, "Hey, do you have a variable called color?" and the answer will be no. And so then it'll ask the class: Do you have a color? And really, it'll ask the object: Do you have a color? And the answer will be, yeah, I do. And so it will replace the word "color" with that actual value. So I'm going to do the same thing with type. I'm going to just put another plus sign, and we can get rid of that last quote here. So now it's going to print this out in A, it's going to look up color, and it's going to look up type. Now unfortunately, that would put the two colours and types right up against each other. So I want to put a space in between colour and type, and I'll do that with another string. I'll put a quote space; after the quote there's a space, and then I need to concatenate that space with the type. So we add another plus sign. So there we go. Now we've got a class with state and behavior, and before we end this lecture, I want to show you what else you could do with a method. So this is the method's basic syntax: thereturn type, name, parentheses, and curly braces. We could also put modifiers in front of a method. We've seen public; we've seen static, so we'll talk more about modifiers through the remainder of this course. We could add those to the left side. We could add parameters, and we can add as many parameters as we want. We could say we are taking three INTs. The only thing we have to do is specify the type and name, and we comma separate them all. And now we're saying whoever calls start is going to have to pass us three integers, but we're not going to take anything right now, so I'll get rid of that. And there's another thing that we can do with methods, but it's called throwing and it deals with exceptions. That is the very last lecture of this course. So we'll hold off on that syntax, but there we created an actual class that we can instantiate and use.

9. Creating Object Types - Part 3

So we've done it. We've created our own class and created our own object type. And when we did that, you might have noticed that the instance variables were at the top and the methods were below. And strictly speaking, the order of the variables and the methods is not important to Java. I could have mixed them all up. I could have had a variable colour and then a method start and then another variable if I wanted to, and it would compile and it would run just fine. However, very conventionally, we typically put the variables near the top of the class and then have the methods follow below. That also occurs conventionally. All of our instance variables, our constructors, our methods, and all of our different types are grouped together, which just makes for easier organisation and readability. With that said, how do we work with the car class? And what we're going to do is create it just like we would any other object. So we create a reference variable here: car, my car. We're going to assign that a new car. It's going to instantiate an object from the Car type that we just created, and we could call that over and over again. We could make as many cars as we need from that single class and that single blueprint. And every single instance, every single object—remember, an instance is an object. Every single instance would have its own colour and its own type. So, to change the colour of our newly created car, we'd say My color, MyCar colour equals white. And so we are going to create the colour white, and we're going to assign it to the MyCar color. We can do the same thing with the type MyCartype equals sedan, and then we can call the methods; we can execute the behaviour My Car, dot Print Description, and that will tell us that this is a white sedan; we can also call MyCar start, and that will tell us that we have begun. And we notice that we're using the dot operator to access the state and the behavior, and you can tell the difference between the two because if there's no parentheses, that means it's a field. If there are parentheses, that means it's a method. "Start" has a parenthesis. So we're calling a methodcolor that doesn't have parentheses. So we're referring to some sort of variable. Both of our class methods returned a void type, which do your work, execute all the statements that are in your code block, and then you're done." You're not going to return anything to the caller. So we could add a new method or change the one that we have here and change it to PrintDescription and change it so that we're actually returning something. So the method would look like this Instead of saying public void, we'd say public string. So the return type is a string. We are saying that after we execute these statements, we will return a string back to the caller. So what we're doing here is creating a string called desk. And its worth; in this case, a white sedan. And then we're returning that string. And so whoever calls it can get a hold of that string and store it in a new variable. Now without that return statement at the very bottom of the return desk, the code would not compile. So when you put in your signature, I'm going to return a string. The compiler is going to hold you to it. You must return something; preferably a string. Now there are a couple of ways we could get around that, but we'll see those exceptional situations a little bit later. So the return statement here terminates the method. Any code that is lower than the return desk will be ignored. In fact, it wouldn't even let you compile because it would say there's code after you return. It's not going to work. Now again, there are always exceptions to these rules that I'm mentioning. We'll talk about conditional statements a little bit later. As a result, it is possible to have the return inside of a conditional statement. A conditional statement means if something's true, run this code. If it's not true, don't run this code. That kind of thing is a conditional statement. So there is a way for us to have code below the return. But in general, just know that any code that's below the return, unless we have these exceptional situations, will never be executed, and therefore it won't even compile it'll.Tell me why you're wasting your time. You're writing code that won't run. So now, using that return type, we can substitute this method anywhere that we'd use a normal string. So we can do things like this. We can say "car." My car equals a new car. Now we've got a car, and we can set the colour to be silver. We can set the type to be a DeLorean DMC twelve.And now when I call get description, that's going to return that new string, and I can take that return value and assign it to a variable. So now this is a silver DeLorean DMC 12. That's the string that will be returned from Git's description. And I can store that in a variable, as I'm doing here with the string desk. And then I can do whatever I want with my desk. I can pass it into the system out print line, which will then print out that this is a silver DeLorean DMC Twelve. If I'm not going to use the variable desk for anything other than printing it out as I am now, I can even inline this entire thing. I could say system out print line, followed by MyCar get description in parentheses. And what's going to happen is the MyCar dot get description will run first, and then the return value, which is that string, will then be passed in to the system. Out. Print this line message.

10. Building Constructors

One thing we didn't do with our cars was take advantage of the fact that we could create unique constructors for initialising the object. And just as a reminder, instead of just calling a new point, we were able to pass in an X and a Y value to the constructor. So we have a point here. My point is that my reference variable equals newpoint, passing in two and five. And that's great because then I don't have to wait until after the point has been created to set the X and Y values. And in fact, that can help prevent a lot of errors. You can imagine that it doesn't make much sense to have a point object without an X or Y. Or you could argue, "Sure, it does; just let's make it a default of zero zero." But those are the kinds of things that you have to debate with your fellow developers when you're writing a program. The important thing to know is that we can specify those rules. We can specify what constructors are available to those that are creating a type or an object from our type. So how do we do that? First of all, remember that constructors are really just methods, but they're special methods. Constructor methods have the exact same name, spelling, and capitalization of the class itself. And they look like methods except that they have no return type, not even void. And there's an exam gotcha: just make sure that the return type for what looks like a function Object() { [native code] } doesn't exist. If you're looking at something and you think it's a function Object() { [native code] } because it has the same name as the class, but it has the type void, Well, now you know it's not a function Object() { [native code] }, it's just a regular method. And the only way that we can call constructors is by using the new keyword. We can't use that dot notation that we use for fields and methods. So here is our public class car, we've got our colour and type, and here is a constructor, so no return value. We have the name of the class car. And now we're specifying that we will accept two strings. And what we're doing is, when we specify the parameters, we say, What is the type of the parameter? And we give it a name so that we can refer to the parameter inside the method. So here we have string C and string T. And what we'll do is whatever the first parameter is that's passed in, we'll assign that to our colour instance variable, and whatever the second one is, we'll assign that to our type. We use these constructors simply to initialise data, and in this case we're taking two strings. We are initialising the variables colour and type using whatever the person passed to us. So how would that work in code? Well now, this is what it looks like to create a car. So the left side is still the same car, my car; that's our reference variable. And on the right side we say "new car." But this time we're passing in the two strings. So we've got silver as our first string and a DeLorean DMC-12 as our second. As a result, silver will be assigned to colour and the DeLorean DMC-12 will be assigned to type. So the function Object() { [native code] } is useful because it saves us from having to take the car and specify what data should exist for that car one by one. And if you think about it, we could make a mistake. We may forget to include the colour or type. When you have a constructor, you don't get that luxury. You can't forget that if I only pass in one string to the car constructor, the compiler is going to complain. It's going to say, Hey, I look in this class, and there's no function Object() { [native code] } that only takes one string. So what's going to happen underneath the covers here? So what happens is when we create the car, or, as we say in this case, the car's wife's car, car equals new car. And when we call that, the stack is going to have the variable, and the heap will have some space allocated for the car object. Now the next thing that's going to happen is that it's going to go through and deal with all of the instance variables. Now instance variables have default values. Talk about that in just a second. But if it's an object a string is an object), then that means the default value for that instance variable will be null. Now we've got two strings, we've got color, and we have type. So both of those will be set to null. When it's first created, I mentioned that we could specify a default initialization value for an instance variable. Remember, when we looked at our card, I said string colour equals blue. Well, here's an example saying that string colour equals black. If we had done that, then the null for the colour would have been replaced with the string black. And then the final step is to call the constructor, and then the function Object() { [native code] } would run, in this case, red. BMW was also turned in. So our car would then be a red BMW. So I mentioned that there are some default values. What are those default values? And it really depends on what the type of the instance variable is. And by the way, it's not just instance variables—it's static variables as well that have default values. We'll talk about static variables in the next section. Any variables declared in a method or in a function Object() { [native code] } must be explicitly initialised before they are used. Here's what I mean. I've got my car; I can say "string color" without saying colour equals blue or colour equals black. That's okay, it's legal. There is a default value, and it's null. Now here's a method called printing. Then this is a simple method, and I'm declaring a variable called int. Okay? Now, if I try to use that variable before I've initialised it, INTVEN equals 32. If I don't actually give it a value, I will get a compile error. I'm trying to use a variable inside of a method before it has been initialized. There are no default values. Here's another example. Here I'm saying that string plate is inside of a method, and I didn't give it a value right away. It's legal because on the very next line I'm initialising it, and we're initialising it with a value before we use it. So it's being initialised with ABC DEF, and then that plate is going to be used. And so we didn't use the stringplate until it had a value. So that is legal. So here are the default values. Any Java object will be null. Any Boolean value will be false. Any of our whole number types will be zero. Our real numbers will be 0.0 and HR will be a null character. The backslash "you" is an escape code to specify that this is a Unicode character. And so it uses the null Blake character.

ExamCollection provides the complete prep materials in vce files format which include Oracle Java certification exam dumps, practice test questions and answers, video training course and study guide which help the exam candidates to pass the exams quickly. Fast updates to Oracle Java certification exam dumps, practice test questions and accurate answers vce verified by industry experts are taken from the latest pool of questions.

Read More


Comments
* The most recent comment are at the top
  • Examcollection
  • Belarus
  • Dec 26, 2018

@Said,
Please, use the button "REQUEST EXAM" at the top of the page to find out how to get the required exam.

  • Dec 26, 2018
  • Said
  • Morocco
  • Dec 24, 2018

Bonsoir, je suis intéressée par la certification JAVA developper

  • Dec 24, 2018

Add Comment

Feel Free to Post Your Comments About EamCollection VCE Files which Include Oracle Java Certification Exam Dumps, Practice Test Questions & Answers.

SPECIAL OFFER: GET 10% OFF

ExamCollection Premium

ExamCollection Premium Files

Pass your Exam with ExamCollection's PREMIUM files!

  • ExamCollection Certified Safe Files
  • Guaranteed to have ACTUAL Exam Questions
  • Up-to-Date Exam Study Material - Verified by Experts
  • Instant Downloads
Enter Your Email Address to Receive Your 10% Off Discount Code
A Confirmation Link will be sent to this email address to verify your login
We value your privacy. We will not rent or sell your email address

SPECIAL OFFER: GET 10% OFF

Use Discount Code:

MIN10OFF

A confirmation link was sent to your e-mail.
Please check your mailbox for a message from support@examcollection.com and follow the directions.

Next

Download Free Demo of VCE Exam Simulator

Experience Avanset VCE Exam Simulator for yourself.

Simply submit your e-mail address below to get started with our interactive software demo of your free trial.

Free Demo Limits: In the demo version you will be able to access only first 5 questions from exam.