Professional Documents
Culture Documents
Course Java Syntax - Lecture - Different Ways To Create Variables
Course Java Syntax - Lecture - Different Ways To Create Variables
AVAILABLE
"Hi, buddy. I made a copy of your contract for you, just in case. Rishi, that cheapskate, is blissfully ignorant. You should see the figures in
my contract. Ha!"
"Sure thing, Amigo. There are too many stupid people in the world who want to get rich without actually doing something. But there are
even more idiots who are ready to work for free."
"OK, let's get back to our lesson. Now I'm going to teach you several ways to create variables:"
1 int a = 5, b = 6; Create an , variable named and set its value equal to Create an ,
variable named and set its value equal to
1 int a = 5, b = a + 1; Create an variable named and set its value equal to Create an
variable named and set its value equal to
1 Date date = new Date(); Create a Date object. It is initialized to the current date and time.
1 boolean isLess = (5 > 6); Assign to the variable. variables only accept the values true
and false.
"By the way, I have a couple more exercises for you. How are they going so far?"
×3
CLOSED
Imagine that for some reason you need a specific number, and until you get it, nothing good will happen (or something bad will happen). Have you got a
picture of that in your mind? Do you have a feel for your role? Good, now let's complete an interesting task. We have some code. You need to comment
out as many lines as possible to make the program display the number 19.
Open
×1
CLOSED
Crazy eights
The fact that cats were able to take over the Internet with ease shows that we are far from knowing everything about these cute balls of furs. The only
obvious thing is that people without them are worse off than people with them. Let's make the world a better place: create 10 Cat variables and 8 more
Cat objects. By the way, does anyone need a kitten?
Open
×3
CLOSED
"You become responsible forever for what you've tamed," said Antoine de Saint-Exupery through the mouth of the Little Prince's fox friend. Let's clean up
our program and not leave any animal without a caregiver. We'll create a cat, a dog, and a fish. And a woman. And then we'll assign her as the owner of
the fish, dog, and cat. We think she'll like this!
Open
Previous Next
+131
Daniel Himmelberg
Mariam
HINT:
You can call it "object" AND you can call it "variable" as well.
Reply +3
Gigi Suchan
precedence:
1. * and /
2. + and -
Reply
Matt
It's a good thing I use JDK and Eclipse. I knew I was typing the right code in, but after 8 attempts I was getting
confused. Then I used Eclipse's built in suggestions and it hit me like a ton of bricks! Duh! I made the changes
and it worked! I just completed a course in Java through an online accredited university. It was 300 hours of hell
in 7 weeks. No guidance from an instructor. I passed, but OOP was still a mystery. Codegym jumped right into
OOP before loops etc. And, I am still cloudy on visibility. Eclipse helps with suggestions, but instruction is what
is needed. I am so glad Codegym is tackling this first!
Reply +1
Ibrahim
Reply
Matt
I copy and paste the task code straight into an Eclipse that is already open. Every task has the same class
name: Solution. This allows me to keep the file name the same: Solution. Eclipse has built-in help in the
form of suggestions. Some have to be done manually while others can be selected and the IDE will do the
rest. Be sure to use [ctrl] [x] to undo changes if they don't work out. I also save all my work in notepad as a
record of my work and for reference. Eclipse saved my GPA, but in the end, the university I was attending
failed to help me understand OOP in any measurable way. Understanding is more important than guessing.
That is why I sought out Codegym.
Reply
AMOON
Reply +4
Kọ́láwọlé Fasasi
Variable is a named storage of some data type(like int, float etc). And Objects are variables of data types
that are user defined. So we say that an object is an instance of a class. And class is nothing but a user
defined data type. (Quora)
Variables are pre-defined by Java but when you create and initialize an object e.g.
you therefore define a new data type named 'Cat' and given it a variable name 'pussBoot'. Since variable
pussBoot's data type was defined by you (the user) and not by Java (such as int, double etc.), it is called an
object.
Reply +4
AMOON
Reply
Tyler Evans
Reply
Maryem Vickers
*reads Diego saying, "By the way, does anyone need a kitten?"* I certainly do! XD
Reply +4
Maryem Vickers
Reply +1
hidden #10602322
cat.owner = woman; is we adding reference to an object am I correct please tell me. If I am wrong then correct
me then tell me what is actually is (︺︹︺)
Reply
Seb
You're correct.
Reply +2
Dinesh
In the main method, how to set the Woman object as the owner of each animal.
Is this right?
woman.owner=cat;
woman.owner=dog;
woman.owner=fish;
Reply
Drazen Jankovic
I would disagree...
cat.owner = woman;
dog.owner = woman;
fish.owner = woman;
In your example, it would be concluded that woman is owned by a pets, not the other way around.
Reply
Jack
just to be clear...
what do i put in the parentheses in the
IDK idk = new IDK ()
Reply +1
Brad Hawk
For now, nothing. In future tasks, I'm sure we'll be passing data to the methods within the parentheses.
For example if the Woman method had an Age variable within it, we could assign the Woman an age while
creating the Woman objec...
Woman barb = new Woman(25);
This would create the Woman object and assign the Age variable the value of 25
Reply +3
Gallad
If the constructor was defined to take in age variable! The constructor would take exact same number of the
variables and in the order it was assigned to it!
Reply
Michael Brimage
can someone explain why it's this way? i understand that this was touched on briefly but it's not sticking. for me.
Reply +2
Julia Drugova
I love to think about that as of English grammar: the pet's owner IS= [who]
I think it's because we assign the new pet owner, so what we assign it to on the left eg pet and than we
specify the value (who) we assigned on the right.
I hope it helps and not more confusing, that's my second day in CodeGym myself :)
Reply +4
MLA
They named the method and variable the same in a lot of their examples, which is why you might be getting
confused.
Reply +1
Gellert Varga
" Date date = new Date(); // Explanation: Create a Date object. It is initialized to the current date and time."
Reply
Seb
You can try it out in your IDE or in the integrated Web-IDE of one of the tasks.
Simply type in the following code in the main method - and run it:
Date date = new Date();
System.out.println(date);
You'll then see that date has been initialized to the current date and time. :-)
Reply +1
Seb
Yes, you're right in both cases. Date is built-in - and in your example a kitty object is created, which does
not have its own name and age yet.
You'll learn a lot more about the initialization and construction of objects in level 5.
All the best and keep it up. ;-) :-)
Reply +1
Daniel Malloy
to be honest this lesson was actually pretty fun, I don't know if you agree .
Reply +2
LEARN COMMUNITY
Subscriptions Forum
Success Stories
Activity
ABOUT VIDEO
FAQ
Support
FOLLOW US
INTERFACE LANGUAGE
English