0% found this document useful (0 votes)
5 views35 pages

Java - Basic - Part 1 to Part 3 - Introduction to Programming, Data Types, Variables, Operators, Expressions, Precedence

This document serves as a lesson plan for an introductory course on Java programming, covering essential topics such as data types, variables, operators, expressions, and operator precedence. It includes explanations of Java's features, examples of code, and rules for variable naming, along with various types of operators. Additionally, it provides problem statements for practical exercises to reinforce learning.

Uploaded by

Yadhavan PS-1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views35 pages

Java - Basic - Part 1 to Part 3 - Introduction to Programming, Data Types, Variables, Operators, Expressions, Precedence

This document serves as a lesson plan for an introductory course on Java programming, covering essential topics such as data types, variables, operators, expressions, and operator precedence. It includes explanations of Java's features, examples of code, and rules for variable naming, along with various types of operators. Additionally, it provides problem statements for practical exercises to reinforce learning.

Uploaded by

Yadhavan PS-1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

INTRODUCTION TO PROGRAMMING

DATA TYPES, VARIABLES & OPERATORS


EXPRESSIONS, PRECEDENCE
Lesson Plan

Subject/Course Basic Java Programming


Lesson Title Introduction to Programming

Lesson Objectives
Introduction to programming
Data types, Variables, operators
Expression, Precedence
What is programming?
Programming is the process of writing instructions that a computer can understand and execute to
perform a task. In Java, these instructions are written using syntax rules of the Java language.

What is Java?
High-level, object-oriented, and platform-independent
Write Once, Run Anywhere – Java code can run on any device with the Java Virtual Machine (JVM)
Widely used in enterprise applications, Android apps, and web development

Why Learn Java?


Strong community support
Rich library and API support
Easy to debug and maintain
Great for beginners and professionals
Example

public class HelloWorld {


public static void main(String[] args) {
System.out.println("Hello, World!");
}
}

Explanation:
public class HelloWorld – Defines a class
main – Starting point of the program
System.out.println() – Prints output to console
Data Types- In Java, data types define the kind of data a variable can hold. Java is
a statically typed language, which means all variables must be declared with a data type.
Example
public class DataTypes {
public static void main(String[] args) {
int age = 25;
float percentage = 87.5f;
char grade = 'A';
boolean isPassed = true;
String name = "Sweety";

System.out.println("Name: " + name);


System.out.println("Age: " + age);
System.out.println("Percentage: " + percentage);
System.out.println("Grade: " + grade);
System.out.println("Passed: " + isPassed);
}
}
Variables-In Java, variables are containers used to store data values during program
execution. Every variable in Java must be declared with a data type, which determines the
size and type of data it can hold.

Syntax:
datatype variableName = value;
Rules for Naming Variables:
•Must start with a letter, _, or $
•Cannot start with a digit
•No spaces or special characters
•Case-sensitive (score and Score are different)
•Cannot use reserved keywords (int, class,
etc.)
Example
public class Variables{
String name; // Instance variable
static String school = "Greenwood High"; // Static variable
void displayDetails() {
int marks = 95; // Local variable
System.out.println("Name: " + name);
System.out.println("Marks: " + marks);
System.out.println("School: " + school);
}
public static void main(String[] args) {
Student s1 = new Student();
s1.name = "Sweety";
s1.displayDetails();
}
}
Operators-In Java, operators are special symbols used to perform operations on variables and values. They are the backbone of logic, math, comparisons, and decision-making in Java programs.
Unary Operators-Operate on a single operand

Operator Description Example


+ Unary plus +a
- Unary minus -a
++ Increment a++ or ++a
-- Decrement a-- or –a
! Logical NOT !flag
Arithmetic Operators-Perform basic math operations

Operator Description Example

+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b
% Modulus (remainder) a%b
Relational Operators-Compare two values

Operator Description Example

== Equal to a == b

!= Not equal to a != b

> Greater than a>b

< Less than a<b

>= Greater than or equal to a >= b


<= Less than or equal to a <= b
Logical Operators-Combine multiple conditions

Operator Description Example

&& Logical AND a > 5 && b < 10


|| Logical OR a > 5 || b < 10
! Logical NOT !(a == b)
Assignment Operators-Assign values to variables

Operator Description Example


= Assign a = 10
+= Add and assign a += 5
-= Subtract and assign a -= 3
*= Multiply and assign a *= 2
/= Divide and assign a /= 4
%= Modulus and assign a %= 2
Bitwise Operators-Perform bit-level operations

Operator Description Example

& Bitwise AND a&b

^ Bitwise XOR a^b

~ Bitwise Complement ~a

<< Left shift a << 2


>> Right shift a >> 2
Ternary Operators-Short-hand for if-else

