SlideShare a Scribd company logo
Java Basic Elements
Lecture 5
Outline
• Starting with Java
• Elements of Java
• Variables
• Constants
• Escape Sequences
Starting with Java
public static void main(String args[])
means you can call this method from any where .
keyword in java means you don't need object for this you can directly call it.
means this method is not returning any thing.
Name of the method
String args[], which is actually an array of String type, and it's name is args
here. args[] is for passing arguments to your program.
Elements of Java
• Java programs are a collection of
1. Whitespace
2. Identifiers
3. Comments
4. Literals
5. Operators
6. Separators, and
7. Keywords
• Whitespace in Java is used to
separate the tokens in a Java source
file.
• In Java, whitespace is a space, tab, or
newline.
• Java Literals are syntactic
representations of Boolean,
character, numeric, or string data.
Literals provide a means of
expressing specific values in your
program.
• An identifier is any name in a Java
program. Identifiers are used to
denote classes, methods, variables
and labels.
• An identifier may be any descriptive
sequence of uppercase and
lowercase
• letters, numbers, or the underscore
and dollar-sign characters.
• Java is case-sensitive.
• Valid: AvgTemp, count, a4, $test,
this_is_ok
• Invalid: 2count, high-temp, Not/ok
• Comments are portions of the code
ignored by the compiler which allow
the user to make simple notes in the
relevant areas of the source code.
Comments come either in block form
or as single lines.
1
2
3
4
Elements of Java (Cont.)
5. Operators: Operators are used to perform operations on variables and values.
Arithmetic
Operator Name Description Example
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from another x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division remainder x % y
Increment and Decrement Operators
Operator Name Description Example
++ Increment Increases the value of a variable by
1
++x
-- Decrement Decreases the value of a variable by
1
--x
Assignment Operator
Operator Example Same As
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
Bitwise Operators
Operator Description Example Same as Result Decimal
& AND - Sets each bit to 1 if both bits are 1 5 & 1 0101 & 0001 0001 1
| OR - Sets each bit to 1 if any of the two bits is 1 5 | 1 0101 | 0001 0101 5
~ NOT - Inverts all the bits ~ 5 ~0101 1010 10
^ XOR - Sets each bit to 1 if only one of the two bits is
1
5 ^ 1 0101 ^ 0001 0100 4
<< Zero-fill left shift - Shift left by pushing zeroes in
from the right and letting the leftmost bits fall off
9 << 1 1001 << 1 0010 2
>> Signed right shift - Shift right by pushing copies of
the leftmost bit in from the left and letting the
rightmost bits fall off
9 >> 1 1001 >> 1 1100 12
>>> Zero-fill right shift - Shift right by pushing zeroes in
from the left and letting the rightmost bits fall off
9 >>> 1 1001 >>> 1 0100 4
Comparison Operators
Operator Name Example
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
Logical Operators
Operator Name Description Example
&& Logical and Returns true if both statements are true x < 5 && x < 10
|| Logical or Returns true if one of the statements is
true
x < 5 || x < 4
! Logical not Reverse the result, returns false if the
result is true
!(x < 5 && x < 10)
Elements of Java (Cont.)
5. Operators: Operators are used to perform operations on variables and values.
– Unary
• Require only one operand; they perform various operations such as
incrementing/decrementing a value by one, negating an expression, or inverting the value of
a Boolean.
– Ternary
• The conditional operator or ternary operator ?: is shorthand for the if-then-else statement.
The syntax of the conditional operator is:
variable = Expression ? expression1 : expression2
Elements of Java (Cont.)
– Operator Precedence
Elements of Java
• Separators: Separators help define the structure of a program.
Symbol Name Purpose
() Parentheses Used to contain lists of parameters in method definition and
invocation. Also used for defining precedence in expressions,
containing expressions in control statements, and surrounding cast
types.
{} Braces Used to contain the values of automatically initialized arrays.
Also used to define a block
of code, for classes, methods, and local scopes.
[] Brackets Used to declare array types. Also used when dereferencing array
values.
; Semicolon Terminates statements.
, Comma Separates consecutive identifiers in a variable declaration. Also
used to chain statements together inside a for statement.
. Full-stop Used to separate package names from subpackages and classes. Also
used to separate a variable or method from a reference variable.
Elements of Java
• Keywords(Java Reserved Keywords): Java has a set of keywords that are reserved
words that cannot be used as variables, methods, classes, or any other identifiers.
Variables
• Variable is a name of memory location. There are three types of variables in java:
local, instance and static.
• Types of Variable: There are three types of variables in java:
– local variable: A variable which is declared inside the method is called local variable.
– instance variable: Instance variables in Java are non-static variables which are defined in
a class outside any method, constructor or a block. Each instantiated object of the class
has a separate copy or instance of that variable. An instance variable belongs to a class.
– static variable: A static variable is common to all the instances (or objects) of the class
because it is a class level variable. In other words you can say that only a single copy of
static variable is created and shared among all the instances of the class.
Variables - Example
• 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
Constants
• A constant is a variable whose value cannot change once it has been assigned.
• Java doesn't have built-in support for constants.
• Syntax: modifier final dataType variableName = value; //global
constant
• For a simple floating point value (a number with a fractional part) like Pi, it would
look something like:
private static final double PI = 3.1415926;
Escape Sequences
• A character preceded by a backslash () is an escape sequence and has a special
meaning to the compiler.
Sequence Name Meaning
n New line Moves to beginning of next line
b Backspace Backs up one character
t Horizontal tab
Moves to next tab position
Tab spacing is every 8 columns starting with 1.
(Columns 9, 17, 25, 33, 41, 49, 57, 65, 73 ...)
 Backslash Displays an actual backslash
