Variables in Programming Languages

 
5 BASIC CONCEPTS OF
ANY PROGRAMMING
LANGUAGE
 
Let’s get started …
 
HERE ARE THE 5 BASIC CONCEPTS
 
Variables
Control Structures
Data Structures
Syntax
Tools
 
WHAT IS A VARIABLE
 
Variables are the backbone of any program, and thus the backbone of any
programming language.
 
Generally defined in Computer Programming as a storage location with an
associated symbolic name which contains some known or unknown quantity or
information (a value)
 
Summing it up a variable is simply a way to store some sort of information for us to
use later, we can retrieve this information by referring to a word that describes this
information.
 
Java behaves differently because of the 
type
 of the variables.
These are the Java variables we will work with:
boolean
byte
char
float
int
long
short
double
String
 
LET’S TRY AN EXAMPLE
 
Let’s say you visit a website and the first thing they want to do is get your email
and name so that the next time you visit the site will remember you and welcome
you back.
 
To do this they would put in a little pop-up text box on the screen and ask you for
your name – that textbox is going to represent the variable .
 
Let’s call the text box “yourName” that becomes the symbolic name (or word)
for your variable. (remember our original definition)
 
You will type your name into the text box, that information is
stored in the variable “yourName
 
Next comes the value of the variable
 
Value is defined as an 
expression
 which cannot be 
evaluated
(this is what will be returned) any further
 
The program you write using variable  would return whatever
was typed into that text box.
 
Examples where this is used: Facebook, Twitter, anyplace you
go online and sign up/ sign in
 
LET’S GET MORE SPECIFIC
 
Variables have different types
 
Example type in a name as a variable that is recognized as a String
 
Type in your Age that becomes and Integer or Int
 
I as for the year you were born (4 digits) that is stored as a Double
 
Why is this important?
 
JAVA IS A STRONGLY TYPED
LANGUAGE
 
Java has to know what kind of information is being stored in a
variable.
Tying in Java means the program knows exactly what is being
stored in a variable
 
Example: Integer
An Integer in Java means you have a number that won’t have
any decimal places, it will be a whole number like 5, 20, -40, 4000,
or -16000.
 
INT
 
An int variable holds an integer
  
int num = 2;
 
Unlike double, an int can ONLY hold integers. You cannot store a
decimal inside of an int. You can store negative numbers in both
ints and doubles however.
 
SIMPLE EXAMPLE
 
You want to add two number together let’s say the number 22
and the number 3. Java will behave differently depending on the
type of the variable that’s storing this data.
Let me show you what I mean:
If you have defined your variables to be of type 
Integer
, then
adding 22 and 3 together will result in the 
Integer
 25. Makes
perfect sense right? Of course, this is simple Math.
But what happens if your variables are not 
Integers
, but are
Strings
?
 
WHAT HAPPENS IF
 
So what if you enter something that isn’t an Integer as an Int
 
Example you enter a value of $34.75
 
Java would give you an error code when you compile and you
would have to fix it
 
BOOLEAN
 
A boolean is one of the special Java variables that stores either true or false. I say
special because in true and false are actually values that the language recognizes.
Here is an example:
 
                   
Boolean x = true;
 
CHAR
 
A char variable is a variable that holds a single character. A character is a single
letter, number, or symbol. For example, 'A' is a character, so is '1' and '&'. Those
are all characters. Let's see what a character variable looks like.
                                  Char c = ‘g’;
 
capital letters are not the same as lower
case letters and vice versa
.
 
DOUBLE
 
A double variable is one that holds a decimal number. For
example:
 
  
double number = 4.67;
 
STRING
 
String is not a basic variable it is a little more complicated.
   
String name = “John”;
 
A string variable must have quotes around the value in order for it
to be a string. Strings can be made up of one letter, one word,
whole sentences, or even entire paragraphs. You can also have
empty strings.
 
STRINGS
 
A 
String
 in Java is a different kind of data type and it behaves
differently BECAUSE it is a different type of data.
 
When we refer to a 
String
 in Java (and in many other
programming languages) we are treating the data like it’s just a
plain old sentence in the English language. A String just
represents words (or more specifically letters) all placed in a
certain order. That’s all the English language (or any language) is,
a series of characters/letters placed in a certain order to give
meaning to what you’re writing down.
 
EXAMPLE OF STRINGS
 
If you were to have two variables, each defined as 
Strings
 and
they stored the data “22” and “3” (respectively), what would
happen if we added them together?
 
We would get the 
String
: “223”
 
What if the two 
String
 variables, aren’t storing numbers, we’re
storing words. So in variable 1 we store the String “Hello”, and in
variable 2 we store the String “World”.
 
WHY ARE WE TALKING ABOUT ANY OTHER
PROGRAMMING LANGUAGES – THIS CLASS IS ABOUT
JAVA
 
