2. What is Java ?
• Java
- Java is not just a programming language but it is a complete
platform for object oriented programming.
• JRE
- Java standard class libraries which provide Application
Programming Interface and JVM together form JRE (Java Runtime
Environment).
• JDK
- JDK (Java development kit) provides all the needed support for
software development in Java.
3. Java Virtual Machine (JVM)
• Runs the Byte Code.
• Makes Java platform independent.
• Handles Memory Management.
4. Byte Code
• Java bytecode is the form of instructions that
the Java Virtual Machine executes
• A Java programmer does not need to be aware of or
understand Java bytecode at all.
• The model of computation of Java bytecode is that
of a stack oriented programming language.
5. Garbage Collection
• The programmer is not responsible for memory
management in Java.
• The memory area in JVM where objects are created
is called Heap.
• The memory is freed during runtime by a special
thread called Garbage Collector.
• The GC looks for objects which are no longer
needed by the program and destroys them.
10. How Java works ?
• Java compilers convert your code from human readable to
something called “bytecode” in the Java world.
• “Bytecode” is interpreted by a JVM, which operates much
like a physical CPU to actually execute the compiled code.
• Just-in-time (JIT) compiler is a program that turns
Java bytecode into instructions that can be sent directly to
the processor.
13. Data Types in Java
• Data types define the nature of a value
• We need different data-types to handle real-world information
Name Size (in bits) Range
long 64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int 32 –2,147,483,648 to 2,147,483,647
Short 16 –32,768 to 32,767
byte 8 –128 to 127
double 64 4.9e–324 to 1.8e+308
float 32 1.4e–045 to 3.4e+038
char 16 0 to 65,536
boolean ??
true/false
14. Primitive Types and Variables
• boolean, char, byte, short, int, long, float, double etc.
• These basic (or primitive) types are the only types that are
not objects (due to performance issues).
• This means that you don’t use the new operator to create
a primitive variable.
15. Naming Convention of Variables
• Can start with a letter, an underscore(_), or a dollar sign ($)
• Cannot start with a number.
long _LongNumber = 9999999;
String firstName = “John”;
float $Val = 2.3f;
int i, index = 2;
double gamma = 1.2;
boolean value2 = false;
16. Statements & Blocks
• A simple statement is a command terminated by a semi-colon:
name = “Fred”;
• A block is a compound statement enclosed in curly brackets:
{
name1 = “Fred”; name2 = “Bill”;
}
• Blocks may contain other blocks.
17. Flow of Control
• Java executes one statement after the other in the
order they are written.
• Many Java statements are flow control statements:
Alternation:
if, if else, switch
19. If else– Syntax
if ( <condition> )
{
// Execute these statements if <condition> is TRUE
}
20. If else– Syntax
if ( <condition> )
{
// Execute these statements if <condition> is TRUE
}
else
{
// Execute these statements if < condition> is FALSE
}
21. If else– Syntax
if ( <condition1> )
{
// Execute these statements if <condition1> is TRUE
} else if ( <condition2> )
{
// Execute these statements if <condition2> is TRUE
} else {
// if both <condition1> and <condition2> is FALSE
}
23. Operators
• Provide a way to perform different operations on
variables
• Categories of Java Operators
Assignment Operators =
Arithmetic Operators - + * / %
Relational Operators > < >= <= == !=
Logical Operators && || & | ^
Unary Operators + - ++ -- !
24. Assignment and Arithmetic Operators
• Used to assign a value to a variable
• Syntax
– <variable> = <expression>
Assignment Operator =
• Java provides eight Arithmetic operators:
– for addition, subtraction, multiplication, division, modulo (or
remainder), increment (or add 1), decrement (or subtract 1),
and negation.
25. Relational Operators
• Used to compare two values.
• Binary operators, and their operands are numeric
expressions.
Relational Operators > < >= <= == !=
26. Logical Operators
• Return a true or false value based on the state of
the variables
• There are six logical operators
Conditional AND Conditional OR AND OR NOT Exclusive OR
Logical Operators && || & | ! ^
27. Static versus Non-static Variables
• Static variables are shared across all the objects of a
class
– There is only one copy
• Non-Static variables are not shared
– There is a separate copy for each individual live object.
• Static variables cannot be declared within a
method.
Not just a programming language but a complete platformThe Programming language Java standard class libraries which provide Application Programming Interface and JVM together form JRE (Java Runtime Environment)JDK (Java development kit) provides all the needed support for software development in Java.
Need a diagram to show garbage collection
Need a diagram to show garbage collection
Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. “Bytecode” is interpreted by a JVM, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Performance - Java performance in generally second only to C/C++ in common language performance comparisons. In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed
Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. “Bytecode” is interpreted by a JVM, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Performance - Java performance in generally second only to C/C++ in common language performance comparisons. In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed
Adv. Question : What is the range of primitive data types ?Initalization:If no value is assigned prior to use, then the compiler will give an errorJava sets primitive variables to zero or false in the case of a boolean variableAll object references are initially set to null
Java provides six relational operators:greater than (>), less than (<), greater than or equal (>=), less than or equal (<=), equal (==), and not equal (!=).
Is it really needed to define all the types of operators.It will be better to show their differences through a program.