' Single quote Displays an actual single quote
" Double quote Displays an actual double quote
References
• https://www.edx.org/learn/java
• https://www.infoworld.com/article/2076075/core-java-learn-java-from-the-grou
nd-up.html
• https://www.geeksforgeeks.org/java-how-to-start-learning-java/
• https://www.geeksforgeeks.org/jvm-works-jvm-architecture/
• https://beginnersbook.com/2013/05/jvm/
• https://www.iare.ac.in/sites/default/files/lecture_notes/IARE_OOPS_THROUGH_
JAVA_LECTURE_NOTES.pdf
• https://lecturenotes.in/notes/23198-note-for-object-oriented-programming-usin
g-java-oopj-by-debasish-pradhan?reading=true
• https://www.softwaretestinghelp.com/java/java-introduction-installation/

More Related Content

Similar to Java Basic Elements Lecture on Computer Science (20)

PPTX
UNIT 2 programming in java_operators.pptx
jijinamt
 
PPTX
Fundamental programming structures in java
Shashwat Shriparv
 
PDF
Java q ref 2018
Christopher Akinlade
 
PPT
Java Basics
Dhanunjai Bandlamudi
 
PPTX
PCSTt11 overview of java
Archana Gopinath
 
PPTX
Android webinar class_java_review
Edureka!
 
PPTX
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
PPTX
Intro to Scala
manaswinimysore
 
PDF
C Programming - Refresher - Part II
Emertxe Information Technologies Pvt Ltd
 
PPTX
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
GANESHBABUVelu
 
PPTX
Java basics and java variables
Pushpendra Tyagi
 
PPT
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Sagar Verma
 
PDF
Ma3696 Lecture 3
Brunel University
 
PPTX
Introduction to Java
Ashita Agrawal
 
PDF
Programming in c by pkv
Pramod Vishwakarma
 
PDF
7. VARIABLEs presentation in java programming. Pdf
simukondasankananji8
 
PPT
java_lect_03-2.ppt
kavitamittal18
 
PPTX
Basic_Java_02.pptx
Kajal Kashyap
 
