Download presentation
Presentation is loading. Please wait.
Published bySuzan Charles Modified over 9 years ago
1
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
2
HERE ARE THE 5 BASIC CONCEPTS Variables Control Structures Data Structures Syntax Tools
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
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)
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 furtherexpressionevaluated 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
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?
8
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.
9
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.
10
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 ?
11
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
12
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;
13
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.
14
DOUBLE A double variable is one that holds a decimal number. For example: double number = 4.67;
15
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.
16
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.
17
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”.
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
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.