ADVANCED JAVA PROGRAMMING
Presented By
S.Vijayalakshmi B.E,
Assistant Professor,
Department of Computer Science,
Sri Sarada Niketan College for Women, Karur.
 Java is a programming language and a platform.
Java is a high level, robust, object-oriented and
secure programming language.
 Java was developed by Sun Microsystems (which
is now the subsidiary of Oracle) in the year 1995.
 James Gosling is known as the father of Java.
Before Java, its name was Oak. Since Oak was
already a registered company, so James Gosling
and his team changed the name from Oak to Java.
What is Java?
 James Gosling initiated Java language project in
June 1991 for use in one of his many set-top box
projects. The language, initially called ‘Oak’ after
an oak tree that stood outside Gosling's office,
also went by the name ‘Green’ and ended up later
being renamed as Java, from a list of random
words.
 Sun released the first public implementation as
Java 1.0 in 1995.
 It promised Write Once, Run
Anywhere (WORA), providing no-cost run-times
on popular platforms.
HISTORY OF JAVA
 On 13 November, 2006, Sun released much of Java as
free and open source software under the terms of the
GNU General Public License (GPL).
 On 8 May, 2007, Sun finished the process, making all
of Java's core code free and open-source, aside from a
small portion of code to which Sun did not hold the
copyright.
HISTORY OF JAVA (Conti…)
 JDK Alpha and Beta (1995)
 JDK 1.0 (23rd Jan 1996)
 JDK 1.1 (19th Feb 1997)
 J2SE 1.2 (8th Dec 1998)
 J2SE 1.3 (8th May 2000)
 J2SE 1.4 (6th Feb 2002)
 J2SE 5.0 (30th Sep 2004)
 Java SE 6 (11th Dec 2006)
 Java SE 7 (28th July 2011)
 Java SE 8 (18th Mar 2014)
Java Version History
 Java SE 9 (21st Sep 2017)
 Java SE 10 (20th Mar 2018)
 Java SE 11 (September 2018)
 Java SE 12 (March 2019)
 Java SE 13 (September 2019)
 Java SE 14 (Mar 2020)
 Java SE 15 (September 2020)
 Java SE 16 (Mar 2021)
 Java SE 17 (September 2021)
 Java SE 18 (to be released by March 2022)
Java Version History(conti…)
According to Sun, 3 billion devices run Java. There
are many devices where Java is currently used.
Some of them are as follows:
 Desktop Applications such as acrobat reader, media
player, antivirus, etc.
 Web Applications such as irctc.co.in, javatpoint.com,
etc.
 Enterprise Applications such as banking applications.
 Mobile
 Embedded System
 Smart Card
 Robotics
 Games, etc.
Java Applications
There are mainly 4 types of applications that can be created
using Java programming:
 1) Standalone Application
Standalone applications are also known as desktop applications or
window-based applications. These are traditional software that we
need to install on every machine. Examples of standalone
application are Media player, antivirus, etc. AWT and Swing are
used in Java for creating standalone applications.
 2) Web Application
An application that runs on the server side and creates a dynamic
page is called a web application. Currently, Servlet, JSP, Struts,
Spring, Hibernate, JSF, etc. technologies are used for creating web
applications in Java.
Types of Java Applications
 3) Enterprise Application
An application that is distributed in nature, such
as banking applications, etc. is called an
enterprise application. It has advantages like
high-level security, load balancing, and clustering.
In Java, EJB is used for creating enterprise
applications.
 4) Mobile Application
An application which is created for mobile devices
is called a mobile application. Currently, Android
and Java ME are used for creating mobile
applications.
Types of Java Applications(Conti…)
Data types specify the different sizes and values
that can be stored in the variable. There are two
types of data types in Java:
 Primitive data types: The primitive data types
include boolean, char, byte, short, int, long, float and
double.
 Non-primitive data types: The non-primitive data
types include Classes, Interfaces, and Arrays.
Data Types in Java
In Java language, primitive data types are the building
blocks of data manipulation. These are the most basic data
types available in Java language. There are 8 types of
primitive data types:
 boolean data type
 byte data type
 char data type
 short data type
 int data type
 long data type
 float data type
 double data type
Java Primitive Data Types
Data Types in Java
 The Boolean data type is used to store only
two possible values: true and false. This data
type is used for simple flags that track
true/false conditions.
 The Boolean data type specifies one bit of
information, but its "size" can't be defined
precisely.
 Example:
Boolean one = false
Boolean Data Type
 The byte data type is an example of primitive data
type. It isan 8-bit signed two's complement integer.
Its value-range lies between -128 to 127 (inclusive).
Its minimum value is -128 and maximum value is
127. Its default value is 0.
 The byte data type is used to save memory in large