PPT
Md03 - part3
Rakesh Madugula
 
PPTX
UNIT – 2 Features of java- (Shilpa R).pptx
shilpar780389
 
UNIT 2 programming in java_operators.pptx
jijinamt
 
Fundamental programming structures in java
Shashwat Shriparv
 
Java q ref 2018
Christopher Akinlade
 
PCSTt11 overview of java
Archana Gopinath
 
Android webinar class_java_review
Edureka!
 
Lecture-02-JAVA, data type, token, variables.pptx
ChandrashekharSingh859453
 
Intro to Scala
manaswinimysore
 
C Programming - Refresher - Part II
Emertxe Information Technologies Pvt Ltd
 
Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) I...
GANESHBABUVelu
 
Java basics and java variables
Pushpendra Tyagi
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Sagar Verma
 
Ma3696 Lecture 3
Brunel University
 
Introduction to Java
Ashita Agrawal
 
Programming in c by pkv
Pramod Vishwakarma
 
7. VARIABLEs presentation in java programming. Pdf
simukondasankananji8
 
java_lect_03-2.ppt
kavitamittal18
 
Basic_Java_02.pptx
Kajal Kashyap
 
Md03 - part3
Rakesh Madugula
 
UNIT – 2 Features of java- (Shilpa R).pptx
shilpar780389
 

Recently uploaded (20)

PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Tally software_Introduction_Presentation
AditiBansal54083
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Ad