Many of the languages are very similar: C+, C++, Python, Objective C
 
Know one language like Java and the rest can be easily learned
Slide Note
Embed
Share

Variables play a crucial role in programming by storing information for later use. They are like containers with symbolic names that hold known or unknown quantities. Different programming languages handle variables uniquely based on types like boolean, byte, char, and more. Knowing how to define and use variables correctly is essential for writing effective programs.

  • Programming
  • Variables
  • Data Structures
  • Syntax
  • Java

Uploaded on Sep 26, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. 5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let s get started

  2. Variables Control Structures Data Structures Syntax Tools HERE ARE THE 5 BASIC CONCEPTS

  3. WHAT IS A VARIABLE Variables are the backbone of any program, and thus the backbone of any programming language. Generally defined in Computer Programming as a storage location with an associated symbolic name which contains some known or unknown quantity or information (a value) Summing it up a variable is simply a way to store some sort of information for us to use later, we can retrieve this information by referring to a word that describes this information.

  4. Java behaves differently because of the type of the variables. These are the Java variables we will work with: boolean byte char float int long short double String

  5. LETS TRY AN EXAMPLE Let s say you visit a website and the first thing they want to do is get your email and name so that the next time you visit the site will remember you and welcome you back. To do this they would put in a little pop-up text box on the screen and ask you for your name that textbox is going to represent the variable . Let s call the text box yourName that becomes the symbolic name (or word) for your variable. (remember our original definition)

  6. You will type your name into the text box, that information is stored in the variable yourName Next comes the value of the variable Value is defined as an expression which cannot be evaluated (this is what will be returned) any further The program you write using variable would return whatever was typed into that text box. Examples where this is used: Facebook, Twitter, anyplace you go online and sign up/ sign in

  7. Variables have different types Example type in a name as a variable that is recognized as a String Type in your Age that becomes and Integer or Int I as for the year you were born (4 digits) that is stored as a Double Why is this important? LET S GET MORE SPECIFIC

  8. Java has to know what kind of information is being stored in a variable. Tying in Java means the program knows exactly what is being stored in a variable Example: Integer An Integer in Java means you have a number that won t have any decimal places, it will be a whole number like 5, 20, -40, 4000, or -16000. JAVA IS A STRONGLY TYPED LANGUAGE

  9. An int variable holds an integer int num = 2; Unlike double, an int can ONLY hold integers. You cannot store a decimal inside of an int. You can store negative numbers in both ints and doubles however. INT

  10. You want to add two number together lets say the number 22 and the number 3. Java will behave differently depending on the type of the variable that s storing this data. Let me show you what I mean: If you have defined your variables to be of type Integer, then adding 22 and 3 together will result in the Integer 25. Makes perfect sense right? Of course, this is simple Math. But what happens if your variables are not Integers, but are Strings? SIMPLE EXAMPLE

  11. So what if you enter something that isnt an Integer as an Int Example you enter a value of $34.75 Java would give you an error code when you compile and you would have to fix it WHAT HAPPENS IF

  12. A boolean is one of the special Java variables that stores either true or false. I say special because in true and false are actually values that the language recognizes. Here is an example: Boolean x = true; BOOLEAN

  13. A char variable is a variable that holds a single character. A character is a single letter, number, or symbol. For example, 'A' is a character, so is '1' and '&'. Those are all characters. Let's see what a character variable looks like. Char c = g ; capital letters are not the same as lower case letters and vice versa. CHAR

  14. A double variable is one that holds a decimal number. For example: double number = 4.67; DOUBLE

  15. String is not a basic variable it is a little more complicated. String name = John ; A string variable must have quotes around the value in order for it to be a string. Strings can be made up of one letter, one word, whole sentences, or even entire paragraphs. You can also have empty strings. STRING

  16. A String in Java is a different kind of data type and it behaves differently BECAUSE it is a different type of data. When we refer to a String in Java (and in many other programming languages) we are treating the data like it s just a plain old sentence in the English language. A String just represents words (or more specifically letters) all placed in a certain order. That s all the English language (or any language) is, a series of characters/letters placed in a certain order to give meaning to what you re writing down. STRINGS

  17. If you were to have two variables, each defined as Strings and they stored the data 22 and 3 (respectively), what would happen if we added them together? We would get the String: 223 What if the two Stringvariables, aren t storing numbers, we re storing words. So in variable 1 we store the String Hello , and in variable 2 we store the String World . EXAMPLE OF STRINGS

  18. WHY ARE WE TALKING ABOUT ANY OTHER PROGRAMMING LANGUAGES THIS CLASS IS ABOUT JAVA Many of the languages are very similar: C+, C++, Python, Objective C Know one language like Java and the rest can be easily learned

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#