JAVA ~ myTechpartner Join Me On Facebook
Join Me On Facebook

Blogroll

Monday, 8 April 2013

JAVA

Variables
• Variables may be tagged as constants (final
keyword).
• Variables may be initialized at creation time
– final variables must be initialized at creation time
• Objects are variables in Java and must be
dynamically allocated with the new keyword.
– E.g., a = new ClassA();
• Objects are freed by assigning them to null, or when
they go out of scope (automatic garbage collection).
– E.g., a = null;
int n = 1;
char ch = ‘A’;
String s = “Hello”;
Long L = new Long(100000);
boolean done = false;
final double pi = 3.14159265358979323846;
Employee joe = new Employee();
char [] a = new char[3];
Vector v = new Vector();
Pointers & References Variables
• Java does not support pointers.
• All variables are passed by value except
objects.
• Java classes either:
– Reference an object (new keyword)
– Alias an object (assign to another object)

Expressions
• Java supports many ways to construct
expressions (in precedence order):
– ++,-- Auto increment/decrement
– +,- Unary plus/minus
– *,/ Multiplication/division
– % Modulus
– +,- Addition/subtraction
Assignment Operators
• Assignment may be simple
– x = y
• Or fancy with the following operators:
– *=, /=
– %=
– +=, -=
– &= (bitwise AND)
– |= (bitwise OR)
– ^= (bitwise exclusive OR)
Conditional Logic
• Conditional logic in Java is performed with the
if statement.
• Unlike C++ a logic expression does not
evaluate to 0 (FALSE) and non-0 (TRUE), it
evaluates to either true or false
• true, false are values of the boolean data
type.
• Building compound conditional statements
– && (And), || (Or), ! (Not), <, >, ==, !=, <=, >=, etc.

0 comments:

Post a Comment

 

Contributors

Online Marketing

Do you Like this Article?

rss twitter facebook