Syntax Description

condition ? a : b Returns a if condition is true, else b


Example
public class Operator{
public static void main(String[] args) {
int a = 10, b = 5;
System.out.println("Addition: " + (a + b));
System.out.println("Is a > b? " + (a > b));
System.out.println("Logical AND: " + (a > 5 && b < 10));
System.out.println("Max using ternary: " + ((a > b) ? a : b));
}
}
Expression
An expression is a construct made up of operands and operators that produces a
result.

Expression Description Result


5+3 Arithmetic expression 8
Multiplies values of variables x
x*y Depends on values
and y
Relational expression (returns
a>b true / false
boolean)
"Hello" + " World" String concatenation "Hello World"
(a > b) ? a : b Ternary expression max value
Example
public class Expressions {
public static void main(String[] args) {
int a = 10, b = 20;

int sum = a + b; // Arithmetic expression


boolean isGreater = a > b; // Relational expression
boolean result = (a < b) && true; // Logical expression
int max = (a > b) ? a : b; // Ternary expression

System.out.println("Sum: " + sum);


System.out.println("Is a > b? " + isGreater);
System.out.println("Logical Result: " + result);
System.out.println("Maximum: " + max);
}
}
Precedence

In Java, operator precedence determines the order in which operators are evaluated in an
expression. If multiple operators are used in a single expression, the one with higher precedence is
evaluated first.

int result = 10 + 5 * 2;

Here, multiplication (*) has higher precedence than addition (+), so the expression is evaluated as:

10 + (5 * 2) = 10 + 10 = 20
Precedence Level Operators Category
1 (Highest) () Parentheses (grouping)
++, --, + (unary), - (unary), !,
2 Unary
~
3 *, /, % Arithmetic
4 +, - Arithmetic
5 <<, >>, >>> Bitwise shift
6 <, <=, >, >=, instanceof Relational
7 ==, != Equality
8 & Bitwise AND
9 ^ Bitwise XOR
10 | Bitwise OR
11 && Logical AND
12 || Logical OR
13 ?: Ternary
14 (Lowest) =, +=, -=, *=, /=, etc. Assignment
Associativity
When two operators have the same precedence, associativity decides the order of evaluation.

Associativity Type Operators Example

Left to Right +, -, *, /, %, <, >, etc.

Right to Left =, +=, *=, ?:, ++, --

int x = 10, y = 5, z = 2;
int result = x - y - z; // Left to Right: (10 - 5) - 2 = 3

int a = b = c = 5; // Right to Left: c = 5, b = 5, a = 5


Problem Statement 1 - Basic
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 0 : java_IP_L0_9(Width Space)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/64f6501f-fd7b-4407-
a33f-5a7fa0649a3f
Problem Statement 2 - Intermediate
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 1 : Java_IP_L1_2(ASCII value to
Character )
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/5b563d3a-324e-4803-
a5f4-826f7df0051c
Problem Statement 3 - Intermediate
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 1 : Java_IP_L1_4(Providing width
space)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/5b563d3a-324e-4803-
a5f4-826f7df0051c
Problem Statement 4 - Intermediate
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 1 : Java_IP_L1_5(Precision value)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/5b563d3a-324e-4803-
a5f4-826f7df0051c
Problem Statement 5 - Complex
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 2 : java_IP_L2_7(If input is 1, print
2. If input is 2, print 1)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/dd4ec96c-a81c-43f9-
b0b9-f2e7c3419e29
Problem Statement 6 - Complex
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 2 : java_IP_L2_9.Convert given
seconds to Hours Minutes and Seconds
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/dd4ec96c-a81c-43f9-
b0b9-f2e7c3419e29
Problem Statement 7 - Complex
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 2 : java_IP_L2_10(TOT_DAYS to
years,weeks and days)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/dd4ec96c-a81c-43f9-
b0b9-f2e7c3419e29
Problem Statement 8 - Advanced
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 3 : java_IP_L3_1(Given a celcius ,
find its equivalent farenheit)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/3f806cb7-23ba-4a5d-
9d12-e9b11c8d65ca
Problem Statement 9 - Advanced
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 3 : java_IP_L3_3(kilogram to
pounds)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/3f806cb7-23ba-4a5d-
9d12-e9b11c8d65ca
Problem Statement 10 - Advanced
Problem Statement Path:
Java Technical Course
Basic Java
Basic Input & Output
Basic I/P & O/P Level 3 :java_IP_L3_5(km to miles)
Link :https://lms.talentely.com/test/test/6581c2c2-
2126-4181-b63b-2f57b2d1c8c3/3f806cb7-23ba-4a5d-
9d12-e9b11c8d65ca
Thank You

You might also like