SlideShare a Scribd company logo
What is Java Technology?
Java technology is:
A programming language
●
–
A development environment
An application environment
–
–
It is similar in syntax to C++.
It is used for developing both applets
●
and applications.●
Thanks to its scalable nature, Java has emerged as the most preferred language
in Web and Mobile application development
Primary Goals of the
Java Technology
Provides an easy-to-use language by:
Avoiding many pitfalls of other languages
●
–
Being object-oriented
Enabling users to create streamlined and clear code
–
–
Provides an interpreted environment for:Provides an interpreted environment for:
Improved speed of development
●
–
Code portability–
Primary Goals of the
Java Technology
Enables users to run more than one thread of activity
Loads classes dynamically; that is, at the time they are actually
needed
Supports changing programs dynamically during runtime by loading
classes from disparate sources
●
●
●
classes from disparate sources
Furnishes better security●
Primary Goals of the
Java Technology
The following features fulfill these goals:
The Java Virtual Machine (JVMTM) 1
Garbage collection
The Java Runtime Environment (JRE)
●
●
●
●
The Java Virtual Machine
a specification that provides runtime environment in which java byte
code can be executed.
Reads compiled byte codes that are platform-independent
JVMs are available for many hardware and software platforms.
JVM is platform dependent because configuration of each OS differs.
The Java Virtual Machine(JVM) make the code run in any platform, thereby
making it platform independent
JVM is platform dependent because configuration of each OS differs.
But, Java is platform independent
Garbage Collection
Allocated memory that is no longer needed should be deallocated.
In other languages, deallocation is the programmer’s responsibility.
The Java programming language provides a system-level thread to
track memory allocation.
●
●
●
Garbage Collection
Garbage collection has the following characteristics:
Checks for and frees memory no longer needed
Is done automatically
Can vary dramatically across JVM implementations
●
●
●
Java Presentation For Syntax
The Java Runtime
Environment
JVM Tasks
The JVM performs
Loads code
Verifies code
Executes code
three main tasks:
●
●
●
The Class Loader
Loads all classes necessary for the execution of a program
Maintains classes of the local file system in separate namespaces
●
●
The Bytecode Verifier
The
The
The
The
code
code
code
adheres to the JVM specification.
does not violate system integrity.
causes no operand stack overflows or underflows.
●
●
●
parameter types for all operational code are●
correct.
No illegal data conversions (the conversion of integers to pointers)
have occurred.
●
Simple
Object-Oriented
Platform independent
Features of Java
Secured
Robust
Architecture neutral
Multithreaded
Distributed
Simple Java Application
The TestGreeting.java Application
//
// Sample "Hello World" application
//
public class TestGreeting{public class TestGreeting{
public static void main (String[]
args)
Greeting hello = new Greeting();
hello.greet();
}
}
{
A Simple Java Application
The Greeting.java Class
public class Greeting {
public void greet() {
System.out.println(“hi”);
}
}
Compiling and Running
the TestGreeting Program
Compile TestGreeting.java:
javac TestGreeting.java
The Greeting.java is compiled
●
automatically.●
Run the application by using the following command:●
java TestGreeting
Locate common compile and runtime errors.●
Java Technology Runtime
Environment
Classes as Blueprints for
Objects
In Java technology, classes support three key features of object-
oriented programming (OOP):
Encapsulation
●
–
Inheritance
Polymorphism
–
– Polymorphism–
Declaring Java Technology
Classes
Basic syntax of a Java class:
<modifier>* class <class_name>
<attribute_declaration>*
<constructor_declaration>*
●
{
<method_declaration>*
}
Declaring Java Technology
Classes
public class Vehicle {
private double maxLoad;
public void setMaxLoad(double
maxLoad = value;
value) {
}
}
Declaring Attributes
Basic syntax of an attribute:●
<modifier>* <type>
<name>
[ = <initial_value>];
Examples:
public class Foo {
●
public class Foo {
private
private
private
}
int x;
float y = 10000.0F;
String name = "Bates Motel";
Declaring Methods
Basic syntax of a method:
<modifier>* <return_type>
<statement>*
}
<name> ( <argument>* ) {
Declaring Methods
public class Dog {
private int weight;
public int getWeight() {
return weight;
}}
public void setWeight(int
if ( newWeight > 0 ) {
weight = newWeight;
}
}
newWeight) {
Accessing Object Members
The dot notation is: <object>.<member>
This is used to access object members, including
methods.
Examples of dot notation are:
d.setWeight(42);
●
attributes and●
●
d.setWeight(42);
d.weight = 42; // only permissible if weight is public
Declaring Constructors
Basic syntax of a constructor:●
[<modifier>] <class_name>
<statement>*
}
Example:
( <argument>* ) {
●
public class Dog {
private int weight;
public Dog() {
weight = 42;
}
}
The Default Constructor
There is always at least one constructor in every class.
If the writer does not supply any constructors, the default
constructor is present automatically:
●
●
The default constructor takes no arguments
The default constructor body is empty
–
– The default constructor body is empty–
The default enables you to create object instances with new
Xxx()without having to write a constructor.
●
Source File Layout
Basic syntax of a Java source file is:
[<package_declaration>]
<import_declaration>*
<class_declaration>+
●
Source File Layout
package shipping.reports;
import
import
import
shipping.domain.*;
java.util.List;
java.io.*;import java.io.*;
public class VehicleCapacityReport
private List vehicles;
{
public void generateReport(Writer output)
{...}
}
Software Packages
Packages help manage large software systems.
Packages can contain classes and sub-packages.
●
●
The package Statement
Basic syntax of the package statement is: package
<top_pkg_name>[.<sub_pkg_name>]*;
●
–
Examples of the statement are:
package shipping.gui.reportscreens;
●
–
Specify the package declaration at the beginning of the source file.Specify the package declaration at the beginning of
Only one package declaration per source file.
the source file.●
●
If no package is declared, then the class is placed into the default
package.
Package names must be hierarchical and separated by dots.
●
●
The import Statement
Basic syntax of the import statement is:
Import<pkg_name>[.<sub_pkg_name>]*.<class_name>;
OR
import<pkg_name>[.<sub_pkg_name>]*.*;
●
Examples of the statement are:●
import
import
import
java.util.List;
java.io.*;
shipping.gui.reportscreens.*;
The import Statement
The import statement does the following:
Precedes all class declarations
Tells the compiler where to find classes
●
●
Comments
The three permissible
styles
program are:
// comment on one line
/* comment on one
of comment in a Java technology
/* comment on one
* or more lines
*/
/** documentation
comment
* can also span one or more
lines
*/
Semicolons, Blocks, and
White Space
A statement is one or more lines of code terminated by a semicolon (;):●
totals = a +
+ d + e + f;
A block is a
and closing
b + c
collection
braces:
of statements bound by opening●
and closing
{
x = y + 1;
y = x + 1;
}
braces:
Semicolons, Blocks, and
White Space
A class definition uses
public class MyDate {
a special block:
private
private
int
int
day;
month;
private
}
int year;
Semicolons, Blocks, and
White Space
You can nest block statements:
while ( i < large
a = a + i;
// nested block
if ( a == max ) {
) {
if ( a == max ) {
b = b + a;
a = 0;
}
i = i + 1;
}
Semicolons, Blocks, and
White Space
Any amount of white
For example:
{int x;x=23*54;}
is equivalent to:
space is permitted in a Java:
{
int x;
x = 23 * 54;
}
Identifiers
Identifiers have the following characteristics:
Are names given to a variable, class, or method
Can start with a Unicode letter, underscore (_),
or
●
dollar sign ($)●
Are case-sensitive
Examples:
and have no maximum length●
● Examples:
identifier
userName
user_name
_sys_var1
$change
●
Keywords
abstract continue for new switch●
assert default goto package
this
synchronized●
boolean do if private●
break
byte
double implements
else import public
protected
throws
throw●
● byte
case
catch
char
class
const
else import public throws●
enum instanceof return transient●
extends int short try●
final interface static void●
finally long strictfp volatile
while
●
floatnative super●
Primitive Types
The Java programming
Logical – boolean
Textual – char
language defines eight primitive types:
●
●
Integral – byte, short, int, and long●
Floating – double and float●
Java Reference Types
In Java technology, beyond primitive types all others are reference
types.
A reference variable contains a handle to an object.
●
●
Car c = new Car();
C is a reference variable
–
– C is a reference variable–
Constructing and
Initializing Objects
Calling new Xyz() performs the following actions:
a. Memory is allocated for the object.
b. Explicit attribute initialization is
performed.
c. A constructor is executed.
●
c. A constructor is executed.
d. The object reference is returned by the
new operator.
The reference to the object is assigned to a variable.
An example is:
MyDate my_birth = new MyDate(22, 7, 1964);
●
●
Memory Allocation and
Layout
A declaration allocates storage only for a reference:
MyDate my_birth = new MyDate(22, 7, 1964);
●
Use the new operator to allocate space for MyDate:
MyDate my_birth = new MyDate(22, 7, 1964);
●
Executing the Constructor
MyDate my_birth = new MyDate(22, 7, 1964);●
Assigning a Variable
Assign the newly created object to the reference variable as
follows:
MyDate my_birth = new MyDate(22, 7, 1964);
●
Assigning References
Two variables refer to a
int x = 7;
int y = x;
single object:
MyDate s = new MyDate(22, 7, 1964);
MyDate t = s;MyDate t = s;
Java Programming Language
Coding Conventions
Packages:
com.example.domain;
●
–
Classes, interfaces, and
SavingsAccount
enum types:●
–
Methods:●
Methods:
GetAccount()–
Variables:
currentCustomer
●
–
Constants:
HEAD_COUNT
●
–
Java Programming Language
Coding Conventions
Control structures:●
if ( condition
statement1;
} else {
) {
statement2;
}
Spacing:●
Use one statement per line.–
Use two or four spaces for indentation.–
Java Programming Language
Coding Conventions
Comments:
Use // to comment inline code.
●
–
Use /** documentation */ for class members.–
Variables and Scope
Local variables are:
Variables that are defined inside a method and are called local,
automatic, temporary, or stack variables
Variables that are created when the method is executed are
destroyed when the method is exited
●
●
destroyed when the method is exited
Variable initialization comprises the following:
Local variables require explicit initialization.
Instance variables are initialized automatically.
●
●
Variable Initialization
Initialization Before
Use Principle
The compiler
before used.
will verify that local variables have been initialized
int
int
int
x=8;
y;
z;int z;
z=x+y;
Operator Precedence
Logical Operators
The boolean operators
! – NOT
are:●
–
| – OR
& – AND
^ – XOR
–
–
^ – XOR–
The short-circuit
&& – AND
boolean operators are:●
–
|| – OR–
Bitwise Logical Operators
The integer bitwise operators
~ – Complement
are:●
–
^ – XOR
& – AND
| – OR
–
–
| – OR–
Bitwise Logical Operators:
Example
Right-Shift Operators >>
and >>>
Arithmetic or signed right
shift
Examples are:
( >> ) operator:●
●
128 >> 1 returns 128/2 1 = 64
256 >> 4 returns 256/2 4 = 16
-256 >> 4 returns -256/2 4 = -
–
–
-256 >> 4 returns -256/2 4 = -
16
–
The sign bit is copied during the shift.
Logical or unsigned right-shift ( >>> )
operator: This operator is used for bit
patterns.
●
●
–
The sign bit is not copied during the
shift.
–
Left-Shift Operator <<
Left-shift ( << ) operator works as follows:
128 << 1 returns 128 * 2 1 = 256
●
–
16 << 2 returns 16 * 2 2 = 64–
Shift Operator Examples
·101010101010101010101
0101010101010101010101
0101010101110111011101
13
57
)
)
5
s>
>
·l1l1l1l1l1l1l1l1l1l1l
1l1l1l1l1l1l1l1l1l1l1l
1l1l1l1l1lol1lol1lol1I
-
135
7
~1
~s,
s ·lololololol1l1l1l1l1l1
l1l1l1l1l1l1l1l1l1l1l1l
1l1l1l1lol1lol1lol1I
>>
>
1
3
"
5
·1°1°1°1°1°1°1°1°1°1°
1°1°1°1°1°1°111°11lol
1lolol1l1lol11ol01°1°1
°1
(
(
>
String Concatenation With +
The + operator works as follows:
Performs String concatenation
●
–
Produces a new String:–
String salutation = "Dr.";String
String
String
salutation = "Dr.";
name = "Pete" + " " + "Seymour";
title = salutation + " " + name;
Casting
If information might be lost in an assignment, the programmer
must
the assignment with a cast.
confirm●
The assignment between long and int requires
an
long bigValue = 99L;
explicit cast.●
int squashed = bigValue;// Wrong, needs a castint
int
squashed
squashed
=
=
bigValue;// Wrong, needs a cast
(int) bigValue; // OK
int
int
int
squashed
squashed
squashed
=
=
=
99L;// Wrong, needs a cast
(int) 99L;// OK, but...
99; // default integer literal
Promotion and Casting
of Expressions
Variables are promoted automatically to a longer form (such as int
to long).
●
Expression is assignment-compatible if the variable
as large
long bigval = 6;// 6 is an int type, OK
type is at least●
long bigval = 6;// 6 is an int type, OK
int smallval = 99L; // 99L is a long, illegal
double z = 12.414F;// 12.414F is float, OK
float z1 = 12.414; // 12.414 is double, illegal
Simple if, else Statements
The if statement syntax:
if ( <boolean_expression> )
<statement_or_block>
Example:
if ( x < 10 )
●
●
if ( x < 10 )
System.out.println("Are
or (recommended): if (
x < 10 ) {
System.out.println("Are
}
you finished yet?");
you finished yet?");
Complex if, else Statements
The if-else statement syntax:
if ( <boolean_expression> )
<statement_or_block>
else
<statement_or_block>
●
Example:
if ( x < 10 ) {
●
System.out.println("Are
} else {
you finished yet?");
System.out.println("Keep working...");
}
Complex if, else Statements
The if-else-if statement syntax:
if ( <boolean_expression> )
<statement_or_block>
else if ( <boolean_expression> )
●
<statement_or_block>
if-else-if statement: Example
Example:
int count = getCount(); // a method
defined if (count < 0) {
●
in the class
System.out.println("Error: count value is
negative.");
} else if (count > getMaxCount()) {
System.out.println("Error: count value is too
big.");
} else {
System.out.println("There will be " + count
+
" people for lunch today.");
}
Switch Statements
The switch statement syntax:
switch ( <expression> ) {
case <constant1>:
<statement_or_block>*
[break;]
case <constant2>:case <constant2>:
<statement_or_block>*
[break;]
default:
<statement_or_block>*
[break;]
}
Switch Statement Example
String carModel = ”STANDARD”;
switch ( carModel ) { case
DELUXE:
System.out.println(“DELUXE”);
break;
case STANDARD:
System.out.println(“Standard”);
break;
default:
System.out.println(“Default”);
}
Switch Statements
Without the break statements, the execution falls through each
subsequent case clause.
●
For Loop
The for loop syntax:
for ( <init_expr>; <test_expr>; <alter_expr> )
<statement_or_block>
●
For Loop Example
for ( int i = 0; i < 10; i++ )
System.out.println(i + " squared
or (recommended):
for ( int i = 0; i < 10; i++ ) {
is " + (i*i));
System.out.println(i + " squared
}
is " + (i*i));
While Loop
The while loop syntax:
while ( <test_expr> )
<statement_or_block>
While Loop Example
Example:
int i = 0;
while ( i < 10 ) {
System.out.println(i + " squared is " + (i*i));
i++;
}
The do/while Loop
The do/while loop syntax:
do
<statement_or_block>
while ( <test_expr> );
●
The do/while
Example
Loop:
Example:
int i = 0; do {
System.out.println(i
i++;
●
+ " squared is " + (i*i));
} while ( i < 10 );
Special Loop Flow
Control
The
The
The
break [<label>]; command
continue [<label>]; command
<label> : <statement> command, where <statement> should be
●
●
●
a loop
The break Statement
do {
statement;
if ( condition
break;
) {
}
statement;
} while ( test_expr );
The continue Statement
do {
statement;
if ( condition
continue;
) {
}
statement;
} while ( test_expr );
Using break
with Labels
Statements
outer:
do {
statement1
;
do {
statement2statement2
;
if ( condition ) {
break outer;
}
statement3;
} while ( test_expr
);
statement4;
} while ( test_expr
);
Using continue
with Labels
Statements
test:
do {
statement1;
do {
statement2;
if ( condition ) {if ( condition ) {
continue test;
}
statement3;
} while ( test_expr
statement4;
} while ( test_expr
);
);
Declaring Arrays
Group data objects of the same type.●
Declare arrays
char s[];
int p[];
of primitive or class types:●
char[] s;
int[] p;
Create space for a reference.●
An array is an object; it is created with new.●
Creating Arrays
Use the new keyword to create an arrayobject.
For example, a primitive (char) array:
public char[] createArray()
char[] s;
{
s = new char[26];
for ( int i=0; i<26; i++ ) {
s[i] = (char) (’A’ + i);
}
return s;
}
Creating an Array of
Character Primitives
Creating Reference Arrays
Another example, an object
array:
public Point[] createArray()
Point[] p;
p = new Point[10];
for ( int i=0; i<10; i++ ) {
{
for ( int i=0; i<10; i++ ) {
p[i] = new Point(i, i+1);
}
return p;
}
Initializing Arrays
Initialize an array element.
Create an array with initial
String[] names;
names = new String[3];
●
values.●
names[0]
names[1]
names[2]
=
=
=
"Georgianna";
"Jen";
"Simon";
Multidimensional Arrays
Arrays of arrays:
int[][] twoDim = new int[4][];
twoDim[0] = new int[5];
twoDim[1] = new int[5];
●
int[][] twoDim = new int[][4]; // illegal
Array of four arrays of five integers each:
int[][] twoDim = new int[4][5];
●
Array Bounds
All array subscripts begin at 0:
public void printElements(int[] list) {
for (int i = 0; i < list.length; i++) {
System.out.println(list[i]);
}
}
Using the Enhanced
for Loop
Java 2 Platform, Standard Edition (J2SETM) version 5.0 introduced●
an enhanced for loop for iterating over
public void printElements(int[] list) {
for ( int element : list ) {
System.out.println(element);
arrays:
System.out.println(element);
}
}
Array Resizing
You
You
cannot resize an array.
can use the same reference variable to refer to an entirely new
●
●
array, such as:
int[] myArray = new int[6];
myArray = new int[10];myArray = new int[10];
Copying Arrays
The System.arraycopy() method to copy arrays
//original array
int[] myArray = { 1, 2, 3, 4, 5, 6 };
// new larger array
is:
int[] hold = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
// copy all of the myArray array to the hold
// array, starting with the 0th index
System.arraycopy(myArray, 0, hold, 0, myArray.length);

More Related Content

PDF
Introduction to java (revised)
Sujit Majety
 
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
PPT
Java basic
Sonam Sharma
 
PDF
Basic Java Programming
Math-Circle
 
PPTX
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
PDF
Introduction to Java Programming
Ravi Kant Sahu
 
PPT
Java Programming for Designers
R. Sosa
 
PPTX
Introduction to java
Sandeep Rawat
 
Introduction to java (revised)
Sujit Majety
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Java basic
Sonam Sharma
 
Basic Java Programming
Math-Circle
 
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
Introduction to Java Programming
Ravi Kant Sahu
 
Java Programming for Designers
R. Sosa
 
Introduction to java
Sandeep Rawat
 

What's hot (20)

PDF
Introduction to Java Programming Language
jaimefrozr
 
PPT
Core java concepts
Ram132
 
PDF
Introduction to Java
Professional Guru
 
PPTX
Introduction to java
Saba Ameer
 
PPTX
Java Programming
Elizabeth alexander
 
PPT
Java platform
BG Java EE Course
 
PPTX
Java
proximotechsoft
 
PPTX
Java features
Prashant Gajendra
 
PPT
Java features
Madishetty Prathibha
 
PPT
Core java slides
Abhilash Nair
 
PPTX
core java
Roushan Sinha
 
PPTX
Control flow statements in java
yugandhar vadlamudi
 
PDF
Introduction to basics of java
vinay arora
 
PPTX
Introduction to Basic Java Versions and their features
Akash Badone
 
PPTX
Core java
Ravi varma
 
PDF
Learn Java with Dr. Rifat Shahriyar
Abir Mohammad
 
PPTX
Advance Java Topics (J2EE)
slire
 
PPT
Oops ppt
abhayjuneja
 
PDF
Java Programming
Anjan Mahanta
 
Introduction to Java Programming Language
jaimefrozr
 
Core java concepts
Ram132
 
Introduction to Java
Professional Guru
 
Introduction to java
Saba Ameer
 
Java Programming
Elizabeth alexander
 
Java platform
BG Java EE Course
 
Java features
Prashant Gajendra
 
Java features
Madishetty Prathibha
 
Core java slides
Abhilash Nair
 
core java
Roushan Sinha
 
Control flow statements in java
yugandhar vadlamudi
 
Introduction to basics of java
vinay arora
 
Introduction to Basic Java Versions and their features
Akash Badone
 
Core java
Ravi varma
 
Learn Java with Dr. Rifat Shahriyar
Abir Mohammad
 
Advance Java Topics (J2EE)
slire
 
Oops ppt
abhayjuneja
 
Java Programming
Anjan Mahanta
 
Ad

Similar to Java Presentation For Syntax (20)

PDF
Core Java Tutorial
eMexo Technologies
 
PPTX
Java For beginners and CSIT and IT students
Partnered Health
 
PDF
Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
WebStackAcademy
 
PPTX
Unit-1_GHD.pptxguguigihihihihihihoihihhi
40NehaPagariya
 
PDF
Core Java Programming Language (JSE) : Chapter I - Getting Started
WebStackAcademy
 
PPT
Jacarashed-1746968053-300050282-Java.ppt
DilipDas70
 
PPT
Java Tutorial 1
Tushar Desarda
 
PPT
What is Java Technology (An introduction with comparision of .net coding)
Shaharyar khan
 
PDF
Building an Extensible, Resumable DSL on Top of Apache Groovy
jgcloudbees
 
PDF
The State of the Veil Framework
VeilFramework
 
PDF
NDK Primer (Wearable DevCon 2014)
Ron Munitz
 
PPTX
Java Notes
Sreedhar Chowdam
 
PPTX
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
PPTX
2. Introduction to Java for engineering stud
vyshukodumuri
 
PPTX
Objective-c for Java Developers
Muhammad Abdullah
 
PPTX
brief introduction to core java programming.pptx
ansariparveen06
 
PPTX
Java subject for the degree BCA students
NithinKuditinamaggi
 
PDF
Java Enterprise Edition
Francesco Nolano
 
ODP
Spring 4 final xtr_presentation
sourabh aggarwal
 
PDF
Adv java unit 1 M.Sc CS.pdf
KALAISELVI P
 
Core Java Tutorial
eMexo Technologies
 
Java For beginners and CSIT and IT students
Partnered Health
 
Core Java Programming Language (JSE) : Chapter II - Object Oriented Programming.
WebStackAcademy
 
Unit-1_GHD.pptxguguigihihihihihihoihihhi
40NehaPagariya
 
Core Java Programming Language (JSE) : Chapter I - Getting Started
WebStackAcademy
 
Jacarashed-1746968053-300050282-Java.ppt
DilipDas70
 
Java Tutorial 1
Tushar Desarda
 
What is Java Technology (An introduction with comparision of .net coding)
Shaharyar khan
 
Building an Extensible, Resumable DSL on Top of Apache Groovy
jgcloudbees
 
The State of the Veil Framework
VeilFramework
 
NDK Primer (Wearable DevCon 2014)
Ron Munitz
 
Java Notes
Sreedhar Chowdam
 
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
2. Introduction to Java for engineering stud
vyshukodumuri
 
Objective-c for Java Developers
Muhammad Abdullah
 
brief introduction to core java programming.pptx
ansariparveen06
 
Java subject for the degree BCA students
NithinKuditinamaggi
 
Java Enterprise Edition
Francesco Nolano
 
Spring 4 final xtr_presentation
sourabh aggarwal
 
Adv java unit 1 M.Sc CS.pdf
KALAISELVI P
 
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
The Evolution of KM Roles (Presented at Knowledge Summit Dublin 2025)
Enterprise Knowledge
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
A Day in the Life of Location Data - Turning Where into How.pdf
Precisely
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 

Java Presentation For Syntax

  • 1. What is Java Technology? Java technology is: A programming language ● – A development environment An application environment – – It is similar in syntax to C++. It is used for developing both applets ● and applications.● Thanks to its scalable nature, Java has emerged as the most preferred language in Web and Mobile application development
  • 2. Primary Goals of the Java Technology Provides an easy-to-use language by: Avoiding many pitfalls of other languages ● – Being object-oriented Enabling users to create streamlined and clear code – – Provides an interpreted environment for:Provides an interpreted environment for: Improved speed of development ● – Code portability–
  • 3. Primary Goals of the Java Technology Enables users to run more than one thread of activity Loads classes dynamically; that is, at the time they are actually needed Supports changing programs dynamically during runtime by loading classes from disparate sources ● ● ● classes from disparate sources Furnishes better security●
  • 4. Primary Goals of the Java Technology The following features fulfill these goals: The Java Virtual Machine (JVMTM) 1 Garbage collection The Java Runtime Environment (JRE) ● ● ● ●
  • 5. The Java Virtual Machine a specification that provides runtime environment in which java byte code can be executed. Reads compiled byte codes that are platform-independent JVMs are available for many hardware and software platforms. JVM is platform dependent because configuration of each OS differs. The Java Virtual Machine(JVM) make the code run in any platform, thereby making it platform independent JVM is platform dependent because configuration of each OS differs. But, Java is platform independent
  • 6. Garbage Collection Allocated memory that is no longer needed should be deallocated. In other languages, deallocation is the programmer’s responsibility. The Java programming language provides a system-level thread to track memory allocation. ● ● ●
  • 7. Garbage Collection Garbage collection has the following characteristics: Checks for and frees memory no longer needed Is done automatically Can vary dramatically across JVM implementations ● ● ●
  • 10. JVM Tasks The JVM performs Loads code Verifies code Executes code three main tasks: ● ● ●
  • 11. The Class Loader Loads all classes necessary for the execution of a program Maintains classes of the local file system in separate namespaces ● ●
  • 12. The Bytecode Verifier The The The The code code code adheres to the JVM specification. does not violate system integrity. causes no operand stack overflows or underflows. ● ● ● parameter types for all operational code are● correct. No illegal data conversions (the conversion of integers to pointers) have occurred. ●
  • 13. Simple Object-Oriented Platform independent Features of Java Secured Robust Architecture neutral Multithreaded Distributed
  • 14. Simple Java Application The TestGreeting.java Application // // Sample "Hello World" application // public class TestGreeting{public class TestGreeting{ public static void main (String[] args) Greeting hello = new Greeting(); hello.greet(); } } {
  • 15. A Simple Java Application The Greeting.java Class public class Greeting { public void greet() { System.out.println(“hi”); } }
  • 16. Compiling and Running the TestGreeting Program Compile TestGreeting.java: javac TestGreeting.java The Greeting.java is compiled ● automatically.● Run the application by using the following command:● java TestGreeting Locate common compile and runtime errors.●
  • 18. Classes as Blueprints for Objects In Java technology, classes support three key features of object- oriented programming (OOP): Encapsulation ● – Inheritance Polymorphism – – Polymorphism–
  • 19. Declaring Java Technology Classes Basic syntax of a Java class: <modifier>* class <class_name> <attribute_declaration>* <constructor_declaration>* ● { <method_declaration>* }
  • 20. Declaring Java Technology Classes public class Vehicle { private double maxLoad; public void setMaxLoad(double maxLoad = value; value) { } }
  • 21. Declaring Attributes Basic syntax of an attribute:● <modifier>* <type> <name> [ = <initial_value>]; Examples: public class Foo { ● public class Foo { private private private } int x; float y = 10000.0F; String name = "Bates Motel";
  • 22. Declaring Methods Basic syntax of a method: <modifier>* <return_type> <statement>* } <name> ( <argument>* ) {
  • 23. Declaring Methods public class Dog { private int weight; public int getWeight() { return weight; }} public void setWeight(int if ( newWeight > 0 ) { weight = newWeight; } } newWeight) {
  • 24. Accessing Object Members The dot notation is: <object>.<member> This is used to access object members, including methods. Examples of dot notation are: d.setWeight(42); ● attributes and● ● d.setWeight(42); d.weight = 42; // only permissible if weight is public
  • 25. Declaring Constructors Basic syntax of a constructor:● [<modifier>] <class_name> <statement>* } Example: ( <argument>* ) { ● public class Dog { private int weight; public Dog() { weight = 42; } }
  • 26. The Default Constructor There is always at least one constructor in every class. If the writer does not supply any constructors, the default constructor is present automatically: ● ● The default constructor takes no arguments The default constructor body is empty – – The default constructor body is empty– The default enables you to create object instances with new Xxx()without having to write a constructor. ●
  • 27. Source File Layout Basic syntax of a Java source file is: [<package_declaration>] <import_declaration>* <class_declaration>+ ●
  • 28. Source File Layout package shipping.reports; import import import shipping.domain.*; java.util.List; java.io.*;import java.io.*; public class VehicleCapacityReport private List vehicles; { public void generateReport(Writer output) {...} }
  • 29. Software Packages Packages help manage large software systems. Packages can contain classes and sub-packages. ● ●
  • 30. The package Statement Basic syntax of the package statement is: package <top_pkg_name>[.<sub_pkg_name>]*; ● – Examples of the statement are: package shipping.gui.reportscreens; ● – Specify the package declaration at the beginning of the source file.Specify the package declaration at the beginning of Only one package declaration per source file. the source file.● ● If no package is declared, then the class is placed into the default package. Package names must be hierarchical and separated by dots. ● ●
  • 31. The import Statement Basic syntax of the import statement is: Import<pkg_name>[.<sub_pkg_name>]*.<class_name>; OR import<pkg_name>[.<sub_pkg_name>]*.*; ● Examples of the statement are:● import import import java.util.List; java.io.*; shipping.gui.reportscreens.*;
  • 32. The import Statement The import statement does the following: Precedes all class declarations Tells the compiler where to find classes ● ●
  • 33. Comments The three permissible styles program are: // comment on one line /* comment on one of comment in a Java technology /* comment on one * or more lines */ /** documentation comment * can also span one or more lines */
  • 34. Semicolons, Blocks, and White Space A statement is one or more lines of code terminated by a semicolon (;):● totals = a + + d + e + f; A block is a and closing b + c collection braces: of statements bound by opening● and closing { x = y + 1; y = x + 1; } braces:
  • 35. Semicolons, Blocks, and White Space A class definition uses public class MyDate { a special block: private private int int day; month; private } int year;
  • 36. Semicolons, Blocks, and White Space You can nest block statements: while ( i < large a = a + i; // nested block if ( a == max ) { ) { if ( a == max ) { b = b + a; a = 0; } i = i + 1; }
  • 37. Semicolons, Blocks, and White Space Any amount of white For example: {int x;x=23*54;} is equivalent to: space is permitted in a Java: { int x; x = 23 * 54; }
  • 38. Identifiers Identifiers have the following characteristics: Are names given to a variable, class, or method Can start with a Unicode letter, underscore (_), or ● dollar sign ($)● Are case-sensitive Examples: and have no maximum length● ● Examples: identifier userName user_name _sys_var1 $change ●
  • 39. Keywords abstract continue for new switch● assert default goto package this synchronized● boolean do if private● break byte double implements else import public protected throws throw● ● byte case catch char class const else import public throws● enum instanceof return transient● extends int short try● final interface static void● finally long strictfp volatile while ● floatnative super●
  • 40. Primitive Types The Java programming Logical – boolean Textual – char language defines eight primitive types: ● ● Integral – byte, short, int, and long● Floating – double and float●
  • 41. Java Reference Types In Java technology, beyond primitive types all others are reference types. A reference variable contains a handle to an object. ● ● Car c = new Car(); C is a reference variable – – C is a reference variable–
  • 42. Constructing and Initializing Objects Calling new Xyz() performs the following actions: a. Memory is allocated for the object. b. Explicit attribute initialization is performed. c. A constructor is executed. ● c. A constructor is executed. d. The object reference is returned by the new operator. The reference to the object is assigned to a variable. An example is: MyDate my_birth = new MyDate(22, 7, 1964); ● ●
  • 43. Memory Allocation and Layout A declaration allocates storage only for a reference: MyDate my_birth = new MyDate(22, 7, 1964); ● Use the new operator to allocate space for MyDate: MyDate my_birth = new MyDate(22, 7, 1964); ●
  • 44. Executing the Constructor MyDate my_birth = new MyDate(22, 7, 1964);●
  • 45. Assigning a Variable Assign the newly created object to the reference variable as follows: MyDate my_birth = new MyDate(22, 7, 1964); ●
  • 46. Assigning References Two variables refer to a int x = 7; int y = x; single object: MyDate s = new MyDate(22, 7, 1964); MyDate t = s;MyDate t = s;
  • 47. Java Programming Language Coding Conventions Packages: com.example.domain; ● – Classes, interfaces, and SavingsAccount enum types:● – Methods:● Methods: GetAccount()– Variables: currentCustomer ● – Constants: HEAD_COUNT ● –
  • 48. Java Programming Language Coding Conventions Control structures:● if ( condition statement1; } else { ) { statement2; } Spacing:● Use one statement per line.– Use two or four spaces for indentation.–
  • 49. Java Programming Language Coding Conventions Comments: Use // to comment inline code. ● – Use /** documentation */ for class members.–
  • 50. Variables and Scope Local variables are: Variables that are defined inside a method and are called local, automatic, temporary, or stack variables Variables that are created when the method is executed are destroyed when the method is exited ● ● destroyed when the method is exited Variable initialization comprises the following: Local variables require explicit initialization. Instance variables are initialized automatically. ● ●
  • 52. Initialization Before Use Principle The compiler before used. will verify that local variables have been initialized int int int x=8; y; z;int z; z=x+y;
  • 54. Logical Operators The boolean operators ! – NOT are:● – | – OR & – AND ^ – XOR – – ^ – XOR– The short-circuit && – AND boolean operators are:● – || – OR–
  • 55. Bitwise Logical Operators The integer bitwise operators ~ – Complement are:● – ^ – XOR & – AND | – OR – – | – OR–
  • 57. Right-Shift Operators >> and >>> Arithmetic or signed right shift Examples are: ( >> ) operator:● ● 128 >> 1 returns 128/2 1 = 64 256 >> 4 returns 256/2 4 = 16 -256 >> 4 returns -256/2 4 = - – – -256 >> 4 returns -256/2 4 = - 16 – The sign bit is copied during the shift. Logical or unsigned right-shift ( >>> ) operator: This operator is used for bit patterns. ● ● – The sign bit is not copied during the shift. –
  • 58. Left-Shift Operator << Left-shift ( << ) operator works as follows: 128 << 1 returns 128 * 2 1 = 256 ● – 16 << 2 returns 16 * 2 2 = 64–
  • 59. Shift Operator Examples ·101010101010101010101 0101010101010101010101 0101010101110111011101 13 57 ) ) 5 s> > ·l1l1l1l1l1l1l1l1l1l1l 1l1l1l1l1l1l1l1l1l1l1l 1l1l1l1l1lol1lol1lol1I - 135 7 ~1 ~s, s ·lololololol1l1l1l1l1l1 l1l1l1l1l1l1l1l1l1l1l1l 1l1l1l1lol1lol1lol1I >> > 1 3 " 5 ·1°1°1°1°1°1°1°1°1°1° 1°1°1°1°1°1°111°11lol 1lolol1l1lol11ol01°1°1 °1 ( ( >
  • 60. String Concatenation With + The + operator works as follows: Performs String concatenation ● – Produces a new String:– String salutation = "Dr.";String String String salutation = "Dr."; name = "Pete" + " " + "Seymour"; title = salutation + " " + name;
  • 61. Casting If information might be lost in an assignment, the programmer must the assignment with a cast. confirm● The assignment between long and int requires an long bigValue = 99L; explicit cast.● int squashed = bigValue;// Wrong, needs a castint int squashed squashed = = bigValue;// Wrong, needs a cast (int) bigValue; // OK int int int squashed squashed squashed = = = 99L;// Wrong, needs a cast (int) 99L;// OK, but... 99; // default integer literal
  • 62. Promotion and Casting of Expressions Variables are promoted automatically to a longer form (such as int to long). ● Expression is assignment-compatible if the variable as large long bigval = 6;// 6 is an int type, OK type is at least● long bigval = 6;// 6 is an int type, OK int smallval = 99L; // 99L is a long, illegal double z = 12.414F;// 12.414F is float, OK float z1 = 12.414; // 12.414 is double, illegal
  • 63. Simple if, else Statements The if statement syntax: if ( <boolean_expression> ) <statement_or_block> Example: if ( x < 10 ) ● ● if ( x < 10 ) System.out.println("Are or (recommended): if ( x < 10 ) { System.out.println("Are } you finished yet?"); you finished yet?");
  • 64. Complex if, else Statements The if-else statement syntax: if ( <boolean_expression> ) <statement_or_block> else <statement_or_block> ● Example: if ( x < 10 ) { ● System.out.println("Are } else { you finished yet?"); System.out.println("Keep working..."); }
  • 65. Complex if, else Statements The if-else-if statement syntax: if ( <boolean_expression> ) <statement_or_block> else if ( <boolean_expression> ) ● <statement_or_block>
  • 66. if-else-if statement: Example Example: int count = getCount(); // a method defined if (count < 0) { ● in the class System.out.println("Error: count value is negative."); } else if (count > getMaxCount()) { System.out.println("Error: count value is too big."); } else { System.out.println("There will be " + count + " people for lunch today."); }
  • 67. Switch Statements The switch statement syntax: switch ( <expression> ) { case <constant1>: <statement_or_block>* [break;] case <constant2>:case <constant2>: <statement_or_block>* [break;] default: <statement_or_block>* [break;] }
  • 68. Switch Statement Example String carModel = ”STANDARD”; switch ( carModel ) { case DELUXE: System.out.println(“DELUXE”); break; case STANDARD: System.out.println(“Standard”); break; default: System.out.println(“Default”); }
  • 69. Switch Statements Without the break statements, the execution falls through each subsequent case clause. ●
  • 70. For Loop The for loop syntax: for ( <init_expr>; <test_expr>; <alter_expr> ) <statement_or_block> ●
  • 71. For Loop Example for ( int i = 0; i < 10; i++ ) System.out.println(i + " squared or (recommended): for ( int i = 0; i < 10; i++ ) { is " + (i*i)); System.out.println(i + " squared } is " + (i*i));
  • 72. While Loop The while loop syntax: while ( <test_expr> ) <statement_or_block>
  • 73. While Loop Example Example: int i = 0; while ( i < 10 ) { System.out.println(i + " squared is " + (i*i)); i++; }
  • 74. The do/while Loop The do/while loop syntax: do <statement_or_block> while ( <test_expr> ); ●
  • 75. The do/while Example Loop: Example: int i = 0; do { System.out.println(i i++; ● + " squared is " + (i*i)); } while ( i < 10 );
  • 76. Special Loop Flow Control The The The break [<label>]; command continue [<label>]; command <label> : <statement> command, where <statement> should be ● ● ● a loop
  • 77. The break Statement do { statement; if ( condition break; ) { } statement; } while ( test_expr );
  • 78. The continue Statement do { statement; if ( condition continue; ) { } statement; } while ( test_expr );
  • 79. Using break with Labels Statements outer: do { statement1 ; do { statement2statement2 ; if ( condition ) { break outer; } statement3; } while ( test_expr ); statement4; } while ( test_expr );
  • 80. Using continue with Labels Statements test: do { statement1; do { statement2; if ( condition ) {if ( condition ) { continue test; } statement3; } while ( test_expr statement4; } while ( test_expr ); );
  • 81. Declaring Arrays Group data objects of the same type.● Declare arrays char s[]; int p[]; of primitive or class types:● char[] s; int[] p; Create space for a reference.● An array is an object; it is created with new.●
  • 82. Creating Arrays Use the new keyword to create an arrayobject. For example, a primitive (char) array: public char[] createArray() char[] s; { s = new char[26]; for ( int i=0; i<26; i++ ) { s[i] = (char) (’A’ + i); } return s; }
  • 83. Creating an Array of Character Primitives
  • 84. Creating Reference Arrays Another example, an object array: public Point[] createArray() Point[] p; p = new Point[10]; for ( int i=0; i<10; i++ ) { { for ( int i=0; i<10; i++ ) { p[i] = new Point(i, i+1); } return p; }
  • 85. Initializing Arrays Initialize an array element. Create an array with initial String[] names; names = new String[3]; ● values.● names[0] names[1] names[2] = = = "Georgianna"; "Jen"; "Simon";
  • 86. Multidimensional Arrays Arrays of arrays: int[][] twoDim = new int[4][]; twoDim[0] = new int[5]; twoDim[1] = new int[5]; ● int[][] twoDim = new int[][4]; // illegal Array of four arrays of five integers each: int[][] twoDim = new int[4][5]; ●
  • 87. Array Bounds All array subscripts begin at 0: public void printElements(int[] list) { for (int i = 0; i < list.length; i++) { System.out.println(list[i]); } }
  • 88. Using the Enhanced for Loop Java 2 Platform, Standard Edition (J2SETM) version 5.0 introduced● an enhanced for loop for iterating over public void printElements(int[] list) { for ( int element : list ) { System.out.println(element); arrays: System.out.println(element); } }
  • 89. Array Resizing You You cannot resize an array. can use the same reference variable to refer to an entirely new ● ● array, such as: int[] myArray = new int[6]; myArray = new int[10];myArray = new int[10];
  • 90. Copying Arrays The System.arraycopy() method to copy arrays //original array int[] myArray = { 1, 2, 3, 4, 5, 6 }; // new larger array is: int[] hold = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; // copy all of the myArray array to the hold // array, starting with the 0th index System.arraycopy(myArray, 0, hold, 0, myArray.length);