0% found this document useful (0 votes)
16 views22 pages

Lecture 6

The document provides an overview of Java programming concepts, including variable scope, arrays, symbolic constants, and methods for outputting variable values. It explains the characteristics of arrays in Java, the declaration of symbolic constants using the 'final' keyword, and the differences between print() and println() methods. Additionally, it touches on operators and expressions in Java, concluding with a note that the content will continue.

Uploaded by

sneha chaudhari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views22 pages

Lecture 6

The document provides an overview of Java programming concepts, including variable scope, arrays, symbolic constants, and methods for outputting variable values. It explains the characteristics of arrays in Java, the declaration of symbolic constants using the 'final' keyword, and the differences between print() and println() methods. Additionally, it touches on operators and expressions in Java, concluding with a note that the content will continue.

Uploaded by

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

JAVA PROGRAMMING

Mrs. Sneha D. Patil


Assistant Professor
(E&C Department)
INDEX

 Scope of variables
 Arrays

 Symbolic constants

 Getting value of variables

 Standard default values

 Operators

 Expressions
SCOPE OF VARIABLES
 Scope of a variable is the part of the program
where the variable is accessible. Like C/C++, in
Java, all identifiers are lexically (or statically)
scoped, i.e.scope of a variable can be determined
at compile time and independent of function call
stack.
Java programs are organized in the form of
classes. Every class is part of some package. Java
scope rules can be covered under following
categories.
ARRAYS
 In Java, all arrays are dynamically allocated.
(discussed below)
 Arrays may be stored in contiguous memory
[consecutive memory locations].
 Since arrays are objects in Java, we can find their
length using the object property length. This is
different from C/C++, where we find length using size
of.
 A Java array variable can also be declared like other
variables with [] after the data type.
 The variables in the array are ordered, and each has
an index beginning with 0.
 Java array can also be used as a static field, a local
variable, or a method parameter.
TYPES OF ARRAY
SYMBOLIC CONSTANTS
 In Java, a symbolic constant is a named constant
value defined once and used throughout a
program. Symbolic constants are declared using
the final keyword.
 Which indicates that the value cannot be
changed once it is initialized.
 The naming convention for symbolic constants is
to use all capital letters with underscores
separating words.
SYNTAX OF SYMBOLIC CONSTANTS

 final data_type CONSTANT_NAME = value;


 final: The final keyword indicates that the value
of the constant cannot be changed once it is
initialized.
 data_type: The data type of the constant such as
int, double, boolean, or String.
 CONSTANT_NAME: The name of the constant
which should be written in all capital letters with
underscores separating words.
 value: The initial value of the constant must be
of the same data type as the constant.
 For eg. final double PI = 3.14159;
GETTING VALUE OF VARIABLES
 Many techniques are available in Java, a popular object-oriented
programming language, for delivering data to the console. Two
methods that are frequently used for this are print() and println().
Even while they might look the same, there are a few subtle
variations that could change how your output is shown. We will
examine the differences between print and println in Java in this
section.
 print():
 In Java, the print method displays text on the console without
shifting the cursor to the next line. It just prints the text while
keeping the pointer on the same line. The following is the syntax:
 System.out.print("Java, ");
 System.out.print("C");
 println():
 Conversely, println() represents "print line." This function inserts a
newline character (n) after printing the text, making it comparable to
print() function. The pointer is advanced to the beginning of the next
line. The following is the syntax:
 System.out.println("Good, ");
 System.out.println("Morning");
OPERATORS
ASSIGNMENT OPERATORS
RELATIONAL OPERATORS
BITWISE OPERATORS
SHIFT OPERATORS IN JAVA
EXPRESSIONS
 In expression in Java is a construct that evaluates to a single
value. This value can be a number, a string, an object, or any
other data type depending on the components of the
expression. Expressions can include variables, literals, method
calls, and operators.
 For example:
 int marks; marks = 90;
TYPES OF EXPRESSION IN JAVA
TO BE CONTINUE....

You might also like