Java Basic Elements Lecture on Computer Science

  • 2. Outline • Starting with Java • Elements of Java • Variables • Constants • Escape Sequences
  • 3. Starting with Java public static void main(String args[]) means you can call this method from any where . keyword in java means you don't need object for this you can directly call it. means this method is not returning any thing. Name of the method String args[], which is actually an array of String type, and it's name is args here. args[] is for passing arguments to your program.
  • 4. Elements of Java • Java programs are a collection of 1. Whitespace 2. Identifiers 3. Comments 4. Literals 5. Operators 6. Separators, and 7. Keywords • Whitespace in Java is used to separate the tokens in a Java source file. • In Java, whitespace is a space, tab, or newline. • Java Literals are syntactic representations of Boolean, character, numeric, or string data. Literals provide a means of expressing specific values in your program. • An identifier is any name in a Java program. Identifiers are used to denote classes, methods, variables and labels. • An identifier may be any descriptive sequence of uppercase and lowercase • letters, numbers, or the underscore and dollar-sign characters. • Java is case-sensitive. • Valid: AvgTemp, count, a4, $test, this_is_ok • Invalid: 2count, high-temp, Not/ok • Comments are portions of the code ignored by the compiler which allow the user to make simple notes in the relevant areas of the source code. Comments come either in block form or as single lines. 1 2 3 4
  • 5. Elements of Java (Cont.) 5. Operators: Operators are used to perform operations on variables and values. Arithmetic Operator Name Description Example + Addition Adds together two values x + y - Subtraction Subtracts one value from another x - y * Multiplication Multiplies two values x * y / Division Divides one value by another x / y % Modulus Returns the division remainder x % y Increment and Decrement Operators Operator Name Description Example ++ Increment Increases the value of a variable by 1 ++x -- Decrement Decreases the value of a variable by 1 --x Assignment Operator Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 Bitwise Operators Operator Description Example Same as Result Decimal & AND - Sets each bit to 1 if both bits are 1 5 & 1 0101 & 0001 0001 1 | OR - Sets each bit to 1 if any of the two bits is 1 5 | 1 0101 | 0001 0101 5 ~ NOT - Inverts all the bits ~ 5 ~0101 1010 10 ^ XOR - Sets each bit to 1 if only one of the two bits is 1 5 ^ 1 0101 ^ 0001 0100 4 << Zero-fill left shift - Shift left by pushing zeroes in from the right and letting the leftmost bits fall off 9 << 1 1001 << 1 0010 2 >> Signed right shift - Shift right by pushing copies of the leftmost bit in from the left and letting the rightmost bits fall off 9 >> 1 1001 >> 1 1100 12 >>> Zero-fill right shift - Shift right by pushing zeroes in from the left and letting the rightmost bits fall off 9 >>> 1 1001 >>> 1 0100 4 Comparison Operators Operator Name Example == Equal to x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y Logical Operators Operator Name Description Example && Logical and Returns true if both statements are true x < 5 && x < 10 || Logical or Returns true if one of the statements is true x < 5 || x < 4 ! Logical not Reverse the result, returns false if the result is true !(x < 5 && x < 10)
  • 6. Elements of Java (Cont.) 5. Operators: Operators are used to perform operations on variables and values. – Unary • Require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a Boolean. – Ternary • The conditional operator or ternary operator ?: is shorthand for the if-then-else statement. The syntax of the conditional operator is: variable = Expression ? expression1 : expression2
  • 7. Elements of Java (Cont.) – Operator Precedence
  • 8. Elements of Java • Separators: Separators help define the structure of a program. Symbol Name Purpose () Parentheses Used to contain lists of parameters in method definition and invocation. Also used for defining precedence in expressions, containing expressions in control statements, and surrounding cast types. {} Braces Used to contain the values of automatically initialized arrays. Also used to define a block of code, for classes, methods, and local scopes. [] Brackets Used to declare array types. Also used when dereferencing array values. ; Semicolon Terminates statements. , Comma Separates consecutive identifiers in a variable declaration. Also used to chain statements together inside a for statement. . Full-stop Used to separate package names from subpackages and classes. Also used to separate a variable or method from a reference variable.
  • 9. Elements of Java • Keywords(Java Reserved Keywords): Java has a set of keywords that are reserved words that cannot be used as variables, methods, classes, or any other identifiers.
  • 10. Variables • Variable is a name of memory location. There are three types of variables in java: local, instance and static. • Types of Variable: There are three types of variables in java: – local variable: A variable which is declared inside the method is called local variable. – instance variable: Instance variables in Java are non-static variables which are defined in a class outside any method, constructor or a block. Each instantiated object of the class has a separate copy or instance of that variable. An instance variable belongs to a class. – static variable: A static variable is common to all the instances (or objects) of the class because it is a class level variable. In other words you can say that only a single copy of static variable is created and shared among all the instances of the class.
  • 11. Variables - Example • 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
  • 12. Constants • A constant is a variable whose value cannot change once it has been assigned. • Java doesn't have built-in support for constants. • Syntax: modifier final dataType variableName = value; //global constant • For a simple floating point value (a number with a fractional part) like Pi, it would look something like: private static final double PI = 3.1415926;
  • 13. Escape Sequences • A character preceded by a backslash () is an escape sequence and has a special meaning to the compiler. Sequence Name Meaning n New line Moves to beginning of next line b Backspace Backs up one character t Horizontal tab Moves to next tab position Tab spacing is every 8 columns starting with 1. (Columns 9, 17, 25, 33, 41, 49, 57, 65, 73 ...) Backslash Displays an actual backslash ' Single quote Displays an actual single quote " Double quote Displays an actual double quote
  • 14. References • https://www.edx.org/learn/java • https://www.infoworld.com/article/2076075/core-java-learn-java-from-the-grou nd-up.html • https://www.geeksforgeeks.org/java-how-to-start-learning-java/ • https://www.geeksforgeeks.org/jvm-works-jvm-architecture/ • https://beginnersbook.com/2013/05/jvm/ • https://www.iare.ac.in/sites/default/files/lecture_notes/IARE_OOPS_THROUGH_ JAVA_LECTURE_NOTES.pdf • https://lecturenotes.in/notes/23198-note-for-object-oriented-programming-usin g-java-oopj-by-debasish-pradhan?reading=true • https://www.softwaretestinghelp.com/java/java-introduction-installation/