Review JAVA Programming Elements Data Types Summery Think ON...
Question
Introduction to Programming
04-Basic Concepts of Java(Java Elements and Variables))
Khadija Rahmany
Women Online University
Computer Science Faculty
April 25, 2024
Review JAVA Programming Elements Data Types Summery Think ON... Question
Table of contents
Review
JAVA Programming Elements
Data Types
Summery
Think ON...
Question
Review JAVA Programming Elements Data Types Summery Think ON... Question
Review
1. Which kind of application can we create with java?
Review JAVA Programming Elements Data Types Summery Think ON... Question
Review
1. Which kind of application can we create with java?
2. What is meaning by Platform Independence in java?and why
it is Platform Independence?
Review JAVA Programming Elements Data Types Summery Think ON... Question
Review
1. Which kind of application can we create with java?
2. What is meaning by Platform Independence in java?and why
it is Platform Independence?
3. What is wrong with this line of code? [Link] (”He
said, ”Hello””)
Review JAVA Programming Elements Data Types Summery Think ON... Question
Review
1. Which kind of application can we create with java?
2. What is meaning by Platform Independence in java?and why
it is Platform Independence?
3. What is wrong with this line of code? [Link] (”He
said, ”Hello””)
4. What is wrong with this program?
class Welcome1
public static void main( String args[])
[Link]( ”Welcome to Java” );
// end class Welcome1
Review JAVA Programming Elements Data Types Summery Think ON... Question
Review
1. Which kind of application can we create with java?
2. What is meaning by Platform Independence in java?and why
it is Platform Independence?
3. What is wrong with this line of code? [Link] (”He
said, ”Hello””)
4. What is wrong with this program?
class Welcome1
public static void main( String args[])
[Link]( ”Welcome to Java” );
// end class Welcome1
5. What is the source file name of the code above?
Review JAVA Programming Elements Data Types Summery Think ON... Question
Programming Elements
• Every programming language has Elements that make up the
language.
• Almost all languages have special symbols and syntax rules for
their use.
• Some languages use similar elements.
• Learning one language often makes learning another
programming language quite simple.
Review JAVA Programming Elements Data Types Summery Think ON... Question
Programming Elements
There are the most programming element, which also use in java.
• Variables
• Keywords • Constants
• Identifiers • Literals
• Separators • Operators
• White Space • Expression
• Comments • Statements
• Data Types • Blocks
• Scope
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Keywords
• In Java,like other languages,There are many keywords form
the vocabulary of the language
• The keywords are reserved for the system to use.
• The keywords are used for a number of tasks.
• Java compiler is case sensitive, all keywords must be entered
in lowercase .
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Keywords
• The following character sequences are reserved for use as
keywords and cannot be used as identifiers
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Identifiers
• Identifier are the names used for variables, methods, classes
to distinguish them by the complier.
• An identifier can consist of letters,digits 0-9,the underscore
, or the dollar sign.
• An identifier cannot be a keyword or true, false, or null.
• Identifiers begin with a letter of the alphabet,either upper or
lower case.
• The only exceptions to this rule are the underscore symbol
(-) and the dollar sign ($).If you try to use any other symbol
or a numeral as the initial character, you will receive an error.
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Separators
• Separators are used in Java to delineate blocks of code.{ } ( )
[];,
• Curly Braces: A block is a collection of statements that is
bounded by the braces { }, they bound the class definitions,
method definitions and other statement that should be
executed in a group.
• Round Braces:Used to define a block of arguments or
Conditions( )
• Square Braces: Used to define Arrays[ ]
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Separators
• Separators are used in Java to delineate blocks of code.{ } ( )
[];,
• Commas: Comma serve as the separatorof [Link]
that require a list of values, require that each value be
separated by a comma.
• Semicolons: A statement is terminated, or ended by a
semicolon ; omitting semicolon makes the common compiler
error.
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
White Space
• White space separates keywords form keywords and
Identifiers
• it is included in printing and displaying information.
• Example:
public class Student
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Comments
• If you want to have extera information about your codes you
can use from Comment
• it makes your code easy to understand, modify and use.
• Java supports different comment styles.
• Comment style #1: // Comments here...
• A end-of-line comment
• Everything after the double slash marks is ignored by the Java
Complier.
• Comment style #2: /* Comments here... */
• A traditional comment
• This style of commenting is useful when you have multiple
lines of comments
Review JAVA Programming Elements Data Types Summery Think ON... Question
JAVA Programming Elements
Data Types
• A data type is a classification of a particular form of
information.
• In most programing languages, data can be from different
types:
• A text: ( = String )
• A real number ( = int )
• The values true and false ( = boolean )
• Different types use different amount of computer memory.
• Data can be moved from the storage of one data type to
another (type conversion) under specific conditions.
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
What Types exist in Java?
• In Java, there exist two kinds of data types:
1. Primitive Types
2. Objects Types
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
What Types exist in Java?
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
Primitive Types
• Primitive Types
• They are basic types that used to store simple kinds of
[Link] real numbers
• A primitive data value uses a small, fixed number of bytes.
• A programmer can not create new primitive data types.
• There are eight types of Java primitives:
• Boolean, char, byte, short, int, long, float, and double.
• The Boolean data type stores a representation of the values
true or [Link] reserved words true and false are the only
valid values for a boolean type.
• The char data type stores a single character. character literals
are delimited by single quotes: ’a’ ’X’ ’7’ ’$’ ’,’ .
• The remaining six types of primitives are used for numbers.
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
Primitive Types
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
Primitive Types
• Boolean
• The Boolean data type stores a representation of the values
true or false.
• The reserved words true and false are the only valid values for
a boolean type.
• A boolean variable can represent any two states such as a light
bulb being on or off.
• Example: boolean isOn = true;
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
Primitive Types
• Characters
• The char data type stores a single character.
• character literals are delimited by single quotes: ’a’ ’X’ ’7’ ’$’
’,’ .
• Example: char topGrade = ’A’;
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
Primitive Types: Examples
• short a = -128;
• short b = 127;
• int j = -2147483648;
• int k = 2147483647;
• boolean question = true;
• boolean question1 = false;
• float fp1 = 2.43;
• float fp2 = -123.58;
• char topGrade = ’A’;
Review JAVA Programming Elements Data Types Summery Think ON... Question
Data Types
Objects Types
• Objects Types
• Objects are more complex types.
• An object may use many bytes of memory.
• These Objects can be used like primitive data types.
• In Java One example of object is String data type which is the
representation of a text.
• Strings always start and end with double quotes.
• Example : String word = ‘hello world‘
Review JAVA Programming Elements Data Types Summery Think ON... Question
Summery
• Every programming language has Elements that make up the
language.
• Almost all languages have special symbols and syntax rules for
their use. Some languages use similar elements.
• There are the most programming element, which also use in
java such as: Identifier, Keywords, Separators, White Space,
Comments and Data Types.
Review JAVA Programming Elements Data Types Summery Think ON... Question
Think ON...
• Java Elements
Review JAVA Programming Elements Data Types Summery Think ON... Question
Question