0% found this document useful (0 votes)
31 views13 pages

2.2 Code Blocks - Lexical Issues

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)
31 views13 pages

2.2 Code Blocks - Lexical Issues

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/ 13

Code Blocks and

Lexical

By Upekha Vandebona
Code Blocks
Java allows two or more statements
to be grouped into blocks of code,
also called code blocks.
This is done by enclosing the
statements between opening and
closing curly braces.
Here, if x is less than y, then both statements inside
the block will be executed.

Thus, the two statements inside the block form a


logical unit, and one statement cannot execute
without the other also executing.
The target of the for loop is a block of code
and not just a single statement.
Thus, each time the loop iterates, the three
statements inside the block will be
executed.
Whitespace
 Java is a free-form language.
 This means that you do not need to follow any
special indentation rules.
 Programs could have been written all on one
line or in any other strange way you felt like
typing it, as long as there was at least one
whitespace character between each token that
was not already delineated by an operator or
separator.
 In Java, whitespace is a space, tab, or newline.
Identifiers
Identifiers are used to name things,
such as classes, variables, and
methods.
Java is case-sensitive, so ‘VALUE’ is
a different identifier than ‘Value’.
Identifier Naming Rules
 Itmust start with a letter, underscore (_)
or currency sign ($). You can’t start a
name with a number.
 Name can be anything you like, but
except Java’s reserved words.
 Without spaces, hypen, asterisk and
slash etc.
 Invalid identifier names include these:
 2ndNumbers, *Mark, values-given, :mark,
val#, .marks, marks/value
Legal Identifiers
_a
$c
_______2_w
_$
 This_is_a_very_detailed_name_for_an_identifier
Separators
The most commonly used separator
in Java is the semicolon. As you
have seen, it is used to terminate
statements.
As a standard practice; for the readability (Naming
Convention)
Class name: Start with uppercase letter
Variable and method name: Start with lowercase letter
Use camel case rather underscore
Thank You!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy