CC102 Week-5 Lesson-Programming Basics
CC102 Week-5 Lesson-Programming Basics
PROGRAMMING BASICS
CC102 – PROGRAMMING 1
• Discuss the the different data types used in java
programming;
• Understand the variable declaration, identifiers
and keywords;
• Recognize the different Java keywords
categorically.
2
Parameters used in First Java Program
• class keyword is used to declare a class in java.
• public keyword is an access modifier which represents visibility.
• static is a keyword. If we declare any method as static, it is known as the static
method.
• void is the return type of the method. main represents the starting point of
the program.
• String[] args is used for command line argument.
• System.out.println() is used to print statement.
3
Basic Syntax
• Case Sensitivity − Java is case sensitive, which means identifier Hello and hello would have
different meaning in Java.
• Class Names − For all class names the first letter should be in Upper Case. If several words
are used to form a name of the class, each inner word's first letter should be in Upper Case.
• Example: class MyFirstJavaClass
• Method Names − All method names should start with a Lower Case letter. If several words
are used to form the name of the method, then each inner word's first letter should be in
Upper Case.
• Example: public void myMethodName()
• Program File Name − Name of the program file should exactly match the class name.
4
Java Keywords
• Java keywords are also known as reserved words. Keywords are particular
words which acts as a key to a code. These are predefined words by Java so it
cannot be used as a variable or object name.
5
Java Identifiers
• All Java components require names. Names used for classes, variables, and
methods are called identifiers.
• All identifiers should begin with a letter (A to Z or a to z), currency character ($)
or an underscore (_).
• After the first character, identifiers can have any combination of characters.
• A key word cannot be used as an identifier.
• Most importantly, identifiers are case sensitive.
• Examples of legal identifiers: age, $salary, _value, __1_value.
• Examples of illegal identifiers: 123abc, -salary.
6
Java Variables
• A variable is a container which holds the value while the java program is
executed. A variable is assigned with a datatype.
• Variable is a name of memory location. There are three types of variables in
java: local, instance and static.
7
Java Variables
• A variable is a container which holds the value while the java program is
executed. A variable is assigned with a datatype.
• Variable is a name of memory location. There are three types of variables in
java: local, instance and static.
Local Variables.
Instance Variable
Static variable
8
Java Variables
9
Java Variables
• Example to understand the types of variables in java
class A{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
10
Java Variables
• Java Variable Example: Add Two Numbers
class Simple{
public static void main(String[] args){
int a=10;
int b=10;
int c=a+b;
System.out.println(c);
}}
11
Data Types in Java
• Data types specify the different sizes and values that can be stored in
the variable. There are two types of data types in Java:
12
Java Primitive Data Types
• are the building blocks of data manipulation. These are the most
basic data types available in Java language.
• There are 8 types of primitive data types:
1. boolean data type 5. int data type
2. byte data type 6. long data type
3. char data type 7. float data type
4. short data type 8. double data type
13
Data Types in Java
Boolean Data Type
The Boolean data type is used to store only two possible values: true and false. This data
type is used for simple flags that track true/false conditions.
Example: Boolean one = false
14
Data Types in Java
Short Data Type
The short data type is a 16-bit signed two's complement integer.
Example: short s = 10000, short r = -5000
15
Data Types in Java
Long Data Type
The long data type is a 64-bit two's complement integer.
Example: long a = 100000L, long b = -200000L
16
References:
• TutorialsPoint.,( 2019). Learn Java Programming Retrieved from:
https://www.tutorialspoint.com/java.
• JavaTPoint., (2019). Java Tutorial. Retrieved from:
https://www.javatpoint.com/java-tutorial
17
18