Soumettre la recherche
Mettre en ligne
04 variables
•
Télécharger en tant que PPTX, PDF
•
0 j'aime
•
270 vues
P
Program in Interdisciplinary Computing
Suivre
Signaler
Partager
Signaler
Partager
1 sur 30
Télécharger maintenant
Recommandé
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2
Umar Ali
Wrapper class
Wrapper class
kamal kotecha
Vectors in Java
Vectors in Java
Abhilash Nair
Autoboxing And Unboxing In Java
Autoboxing And Unboxing In Java
chathuranga kasun bamunusingha
Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
Subhadra Sundar Chakraborty
Wrapper classes
Wrapper classes
simarsimmygrewal
Lecture20 vector
Lecture20 vector
nurkhaledah
Recommandé
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2
Umar Ali
Wrapper class
Wrapper class
kamal kotecha
Vectors in Java
Vectors in Java
Abhilash Nair
Autoboxing And Unboxing In Java
Autoboxing And Unboxing In Java
chathuranga kasun bamunusingha
Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
Java Wrapper Classes and I/O Mechanisms
Java Wrapper Classes and I/O Mechanisms
Subhadra Sundar Chakraborty
Wrapper classes
Wrapper classes
simarsimmygrewal
Lecture20 vector
Lecture20 vector
nurkhaledah
Introduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
Autoboxing and unboxing
Autoboxing and unboxing
Geetha Manohar
String handling session 5
String handling session 5
Raja Sekhar
M C6java7
M C6java7
mbruggen
Function Java Vector class
Function Java Vector class
Nontawat Wongnuk
05 object behavior
05 object behavior
Program in Interdisciplinary Computing
Java strings
Java strings
Mohammed Sikander
Python Fundamentals Class 11
Python Fundamentals Class 11
chinthala Vijaya Kumar
Writer Monad for logging execution of functions
Writer Monad for logging execution of functions
Philip Schwarz
String, string builder, string buffer
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
L13 string handling(string class)
L13 string handling(string class)
teach4uin
Chapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
Solid Deconstruction
Solid Deconstruction
Kevlin Henney
Python interview questions and answers
Python interview questions and answers
RojaPriya
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
Peter Antman
Strings
Strings
naslin prestilda
Introduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
Definitions of Functional Programming
Definitions of Functional Programming
Philip Schwarz
Python Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
Chapter 7 String
Chapter 7 String
OUM SAOKOSAL
15a gui
15a gui
Program in Interdisciplinary Computing
Sdlc
Sdlc
Program in Interdisciplinary Computing
Contenu connexe
Tendances
Introduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian
Autoboxing and unboxing
Autoboxing and unboxing
Geetha Manohar
String handling session 5
String handling session 5
Raja Sekhar
M C6java7
M C6java7
mbruggen
Function Java Vector class
Function Java Vector class
Nontawat Wongnuk
05 object behavior
05 object behavior
Program in Interdisciplinary Computing
Java strings
Java strings
Mohammed Sikander
Python Fundamentals Class 11
Python Fundamentals Class 11
chinthala Vijaya Kumar
Writer Monad for logging execution of functions
Writer Monad for logging execution of functions
Philip Schwarz
String, string builder, string buffer
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
L13 string handling(string class)
L13 string handling(string class)
teach4uin
Chapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
Solid Deconstruction
Solid Deconstruction
Kevlin Henney
Python interview questions and answers
Python interview questions and answers
RojaPriya
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
Peter Antman
Strings
Strings
naslin prestilda
Introduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
Definitions of Functional Programming
Definitions of Functional Programming
Philip Schwarz
Python Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
Chapter 7 String
Chapter 7 String
OUM SAOKOSAL
Tendances
(20)
Introduction to Python - Part Three
Introduction to Python - Part Three
Autoboxing and unboxing
Autoboxing and unboxing
String handling session 5
String handling session 5
M C6java7
M C6java7
Function Java Vector class
Function Java Vector class
05 object behavior
05 object behavior
Java strings
Java strings
Python Fundamentals Class 11
Python Fundamentals Class 11
Writer Monad for logging execution of functions
Writer Monad for logging execution of functions
String, string builder, string buffer
String, string builder, string buffer
L13 string handling(string class)
L13 string handling(string class)
Chapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Solid Deconstruction
Solid Deconstruction
Python interview questions and answers
Python interview questions and answers
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
Strings
Strings
Introduction To Programming with Python
Introduction To Programming with Python
Definitions of Functional Programming
Definitions of Functional Programming
Python Interview Questions And Answers
Python Interview Questions And Answers
Chapter 7 String
Chapter 7 String
En vedette
15a gui
15a gui
Program in Interdisciplinary Computing
Sdlc
Sdlc
Program in Interdisciplinary Computing
12 abstract classes
12 abstract classes
Program in Interdisciplinary Computing
07 java api and inheritance
07 java api and inheritance
Program in Interdisciplinary Computing
Mysocial
Mysocial
Program in Interdisciplinary Computing
03 objects
03 objects
Program in Interdisciplinary Computing
14a exceptions
14a exceptions
Program in Interdisciplinary Computing
06a methods original
06a methods original
Program in Interdisciplinary Computing
Web architecture v3
Web architecture v3
Program in Interdisciplinary Computing
En vedette
(9)
15a gui
15a gui
Sdlc
Sdlc
12 abstract classes
12 abstract classes
07 java api and inheritance
07 java api and inheritance
Mysocial
Mysocial
03 objects
03 objects
14a exceptions
14a exceptions
06a methods original
06a methods original
Web architecture v3
Web architecture v3
Similaire à 04 variables
04 Variables
04 Variables
thewhiteafrican
12 constructors
12 constructors
Program in Interdisciplinary Computing
11 polymorphism
11 polymorphism
Program in Interdisciplinary Computing
09 polymorphism
09 polymorphism
Program in Interdisciplinary Computing
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Chapter - 3.pptx
Chapter - 3.pptx
MikialeTesfamariam
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Mohd Sajjad
Python basics
Python basics
Manisha Gholve
Primitive Wrappers
Primitive Wrappers
Bharat17485
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov
P1
P1
Actuaria, Facultad de Ciencias, UNAM
10 abstract
10 abstract
Program in Interdisciplinary Computing
03 Variables - Chang.pptx
03 Variables - Chang.pptx
Dileep804402
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
Felipe Prado
13 interfaces
13 interfaces
Program in Interdisciplinary Computing
11 interfaces
11 interfaces
Program in Interdisciplinary Computing
Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11
chinthala Vijaya Kumar
Similaire à 04 variables
(20)
04 Variables
04 Variables
12 constructors
12 constructors
11 polymorphism
11 polymorphism
09 polymorphism
09 polymorphism
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Chapter - 3.pptx
Chapter - 3.pptx
Python-04| Fundamental data types vs immutability
Python-04| Fundamental data types vs immutability
Python basics
Python basics
Primitive Wrappers
Primitive Wrappers
Python Homework Help
Python Homework Help
Python Homework Help
Python Homework Help
Anton Kasyanov, Introduction to Python, Lecture2
Anton Kasyanov, Introduction to Python, Lecture2
P1
P1
10 abstract
10 abstract
03 Variables - Chang.pptx
03 Variables - Chang.pptx
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
DEF CON 27 - workshop - EIGENTOURIST - hacking with monads
13 interfaces
13 interfaces
11 interfaces
11 interfaces
Data handling CBSE PYTHON CLASS 11
Data handling CBSE PYTHON CLASS 11
Plus de Program in Interdisciplinary Computing
Phpmysqlcoding
Phpmysqlcoding
Program in Interdisciplinary Computing
Database basics
Database basics
Program in Interdisciplinary Computing
CGS2835 HTML5
CGS2835 HTML5
Program in Interdisciplinary Computing
Mysocial databasequeries
Mysocial databasequeries
Program in Interdisciplinary Computing
Mysocial databasequeries
Mysocial databasequeries
Program in Interdisciplinary Computing
CGS2835 HTML5
CGS2835 HTML5
Program in Interdisciplinary Computing
01 intro tousingjava
01 intro tousingjava
Program in Interdisciplinary Computing
Xhtml
Xhtml
Program in Interdisciplinary Computing
Webdev
Webdev
Program in Interdisciplinary Computing
Web architecture
Web architecture
Program in Interdisciplinary Computing
Javascript
Javascript
Program in Interdisciplinary Computing
Javascript
Javascript
Program in Interdisciplinary Computing
Html5
Html5
Program in Interdisciplinary Computing
Frameworks
Frameworks
Program in Interdisciplinary Computing
Drupal
Drupal
Program in Interdisciplinary Computing
Database
Database
Program in Interdisciplinary Computing
Javascript2
Javascript2
Program in Interdisciplinary Computing
15b more gui
15b more gui
Program in Interdisciplinary Computing
14b exceptions
14b exceptions
Program in Interdisciplinary Computing
13 life and scope
13 life and scope
Program in Interdisciplinary Computing
Plus de Program in Interdisciplinary Computing
(20)
Phpmysqlcoding
Phpmysqlcoding
Database basics
Database basics
CGS2835 HTML5
CGS2835 HTML5
Mysocial databasequeries
Mysocial databasequeries
Mysocial databasequeries
Mysocial databasequeries
CGS2835 HTML5
CGS2835 HTML5
01 intro tousingjava
01 intro tousingjava
Xhtml
Xhtml
Webdev
Webdev
Web architecture
Web architecture
Javascript
Javascript
Javascript
Javascript
Html5
Html5
Frameworks
Frameworks
Drupal
Drupal
Database
Database
Javascript2
Javascript2
15b more gui
15b more gui
14b exceptions
14b exceptions
13 life and scope
13 life and scope
04 variables
1.
KNOW YOUR VARIABLES
So far we have discussed variables in two contexts: As object state (instance variables) As local variables (variables declared within a method) Now we continue to discuss variables as: Arguments (values sent to a method by the calling code) Return types (values sent back to the caller of the method) LIS4930 © PIC
2.
Declaring a variable
LIS4930 © PIC Java cares about type. It won’t let you do something bizarre or dangerous, like stuff a Bicycle reference into a Dog variable – what would happen if someone tries to ask the bicycle to bark()? For the compiler to catch these potential problems, Java requires us to declare the type of the variable. Is it an integer? a Dog? a single Character? Variables come in two flavors: primitives object references
3.
Declaring Variables LIS4930
© PIC You must follow two declaration rules: variables must have a type 1 variables must have a name 2 type name int count;
4.
Think of Cups!
LIS4930 © PIC Think of Java variables as different types of cups. Coffee cups, tea cups, beer cups, massive popcorn cups, Double Gulp cups.
5.
“I’d like a
tall Mocha, no make that an int.” LIS4930 © PIC A variable is just a cup. A container. It holds something. It has a size and a type. tall venti short grande When you go to Starbucks you know they have different sized cups, so you order what you want and tell them the size you would like. Just as they write your name on your cup in Starbucks, Java also requires you to give your variable a name. int short long byte In Java, primitives come in different sizes, and those sizes have names. The four containers here are for the four integer primitives in Java.
6.
Java Primitive Types
LIS4930 © PIC Note the ‘f’. Java assumes anything with a floating point is a double otherwise.
7.
8.
assign the
value of one variable to another (x = y)
9.
10.
boolean boo =
x;
11.
intg = 17;
12.
inty = g;
13.
y = y
+ 10;
14.
short s;
15.
s = y;
16.
byte b =
3;
17.
byte v =
b;
18.
short n =
12;
19.
v = n;
20.
21.
Reserved Words LIS4930
© PIC public static void boolean char byte short int long float double …or any of these! (don’t memorize these) Don’t use any of these for you own variable names (memorize these) Even if you don’t need to know what they mean, you still need to know you can’t use them yourself.
22.
23.
There’s only
an object reference variable.
24.
An object
reference variable holds bits that represent a way to access an object.
25.
26.
An Object Reference
is Just Another Variable Value LIS4930 © PIC Reference Variable Dog rufus = new Dog( ); The Dog object itself does not go into the Variable! Primitive Variable byte x = 7; The bits representing 7 go into the variable. (00000111) 00000111 int Dog
27.
3 Steps To
Making An Object LIS4930 © PIC Declare a reference variable 1 Dog rufus= new Dog( ); Dog rufus = new Dog( ); Dog rufus=new Dog( ); Create an object 2 Link the object and the reference 3
28.
What else about
Object References? LIS4930 © PIC Can a reference variable be programmed to refer to something else – can a Dog reference variable be programmed to reference a Cat object? Can a Dog reference variable be programmed to reference a different Dog object? What about objects marked as final? Can a reference variable ever refer to nothing at all? Is null a value? If an object is the only reference to a particular object, and then its set to null (deprogrammed), it means that now nobody can get to that object it once referred to.
29.
Life On The
Garbage-Collectible Heap LIS4930 © PIC b Book b = new Book(); 1 Book c = new Book(); Book object Book HEAP Book object 2 c References: 2 Objects: 2 Book
30.
Life On The
Garbage-Collectible Heap LIS4930 © PIC b Book d = c; 1 Book object Book HEAP Book object 2 c d Book References: 3 Objects: 2 Book
31.
Life On The
Garbage-Collectible Heap LIS4930 © PIC b c = b; 1 Book object Book HEAP X Book object 2 c d Book References: 3 Objects: 2 Book
32.
Life and Death
on the Heap LIS4930 © PIC b Book b = new Book(); 1 Book c = new Book(); Book object Book HEAP Book object 2 c References: 2 Objects: 2 Book
33.
LIS4930 © PIC
Life and Death on the Heap This guy is toast. b b= c; 1 Book object Book HEAP Book object 2 c Active References: 2 Reachable Objects: 1 Abandoned Objects: 1 Book
34.
LIS4930 © PIC
Life and Death on the Heap Still toast. b c = null; 1 Book object Book HEAP Book object X 2 c Active References: 1 null References: 1 Reachable Objects: 1 Abandoned Objects: 1 Book
35.
Array Variables LIS4930
© PIC An array variable is a remote to an array object. Declare an intarray variable. int[ ] nums; 1 Create a new int array with a length of 6, and assign it to the previously declared int[] variable nums nums = new int[6]; Give each elements in the array an intvalue. Remember, elements in an intarray are just intvariables. nums[0] = 6; nums[1] = 19; nums[2] = 44; nums[3] = 42; nums[4] = 10; nums[5] = 20; 2 3
36.
Array Variables LIS4930
© PIC 44 42 10 19 6 20 int int int int int int int[ ] 4 2 0 5 3 1 int array object (int[ ]) nums NOTE: The array is an object, even though it’s an array of primitives.
37.
LIS4930 © PIC
Array Variables Every element in an array is just a variable. In other words, one of the eight primitive variable types or a reference variable. Anything you would put in a variable of that type can be assigned to an array element of that type. So in an array of type int (int[ ]), each element can hold an int. So in a Dog array, each element can hold a remote control to a Dog. Arrays are always objects, whether they’re declared to hold primitives or object references. The array itself is never a primitive.
38.
Make an Array
of Dogs LIS4930 © PIC Declare an Dog array variable. Dog[ ] pets; Create a new Dog array with a length of 6, and assign it to the previously declared Dog[ ] variable pets. pets = new Dog[6]; 1 2 Dog Dog Dog Dog Dog Dog Dog[ ] 4 2 0 5 3 1 Dog array object (Dog[ ]) pets What’s Missing?
39.
Make an Array
of Dogs LIS4930 © PIC Create new Dog objects, and assign them to the array elements. Remember, elements in a Dog array are just Dog reference variables. We still need Dogs!!! pets[0] = new Dog; pets[1] = new Dog; pets[2] = new Dog; 3 Dog objects Dog[ ] Dog Dog Dog Dog Dog Dog pets 4 2 0 5 3 1 Dog array object (Dog[ ])
40.
Control Your Dog
LIS4930 © PIC name Dog rufus = new Dog(); rufus.name = “Rufus”; String Dog object Dog rufus name bark() eat() chaseCat() What happens if the Dog is in a Dog array? Dog
41.
Dog Array LIS4930
© PIC Dog[ ] myDogs = new Dog[3]; myDogs[0] = new Dog(); myDogs[0].name = “Rufus”; myDogs[0].bark(); Dog name Dog Remote bark() eat() chaseCat() When the Dog is in an array, we don’t have an actual variable name (like rufus). Instead we use array notation and push the remote control button (dot operator) on an object at a particular index (position) in the array. Eg: myDogs[1].bark(); chaseCat bark eat myDogs[0]
42.
Java Cares About
Type LIS4930 © PIC Once you’ve declared an array, you can’t put anything in it except things that are of the declared array type. You can’t put a Cat into a Dog array, or a double into an int array (spillage, remember?). You can, however, put a byte into an intarray, because a byte willalways fit into an int-sized cup. This is known as implicit widening. We’ll get into the details later, but for now just remember that the compiler won’t let you put the wrong thing in an array, based on the array’s declared type. I don’t’ belong here.
43.
Dog Example LIS4930
© PIC Do you understand everything in this code? What does this mean? Dog name bark() eat() chaseCat()
Notes de l'éditeur
When you see a statement like: “an object of type X”, think of type and class as synonyms.
Télécharger maintenant