arrays where the memory savings is most
required. It saves space because a byte is 4 times
smaller than an integer. It can also be used in place
of "int" data type.
 Example:
byte a = 10, byte b = -20
Byte Data Type
 The short data type is a 16-bit signed two's
complement integer. Its value-range lies
between -32,768 to 32,767 (inclusive). Its
minimum value is -32,768 and maximum value
is 32,767. Its default value is 0.
 The short data type can also be used to save
memory just like byte data type. A short data
type is 2 times smaller than an integer.
 Example:
short s = 10000, short r = -5000
Short Data Type
 The int data type is a 32-bit signed two's
complement integer. Its value-range lies
between - 2,147,483,648 (-2^31) to
2,147,483,647 (2^31 -1) (inclusive). Its minimum
value is - 2,147,483,648and maximum value is
2,147,483,647. Its default value is 0.
 The int data type is generally used as a default
data type for integral values unless if there is
no problem about memory.
 Example:
int a = 100000, int b = -200000
Int Data Type
 The long data type is a 64-bit two's complement
integer. Its value-range lies between -
9,223,372,036,854,775,808(-2^63) to
9,223,372,036,854,775,807(2^63 -1)(inclusive).
 Its minimum value is - 9,223,372,036,854,775,808
and maximum value is 9,223,372,036,854,775,807.
 Its default value is 0. The long data type is used
when you need a range of values more than those
provided by int.
 Example:
long a = 100000L, long b = -200000L
Long Data Type
 The float data type is a single-precision 32-bit IEEE
754 floating point.Its value range is unlimited.
 It is recommended to use a float (instead of
double) if you need to save memory in large
arrays of floating point numbers.
 The float data type should never be used for
precise values, such as currency. Its default value
is 0.0F.
 Example:
float f1 = 234.5f
Float Data Type
 The double data type is a double-precision 64-
bit IEEE 754 floating point.
 Its value range is unlimited. The double data
type is generally used for decimal values just
like float.
 The double data type also should never be
used for precise values, such as currency. Its
default value is 0.0d.
 Example:
double d1 = 12.3
Double Data Type
 The char data type is a single 16-bit Unicode
character. Its value-range lies between 'u0000'
(or 0) to 'uffff' (or 65,535 inclusive).
 The char data type is used to store characters.
 Example:
char letterA = 'A'
Char Data Type
 Non-primitive data types are
called reference types because they refer
to objects.
 Examples of non-primitive types are Strings
, Arrays, Classes, Interface, etc.
Non-Primitive Data Types
 Primitive types are predefined (already defined) in
Java. Non-primitive types are created by the
programmer and is not defined by Java (except
for String).
 Non-primitive types can be used to call methods to
perform certain operations, while primitive types
cannot.
 A primitive type has always a value, while non-
primitive types can be null.
 A primitive type starts with a lowercase letter, while
non-primitive types starts with an uppercase letter.
Difference between primitive and non-
primitive data types:
 A variable is a container which holds the
value while the Java program is executed.
 It is a combination of "vary + able" which
means its value can be changed.
 A variable is assigned with a data type.
 Variable is a name of memory location.
 There are three types of variables in java:
local, instance and static.
EX: int data=50;//Here data is variable
Java Variables
 There are three types of variables in Java:
Local variable
Instance variable
Static variable
 1) Local Variable
A variable declared inside the body of the method is
called local variable. You can use this variable only
within that method and the other methods in the class
aren't even aware that the variable exists.
 A local variable cannot be defined with "static"
keyword.
Types of Variables
2) Instance Variable
 A variable declared inside the class but outside
the body of the method, is called an instance
variable. It is not declared as static.
 It is called an instance variable because its
value is instance-specific and is not shared
among instances.
Types of Variables(Conti..)
3) Static variable
 A variable that is declared as static is called a
static variable. It cannot be local. You can
create a single copy of the static variable and
share it among all the instances of the class.
Memory allocation for static variables happens
only once when the class is loaded in the
memory.
Types of Variables(Conti..)
public class A
{
static int m=100; //static variable
void method()
{
int n=90;//local variable
}
public static void main(String args[])
{
int data=50; //instance variable
}
} //end of class
Example to understand the types of variables in java
 Arrays are used to store multiple values in a
single variable, instead of declaring separate
variables for each value.
 To declare an array, define the variable type
with square brackets:
EX: String[] cars;
 We have now declared a variable that holds an
array of strings. To insert values to it, you can
place the values in a comma-separated list, inside
curly braces:
String[] cars = {"Volvo", "BMW", "Ford",
"Mazda"};
 To create an array of integers, you could write:
int[] myNum = {10, 20, 30, 40};
Java Arrays
 You can access an array element by referring to
the index number.
 This statement accesses the value of the first
element in cars:
 Example:
String[] cars = {"Volvo", "BMW", "Ford",
"Mazda"};
System.out.println(cars[0]);
Output: Volvo
Access the Elements of an Array
 To change the value of a specific element,
refer to the index number:
 Example
 cars[0] = "Opel";
 Example
String[] cars = {"Volvo", "BMW", "Ford",
"Mazda"};
cars[0] = "Opel";
System.out.println(cars[0]);
// Now outputs Opel instead of Volvo
Change an Array Element
 To find out how many elements an array has,
use the length property:
 Example
String[] cars = {"Volvo", "BMW", "Ford",
"Mazda"};
System.out.println(cars.length);
Output 4
Array Length
THANK YOU

Advanced java programming - DATA TYPES, VARIABLES, ARRAYS

  • 1.
    ADVANCED JAVA PROGRAMMING PresentedBy S.Vijayalakshmi B.E, Assistant Professor, Department of Computer Science, Sri Sarada Niketan College for Women, Karur.
  • 2.
     Java isa programming language and a platform. Java is a high level, robust, object-oriented and secure programming language.  Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995.  James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java. What is Java?
  • 3.
     James Goslinginitiated Java language project in June 1991 for use in one of his many set-top box projects. The language, initially called ‘Oak’ after an oak tree that stood outside Gosling's office, also went by the name ‘Green’ and ended up later being renamed as Java, from a list of random words.  Sun released the first public implementation as Java 1.0 in 1995.  It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms. HISTORY OF JAVA
  • 4.
     On 13November, 2006, Sun released much of Java as free and open source software under the terms of the GNU General Public License (GPL).  On 8 May, 2007, Sun finished the process, making all of Java's core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright. HISTORY OF JAVA (Conti…)
  • 5.
     JDK Alphaand Beta (1995)  JDK 1.0 (23rd Jan 1996)  JDK 1.1 (19th Feb 1997)  J2SE 1.2 (8th Dec 1998)  J2SE 1.3 (8th May 2000)  J2SE 1.4 (6th Feb 2002)  J2SE 5.0 (30th Sep 2004)  Java SE 6 (11th Dec 2006)  Java SE 7 (28th July 2011)  Java SE 8 (18th Mar 2014) Java Version History
  • 6.
     Java SE9 (21st Sep 2017)  Java SE 10 (20th Mar 2018)  Java SE 11 (September 2018)  Java SE 12 (March 2019)  Java SE 13 (September 2019)  Java SE 14 (Mar 2020)  Java SE 15 (September 2020)  Java SE 16 (Mar 2021)  Java SE 17 (September 2021)  Java SE 18 (to be released by March 2022) Java Version History(conti…)
  • 7.
    According to Sun,3 billion devices run Java. There are many devices where Java is currently used. Some of them are as follows:  Desktop Applications such as acrobat reader, media player, antivirus, etc.  Web Applications such as irctc.co.in, javatpoint.com, etc.  Enterprise Applications such as banking applications.  Mobile  Embedded System  Smart Card  Robotics  Games, etc. Java Applications
  • 8.
    There are mainly4 types of applications that can be created using Java programming:  1) Standalone Application Standalone applications are also known as desktop applications or window-based applications. These are traditional software that we need to install on every machine. Examples of standalone application are Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone applications.  2) Web Application An application that runs on the server side and creates a dynamic page is called a web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used for creating web applications in Java. Types of Java Applications
  • 9.
     3) EnterpriseApplication An application that is distributed in nature, such as banking applications, etc. is called an enterprise application. It has advantages like high-level security, load balancing, and clustering. In Java, EJB is used for creating enterprise applications.  4) Mobile Application An application which is created for mobile devices is called a mobile application. Currently, Android and Java ME are used for creating mobile applications. Types of Java Applications(Conti…)
  • 10.
    Data types specifythe different sizes and values that can be stored in the variable. There are two types of data types in Java:  Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float and double.  Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays. Data Types in Java
  • 11.
    In Java language,primitive data types are the building blocks of data manipulation. These are the most basic data types available in Java language. There are 8 types of primitive data types:  boolean data type  byte data type  char data type  short data type  int data type  long data type  float data type  double data type Java Primitive Data Types
  • 12.
  • 13.
     The Booleandata type is used to store only two possible values: true and false. This data type is used for simple flags that track true/false conditions.  The Boolean data type specifies one bit of information, but its "size" can't be defined precisely.  Example: Boolean one = false Boolean Data Type
  • 14.
     The bytedata type is an example of primitive data type. It isan 8-bit signed two's complement integer. Its value-range lies between -128 to 127 (inclusive). Its minimum value is -128 and maximum value is 127. Its default value is 0.  The byte data type is used to save memory in large arrays where the memory savings is most required. It saves space because a byte is 4 times smaller than an integer. It can also be used in place of "int" data type.  Example: byte a = 10, byte b = -20 Byte Data Type
  • 15.
     The shortdata type is a 16-bit signed two's complement integer. Its value-range lies between -32,768 to 32,767 (inclusive). Its minimum value is -32,768 and maximum value is 32,767. Its default value is 0.  The short data type can also be used to save memory just like byte data type. A short data type is 2 times smaller than an integer.  Example: short s = 10000, short r = -5000 Short Data Type
  • 16.
     The intdata type is a 32-bit signed two's complement integer. Its value-range lies between - 2,147,483,648 (-2^31) to 2,147,483,647 (2^31 -1) (inclusive). Its minimum value is - 2,147,483,648and maximum value is 2,147,483,647. Its default value is 0.  The int data type is generally used as a default data type for integral values unless if there is no problem about memory.  Example: int a = 100000, int b = -200000 Int Data Type
  • 17.
     The longdata type is a 64-bit two's complement integer. Its value-range lies between - 9,223,372,036,854,775,808(-2^63) to 9,223,372,036,854,775,807(2^63 -1)(inclusive).  Its minimum value is - 9,223,372,036,854,775,808 and maximum value is 9,223,372,036,854,775,807.  Its default value is 0. The long data type is used when you need a range of values more than those provided by int.  Example: long a = 100000L, long b = -200000L Long Data Type
  • 18.
     The floatdata type is a single-precision 32-bit IEEE 754 floating point.Its value range is unlimited.  It is recommended to use a float (instead of double) if you need to save memory in large arrays of floating point numbers.  The float data type should never be used for precise values, such as currency. Its default value is 0.0F.  Example: float f1 = 234.5f Float Data Type
  • 19.
     The doubledata type is a double-precision 64- bit IEEE 754 floating point.  Its value range is unlimited. The double data type is generally used for decimal values just like float.  The double data type also should never be used for precise values, such as currency. Its default value is 0.0d.  Example: double d1 = 12.3 Double Data Type
  • 20.
     The chardata type is a single 16-bit Unicode character. Its value-range lies between 'u0000' (or 0) to 'uffff' (or 65,535 inclusive).  The char data type is used to store characters.  Example: char letterA = 'A' Char Data Type
  • 21.
     Non-primitive datatypes are called reference types because they refer to objects.  Examples of non-primitive types are Strings , Arrays, Classes, Interface, etc. Non-Primitive Data Types
  • 22.
     Primitive typesare predefined (already defined) in Java. Non-primitive types are created by the programmer and is not defined by Java (except for String).  Non-primitive types can be used to call methods to perform certain operations, while primitive types cannot.  A primitive type has always a value, while non- primitive types can be null.  A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase letter. Difference between primitive and non- primitive data types:
  • 23.
     A variableis a container which holds the value while the Java program is executed.  It is a combination of "vary + able" which means its value can be changed.  A variable is assigned with a data type.  Variable is a name of memory location.  There are three types of variables in java: local, instance and static. EX: int data=50;//Here data is variable Java Variables
  • 24.
     There arethree types of variables in Java: Local variable Instance variable Static variable  1) Local Variable A variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class aren't even aware that the variable exists.  A local variable cannot be defined with "static" keyword. Types of Variables
  • 25.
    2) Instance Variable A variable declared inside the class but outside the body of the method, is called an instance variable. It is not declared as static.  It is called an instance variable because its value is instance-specific and is not shared among instances. Types of Variables(Conti..)
  • 26.
    3) Static variable A variable that is declared as static is called a static variable. It cannot be local. You can create a single copy of the static variable and share it among all the instances of the class. Memory allocation for static variables happens only once when the class is loaded in the memory. Types of Variables(Conti..)
  • 27.
    public class A { staticint m=100; //static variable void method() { int n=90;//local variable } public static void main(String args[]) { int data=50; //instance variable } } //end of class Example to understand the types of variables in java
  • 28.
     Arrays areused to store multiple values in a single variable, instead of declaring separate variables for each value.  To declare an array, define the variable type with square brackets: EX: String[] cars;  We have now declared a variable that holds an array of strings. To insert values to it, you can place the values in a comma-separated list, inside curly braces: String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};  To create an array of integers, you could write: int[] myNum = {10, 20, 30, 40}; Java Arrays
  • 29.
     You canaccess an array element by referring to the index number.  This statement accesses the value of the first element in cars:  Example: String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; System.out.println(cars[0]); Output: Volvo Access the Elements of an Array
  • 30.
     To changethe value of a specific element, refer to the index number:  Example  cars[0] = "Opel";  Example String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; cars[0] = "Opel"; System.out.println(cars[0]); // Now outputs Opel instead of Volvo Change an Array Element
  • 31.
     To findout how many elements an array has, use the length property:  Example String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; System.out.println(cars.length); Output 4 Array Length
  • 32.