SlideShare a Scribd company logo
1 of 99
Learn JAVA
--- Rohit Raj Singh
Introduction
 Firstly, it was called "Greentalk" by James Gosling and file
extension was .gt.
 After that, it was called Oak and was developed as a part of the
Green project.
 James Gosling and Sun Microsystems.
 Java, May 20, 1995, Sun World
 HotJava, The first Java-enabled Web browser
History
 The history of Java is very interesting. Java was originally
designed for interactive television, but it was too advanced
technology for the digital cable television industry at the time.
The history of java starts from Green Team. Java team members
initiated this project to develop a language for digital devices
such as set-top boxes, televisions etc. But, it was suited for
internet programming. Later, Java technology was incorporated
by Netscape
 James Gosling, Mike Sheridan, and Patrick
Naughton initiated the Java language project in June 1991. The
small team of sun engineers called Green Team.
What is Java ?
 Java is a secure programming language that follows OOPs Java
is a high level, robust, secured and object-oriented programming
language.
 The most important feacture’s of java is plateform independent.
 Java's platform independence is achieved by the use of the JVM
(Java Virtual Machine).
 When a Java program is compiled the .java files are fed to a
compiler which produces a .class file for each .java file
 The .class file contains Java bytecode.
 Bytecode is like machine language, but it is intended for the
Java Virtual Machine not a specific chip such as a Pentium or
PowerPC chip
Characteristic of Java
 Java is simple
 Java is dynamic
 Java is portable
 Java is secure
 Java is object-oriented
 Java is multithreaded
 Generics
 Collection
Plateform
 Any hardware or software environment in which a program
runs, is known as a platform. Since Java has its own runtime
environment (JRE) and API, it is called platform.
Java IDE
 IDE means the Environment in which Java Programs or
Applications are Developed and Run.
 Netbean
 Eclipse
Flow of Program
What is JDK, JRE and JVM?
 Jdk provide development tool to Develop and
Run the Java Program for Developers.
 JRE provide Environment to Run the Java
Application for Clients.
 JVM is Responsible to Run the Java Program
or Application Line by Line for Developers
and Client both.
 JDK = JRE + Development Tools
 JRE = JVM + Library Classes.
Architecture of Jdk
 jdk contains the Java Runtime Environment (JRE), an
interpreter/loader (java), a compiler (javac), an archiver (jar), a
documentation generator (javadoc) and other tools needed
in Java development.
Architecture of JRE
 JRE is an acronym for Java Runtime Environment.
 It is the implementation of JVM. It physically exists. It contains
set of libraries + other files that JVM uses at runtime.
JVM
 JVM (Java Virtual Machine) is an abstract machine that
provides runtime environment in which java bytecode can be
executed.
 JVM, JRE and JDK are platform dependent because
configuration of each OS differs. But, Java is platform
independent.
 The JVM performs following main tasks:
1. Loads code
2. Verifies code
3. Executes code
4. Provides runtime environment
Current JDK Versions
JDK 13 September, 10th 2019
JDK 12 March, 19th 2019
JDK 11 September, 25th 2018
JDK 10 March, 20th 2018
JDK 9 September, 21st 2017
JDK 8 March 2014
JDK 7 Dolphin July 2011
Executing JAVA Applications
 On Command Prompt
Type javac Class or File_Name with
extension of java file.
Ex- javac Welcome.java
Type Java ByteCode file Name.
Ex- java Welcome
Output:...
Java Architecture
Anatomy of a Java Program
 Comments
 Package
 Reserved words
 Modifiers
 Statements
 Blocks
 Classes
 Methods
 The main method
Comments
 We use the Comment to enhancing the readability of our
program.
 In Java, comments are preceded by two forward slashes (//) in a
line
 Multiline Comment enclosed between /* and */ in one or
multiple lines.
 When the compiler sees //, it ignores all text after // in the same
line.
 When it sees /*, it scans for the next */ and ignores any text
between /* and */.
Package
 The second line in the program specifies a package name, A
Package is a namespace that organize a set of related classes and
interfaces.
Keyword
 Reserved words or keywords are words that have a specific
meaning to the compiler and cannot be used for other purposes
in the program. For example, when the compiler sees the word
class, it understands that the word after class is the name for the
class. Other reserved words are as public, static, and void. Their
use will be introduced later in the book.
Modifiers
 Java uses certain reserved words called modifiers that specify
the properties of the data, methods, and classes and how they
can be used. Examples of modifiers are public and static. Other
modifiers are private, final, abstract, and protected. A public
datum, method, or class can be accessed by other programs. A
private datum or method cannot be accessed by other programs.
Statement
 A statement represents an action or a sequence of actions.
 The statement System.out.println("Welcome to Java!") in the
program in Example 1.1 is a statement to display the greeting
"Welcome to Java!" Every statement in Java ends with a
semicolon (;).
Blocks
 A pair of braces in a program forms a block that groups
components of a program.
public class Test {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
Class block
Method block
Methods
 What is System.out.println? It is a method:
 a collection of statements that performs sequence of operations
to display a message on the console.
 It can be used even without fully understanding the details of
how it works.
 It is used by invoking a statement with a string argument. The
string argument is enclosed within parentheses. And the
argument is "Welcome to Java!" You can call the same println
method with a different argument to print a different message.
Main Method
The main method provides the control of program flow. The Java
interpreter executes the application by invoking the main method.
The main method looks like this:
public static void main(String args[]) {
// Statements;
class
 The class is the essential Java construct. A class is a template or
blueprint for objects. To program in Java, you must understand
classes and be able to write and use them .
 A program can contain more than one classes.
Types of Java Edition
 Java SE (Standard Edition)
 Java EE (Enterprise Edition)
 Java MC (Micro Edition)
 Java TV (Television Edition)
 Java Card (Sim Card)
Types of Application made by
java
 Standalone Application
 Enterprise Application
 Mobile Application
 Web Application
Naming Convention
 Java naming convention is a rule to follow as you decide what
to name your identifiers such as class, package, variable,
constant, method etc.
 But, it is not forced to follow. So, it is known as convention not
rule.
 All the classes, interfaces, packages, methods and fields of java
programming language are given according to java naming
convention.
First Program
class Name
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
What happens at Runtime?
Classloader: is the subsystem of JVM
that is used to load class files.
Bytecode Verifier: checks the code
fragments for illegal code that can violate
access right to objects.
Interpreter: read bytecode stream then
execute the instructions.
Can you save a java source file by
other name than the class name?
 Yes, if the class is not public.
Can you have multiple classes
in a java source file?
 Yes , A class can contains more than one class.
Variables in Java
 A variable is a container which holds the value while the java
program is executed. A variable is assigned with a data-type.
 Data Type describes the size of variable ,default value, Which
type of value are stored.
 Variable is a name of memory location. Eg. int a=10;
Types of variable
There are three types of variables in java:
Types of Variables
 1. Local Variable:
A variable declared inside the method is called local
variable.
 2. Instance Variable:
A variable declared inside the class but outside the method, is
called instance variable . It is not declared as static.
 3. Static variable:
A variable which is declared as static is called static
variable. It cannot be local.
Data Types
 Data types represent the different values to be stored in the
variable. In java, there are two types of data types:
 Primitive data types
 Non-primitive data types
Java Heap and Stack Memory
Heap Memory Stack Memory
Heap Memory is created by the Java
Virtual Machine when it starts. The
memory is used as long as the
application is running.
When an object is created, it is
always created in Heap and has
global access. That means all objects
can be referenced from anywhere in
the application.
Stack Memory is the temporary
memory where variable values are
stored when their methods are
invoked. After the method is finished,
the memory containing those values
is cleared to make room for new
methods.
When a new method is invoked, a
new block of memory will be created
in the Stack.
Heap and Stack Memory e.g.
class Student8{
int rollno;
String name;
static String college ="ITS";
Student8(int r,String n){
rollno = r;
name = n;
}
..void display ()
{
System.out.println(rollno+" "+name+" "+college);}
public static void main(String args[]){
Student8 s1 = new Student8(111,"Karan");
Student8 s2 = new Student8(222,"Aryan");
s1.display();
s2.display();
}
}
Operators in java
 Operator in java is a symbol that is used to perform operations.
How to take input from user
 By using Scanner Class
Control Statement
OOPs Concept
 Object means a real word entity such
as pen, chair, table etc. Object-
Oriented
 Programming is a methodology or
paradigm to design a program using
classes and objects.
 Programming simplifies the software
development and maintenance by
providing some concepts:
Object and Class
 Object :
Any entity that has state and behavior is known as an object.
For example: chair, pen, table, keyboard, bike etc. It can be physical
and logical.
 Class :
Collection of objects is called class. It is a logical entity.
Abstraction
 Hiding internal details and showing functionality is known as
abstraction. For example: phone call, we don't know the internal
processing.
 In java, we use abstract class and interface to achieve
abstraction.
Encapsulation
 Binding (or wrapping) code and data together into a single
unit is known as encapsulation. For example: capsule, it is
wrapped with different medicines.
 A java class is the example of encapsulation. Java bean is the
fully encapsulated class because all the data members are
private here.
 We can create a fully encapsulated class in java by making all
the data members of the class private. Now we can use setter
and getter methods to set and get the data in it
Inheritance and Polymorphism
 Inheritance :
When one object acquires all the properties and
behaviours of parent object i.e. known as inheritance. It provides
code reusability. It is used to achieve runtime polymorphism.
When one task is performed by different ways i.e. known as polymorphism.
Polymorphism
Java Package
 A java package is a group of similar types of classes, interfaces
and sub-packages.
 Package in java can be categorized in two form, built-in
package and user-defined package.
 There are many built-in packages such as java, lang, awt, javax,
swing, net, io, util, sql etc.
Advantages of Package
 Java package is used to categorize the classes and interfaces so
that they can be easily maintained.
 Java package provides access protection.
 Java package removes naming collision
Types of Package
How to access package from
another package
 There are three ways to access the package from outside the
package.
1. Using Package Name.*
2. import package.classname;
3. fully qualified name.
Using PackageName.*
//save by A.java
package pack;
public class A{
public void msg()
{
System.out.println("Hello");
}
}
//save by B.java
package mypack;
import pack.*;
class B
{
public static void main(String
args[])
{
A obj = new A();
obj.msg();
}
}
Output Hello
Using PackageName.ClassName
//save by A.java
package pack;
public class A{
public void msg()
{
System.out.println("Hello");
}
}
//save by B.java
package mypack;
import pack.A;
class B
{
public static void main(String
args[])
{
A obj = new A();
obj.msg();
}
}
Using FullyQualified Name
//save by A.java
package pack;
public class A{
public void msg()
{
System.out.println("Hello");
}
}
//save by B.java
package mypack;
class B
{
public static void main(String
args[])
{
pack.A obj = new pack.A();
//using fully qualified name
obj.msg();
}
}
Abstract and Interface
 Abstract class and Interface both are used to achieve abstraction
where we can declared abstract and non-abstract method.
 A class which is declared with abstract keyword is called
abstract class.
 An Interface keyword is used to declare interface.
 A class that implement interface must implement all the
methods declared in the interface.
Access Modifiers in Java
 The access modifiers in java specifies accessibility (scope) of a
data member, method, constructor or class.
 There are many non-access modifiers such as static, abstract etc.
default access modifier
 If you don't use any modifier, it is treated as default by default.
The default modifier is accessible only within package.
package pack;
class A{
void msg()
{System.out.println("Hello");}
}
//save by A.java
package mypack;
import pack.*;
class B{
public static void main(String args[])
{
A obj = new A();//Compile Time Error
obj.msg();//Compile Time Error
}
}
//save by B.java
In this example, we have created two packages pack and mypack. the scope of class
A and its method msg() is default so it cannot be accessed from outside the package.
public access modifier
 The public access modifier is accessible everywhere. It has the
widest scope among all other modifiers.
//save by A.java
package pack;
public class A{
public void msg()
{
System.out.println("Hello");
}
}
//save by B.java
package mypack;
import pack.*;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg();
}
}
private access modifier
 The private access modifier is accessible only within class.
class A
{
private int data=40;
private void msg()
{
System.out.println("Hello java");
}
}
public class Simple{
public static void main(String args[]){
A obj=new A();
System.out.println(obj.data);//Compile Time Error
obj.msg();//Compile Time Error
}
}
In this example, we have created two classes A
and Simple. A class contains private data
member and private method. We are accessing
these private members from outside the class,
so there is compile time error.
protected access modifier
The protected access modifier is accessible within package and outside the
package but through inheritance only.The protected access modifier can be
applied on the data member, method and constructor. It can't be applied on the
class.
In this example, we have created the two packages pack and mypack. The A class
of pack package is public, so can be accessed from outside the package. But msg
method of this package is declared as protected, so it can be accessed from
outside the class only through inheritance.
//save by A.java
package pack;
public class A{
protected void msg()
{System.out.println("Hello");}
}
//save by B.java
package mypack;
import pack.*;
class B extends A{
public static void main(String args[]){
B obj = new B();
obj.msg();
}
}
Java Array
 Java array is an object that contains elements of similar data
type. It is a data structure where we store similar elements. We
can store only fixed set of elements in a java array.
 Array can contains primitives data types as well as objects of a
class depending on the definition of array. In case of primitives
data types, the actual values are stored in contiguous memory
locations. In case of objects of a class, the actual objects are
stored in heap segment.
Advantage & Disadvantage of
Java Array
Advantage of Java Array :
1. Code Optimization : It makes the code optimized, we can retrieve
or sort the data easily.
2. Random access : We can get any data located at any index
position.
 Disadvantage of Java Array :
1. Size Limit : We can store only fixed size of elements in the array. It
doesn't grow its size at runtime. To solve this problem, collection
framework is used in java.
Creating an Array in java
 One-DimensionalArrays:
The general form of a one-dimensional array declaration is
 type var-name[]; OR type[] var-name;
 The element type for the array determines what type of data the
array will hold.
 Like -- array of int type, we can also create an array of other
primitive data types like char, float, double..etc or user defined data
type(objects of a class).
 // both are valid declarations ---
 int intArray[]; or int[] intArray;
 intArray is an array variable, no array actually exists. It simply
tells to the compiler that this(intArray) variable will hold an array of
the integer type. To link intArray with an actual, physical array of
integers, you must allocate one using new and assign it to intArray.
Instantiating an Array in Java
 When an array is declared, only a reference of array is created. To
actually create or give memory to array, you create an array like this:
 SYNTAX --- : var-name = new type [size];
 // Here, type specifies the type of data being allocated, size specifies
the number of elements in the array, and var-name is the name of
array variable that is linked to the array.
Accessing Java Array Elements
 The index begins with 0 and ends at (total array size)-1. All the
elements of array can be accessed using Java for Loop.
Implementation of Array
.
Jagged Array
 Jagged Array are arrays of arrays with each element of the
array holding the reference of other array. These are also known
as multidimensional array. Examples: --
 A multidimensional array is created by appending one set of
square brackets ([]) per dimension.
Implementation of Jagged Array
.
Array Literal
 In a situation, where the size of the array and variables of array
are already known, array literals can be used.
 The length of this array determines the length of the created
array.
 There is no need to write the new int[] part in the latest versions
of Java.
Passing Array to Method in java
.
Iterator interface
 Iterator interface provides the facility of iterating the elements in forward
direction only.
 Methods of Iterator interface :
No. Method Description
1 public boolean
hasNext()
It returns true if iterator has more elements.
2 public Object next() It returns the element and moves the cursor
pointer to the next element.
3 public void remove() It removes the last elements returned by the
iterator. It is rarely used.
Methods of Collection interface
.
No. Method Description
1 public boolean add(Object element) is used to insert an element in this collection.
2 public boolean addAll(Collection c) is used to insert the specified collection elements in the invoking collection.
3 public boolean remove(Object element) is used to delete an element from this collection.
4 public boolean removeAll(Collection c) is used to delete all the elements of specified collection from the invoking
collection.
5 public boolean retainAll(Collection c) is used to delete all the elements of invoking collection except the specified
collection.
6 public int size() return the total number of elements in the collection.
7 public void clear() removes the total no of element from the collection.
8 public boolean contains(Object element) is used to search an element.
9 public boolean containsAll(Collection c) is used to search the specified collection in this collection.
10 public Iterator iterator() returns an iterator.
11 public Object[] toArray() converts collection into array.
12 public boolean isEmpty() checks if collection is empty.
13 public boolean equals(Object element) matches two collection.
14 public int hashCode() returns the hashcode number for collection.
Hierarchy of Collection Framework
Collections in Java
 Collection represents a single unit of objects i.e. a group.
 Collections in java is a framework that provides an architecture
to store and manipulate the group of objects.
 All the operations that you perform on a data such as searching,
sorting, insertion, manipulation, deletion etc. can be performed
by Java Collections.
 Java Collection framework provides many interfaces (Set, List,
Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList,
PriorityQueue, HashSet, LinkedHashSet, TreeSet etc).
 What is framework in java :
1. provides readymade architecture.
2. represents set of classes and interface.
3. is optional.
 What is Collection framework :
Collection framework represents a unified architecture for
storing and manipulating group of objects. It has:
1. Interfaces and its implementations i.e. classes
2. Algorithm
Two ways to iterate the elements of
collection in java
 There are two ways to traverse collection elements:
1. By Iterator interface.
2. By for - each loop.
Iterate the elements from collection
through foreach loop
Iterate the elements from collection
through iterator interface
Java Non-generic Vs Generic Collection
 Java collection framework was non-generic before JDK 1.5. Since 1.5, it
is generic.
 Java new generic collection allows you to have only one type of object
in collection. Now it is type safe so typecasting is not required at run
time.
 Let's see the old non-generic example of creating java collection.
ArrayList al=new ArrayList();
//creating old non-generic arraylist
 Let's see the new generic example of creating java collection.
ArrayList<String> al=new ArrayList<String>();
//creating new generic arraylist
 In generic collection, we specify the type in angular braces. Now
ArrayList is forced to have only specified type of objects in it. If you try
to add another type of object, it gives compile time error.
Type Casting
 Assigning a value of one type to a variable of another
type is known as Type Casting.
Widening Casting(Implicit)
 Automatic Type casting take place when,
 The two types are compatible
 The target type is larger than the source type
Narrowing or Explicit type
conversion
 When you are assigning a larger type value to a variable
of smaller type, then you need to perform explicit type
casting.
Exception and Exception handling
What is exception :
 Exception is an abnormal condition.
 In java, exception is an event that disrupts the normal flow of
the program. It is an object which is thrown at runtime.
What is exception handling :
 The exception handling is a mechanism to handle the runtime
errors so that normal flow of the application can be maintained.
 such as ClassNotFound, IO, SQL, Remote etc.
Types of Exception
 There are mainly two types of exceptions:
 checked
 unchecked
 where error is considered as unchecked exception.
 The sun microsystem says there are three types of
exceptions:
 Checked Exception
 Unchecked Exception
 Error
Checked Exception
 The classes that extend Throwable class except
RuntimeException and Error are known as checked
exceptions .
 Checked exceptions are checked at compile-time.
 Example :
IOException, SQLException,
ClassNotFound Exception etc
Unchecked Exception
 The classes that extend RuntimeException are known as
unchecked exceptions
 Example :
ArithmeticException, NullPointerException,
NumberFormatException,
IndexOutOfBoundsException --
(
ArrayIndexOutOfBoundsException,
StringIndexOutOfBoundsException
) etc.
 Unchecked exceptions are not checked at compile-time
rather they are checked at runtime.
Error
 Error is irrecoverable .
 Example :
StackOverFlowError, VirtualMachineError,
OutOfMemoryError, AssertionError, etc.
Common Scenarios Where
Unchecked Exception may occur
 There are given some scenarios where unchecked
exceptions can occur.
 They are as follows:
 Scenario where ArithmeticException occurs
 Scenario where NullPointerException occurs
 Scenario where NumberFormatException occurs
 Scenario where ArrayIndexOutOfBoundsException
occurs
 Scenario where StringIndexOutOfBoundsException
occurs
ArithmeticException
 If we divide any number by zero, there occurs an
ArithmeticException.
 int a=50/0;//ArithmeticException
NullPointerException
 If we have null value in any variable, performing any
operation by the variable occurs an
NullPointerException.
 //NullPointerException
 String s=null; System.out.println(s.length());
NumberFormatException
 The wrong formatting of any value, may occur
NumberFormatException.
 Suppose I have a string variable that have characters,
converting this variable into digit will occur
NumberFormatException.
 String s="abc";
 int i=Integer.parseInt(s);//NumberFormatException
ArrayIndexOutOfBoundsException
 If you are inserting any value in the wrong index, it
would result ArrayIndexOutOfBoundsException as shown
below:
 int a[]=new int[5];
a[10]=50; //ArrayIndexOutOfBoundsException
StringIndexOutOfBoundException
 This exception is thrown by the methods of the String class, in
order to indicate that an index is either negative, or greater than
the size of the string itself. Moreover, some methods of
the String class thrown this exception, when the specified index
is equal to the size of the string.
Common Scenarios Where
checked Exception may occur
 Scenario where IOException occurs
 Scenario where SQLException occurs
 Scenario where ClassNotFound Exception occurs
IOException
 IOException is the general class of exceptions produced by
failed or interrupted I/O Operations.
 As This is the checked Exception, It must be handled by the
programmer else program does not compile.
 Below are some scenarios when IOException would be
thrown.
 You were reading network file and got disconnected.
 Reading Local file which is not available any more.
 Using some stream to read the data and some other process
closes the stream.
 You are trying to read/write a file and don’t have permission
 You were writing a file and disk space is not available
anymore
SQLException
ClassNotFound Exception
.
Thank You!

More Related Content

More from Rohit Singh

More from Rohit Singh (8)

5g networking technology
5g networking technology5g networking technology
5g networking technology
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
 
First program of C ( Complete Explanation )
First program of C ( Complete Explanation )First program of C ( Complete Explanation )
First program of C ( Complete Explanation )
 
C language
C languageC language
C language
 
CCNA Course Training Presentation
CCNA Course Training PresentationCCNA Course Training Presentation
CCNA Course Training Presentation
 
Html Basic
Html Basic Html Basic
Html Basic
 
Software testing basic
Software testing basicSoftware testing basic
Software testing basic
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 

Recently uploaded

Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
K Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CV
K VENKAT NAVEEN KUMAR
 
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
eqaqen
 
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
yynod
 
一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证
一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证
一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证
eqaqen
 
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
gajnagarg
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
ZurliaSoop
 
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
eqaqen
 
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
gynedubai
 
怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制
怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制
怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制
yynod
 
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Angela Justice, PhD
 
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
gajnagarg
 
Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
gajnagarg
 
Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 

Recently uploaded (20)

Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Sagar [ 7014168258 ] Call Me For Genuine Models We ...
 
K Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CVK Venkat Naveen Kumar | GCP Data Engineer | CV
K Venkat Naveen Kumar | GCP Data Engineer | CV
 
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
一比一定(购)中央昆士兰大学毕业证(CQU毕业证)成绩单学位证
 
drug book file on obs. and gynae clinical pstings
drug book file on obs. and gynae clinical pstingsdrug book file on obs. and gynae clinical pstings
drug book file on obs. and gynae clinical pstings
 
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
怎样办理加利福尼亚大学伯克利分校毕业证(UC Berkeley毕业证书)成绩单学校原版复制
 
一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证
一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证
一比一定(购)堪培拉大学毕业证(UC毕业证)成绩单学位证
 
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Ratnagiri [ 7014168258 ] Call Me For Genuine Models...
 
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
Jual obat aborsi Jakarta ( 085657271886 )Cytote pil telat bulan penggugur kan...
 
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
一比一定(购)南昆士兰大学毕业证(USQ毕业证)成绩单学位证
 
Joshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptxJoshua Minker Brand Exploration Sports Broadcaster .pptx
Joshua Minker Brand Exploration Sports Broadcaster .pptx
 
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
<DUBAI>Abortion pills IN UAE {{+971561686603*^Mifepristone & Misoprostol in D...
 
Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...
Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...
Novo Nordisk Kalundborg. We are expanding our manufacturing hub in Kalundborg...
 
DMER-AYUSH-MIMS-Staff-Nurse-_Selection-List-04-05-2024.pdf
DMER-AYUSH-MIMS-Staff-Nurse-_Selection-List-04-05-2024.pdfDMER-AYUSH-MIMS-Staff-Nurse-_Selection-List-04-05-2024.pdf
DMER-AYUSH-MIMS-Staff-Nurse-_Selection-List-04-05-2024.pdf
 
怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制
怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制
怎样办理宾夕法尼亚大学毕业证(UPenn毕业证书)成绩单学校原版复制
 
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
Simple, 3-Step Strategy to Improve Your Executive Presence (Even if You Don't...
 
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Gangtok [ 7014168258 ] Call Me For Genuine Models W...
 
Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Etawah [ 7014168258 ] Call Me For Genuine Models We...
 
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hubli [ 7014168258 ] Call Me For Genuine Models We ...
 
Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Agartala [ 7014168258 ] Call Me For Genuine Models ...
 
Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.Brand Analysis for reggaeton artist Jahzel.
Brand Analysis for reggaeton artist Jahzel.
 

Java Project Basic (Complete Java)

  • 2. Introduction  Firstly, it was called "Greentalk" by James Gosling and file extension was .gt.  After that, it was called Oak and was developed as a part of the Green project.  James Gosling and Sun Microsystems.  Java, May 20, 1995, Sun World  HotJava, The first Java-enabled Web browser
  • 3. History  The history of Java is very interesting. Java was originally designed for interactive television, but it was too advanced technology for the digital cable television industry at the time. The history of java starts from Green Team. Java team members initiated this project to develop a language for digital devices such as set-top boxes, televisions etc. But, it was suited for internet programming. Later, Java technology was incorporated by Netscape  James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team.
  • 4. What is Java ?  Java is a secure programming language that follows OOPs Java is a high level, robust, secured and object-oriented programming language.  The most important feacture’s of java is plateform independent.  Java's platform independence is achieved by the use of the JVM (Java Virtual Machine).  When a Java program is compiled the .java files are fed to a compiler which produces a .class file for each .java file  The .class file contains Java bytecode.  Bytecode is like machine language, but it is intended for the Java Virtual Machine not a specific chip such as a Pentium or PowerPC chip
  • 5. Characteristic of Java  Java is simple  Java is dynamic  Java is portable  Java is secure  Java is object-oriented  Java is multithreaded  Generics  Collection
  • 6. Plateform  Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own runtime environment (JRE) and API, it is called platform.
  • 7. Java IDE  IDE means the Environment in which Java Programs or Applications are Developed and Run.  Netbean  Eclipse
  • 9. What is JDK, JRE and JVM?  Jdk provide development tool to Develop and Run the Java Program for Developers.  JRE provide Environment to Run the Java Application for Clients.  JVM is Responsible to Run the Java Program or Application Line by Line for Developers and Client both.  JDK = JRE + Development Tools  JRE = JVM + Library Classes.
  • 10. Architecture of Jdk  jdk contains the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
  • 11. Architecture of JRE  JRE is an acronym for Java Runtime Environment.  It is the implementation of JVM. It physically exists. It contains set of libraries + other files that JVM uses at runtime.
  • 12. JVM  JVM (Java Virtual Machine) is an abstract machine that provides runtime environment in which java bytecode can be executed.  JVM, JRE and JDK are platform dependent because configuration of each OS differs. But, Java is platform independent.  The JVM performs following main tasks: 1. Loads code 2. Verifies code 3. Executes code 4. Provides runtime environment
  • 13. Current JDK Versions JDK 13 September, 10th 2019 JDK 12 March, 19th 2019 JDK 11 September, 25th 2018 JDK 10 March, 20th 2018 JDK 9 September, 21st 2017 JDK 8 March 2014 JDK 7 Dolphin July 2011
  • 14. Executing JAVA Applications  On Command Prompt Type javac Class or File_Name with extension of java file. Ex- javac Welcome.java Type Java ByteCode file Name. Ex- java Welcome Output:...
  • 16. Anatomy of a Java Program  Comments  Package  Reserved words  Modifiers  Statements  Blocks  Classes  Methods  The main method
  • 17. Comments  We use the Comment to enhancing the readability of our program.  In Java, comments are preceded by two forward slashes (//) in a line  Multiline Comment enclosed between /* and */ in one or multiple lines.  When the compiler sees //, it ignores all text after // in the same line.  When it sees /*, it scans for the next */ and ignores any text between /* and */.
  • 18. Package  The second line in the program specifies a package name, A Package is a namespace that organize a set of related classes and interfaces.
  • 19. Keyword  Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words are as public, static, and void. Their use will be introduced later in the book.
  • 20. Modifiers  Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs.
  • 21. Statement  A statement represents an action or a sequence of actions.  The statement System.out.println("Welcome to Java!") in the program in Example 1.1 is a statement to display the greeting "Welcome to Java!" Every statement in Java ends with a semicolon (;).
  • 22. Blocks  A pair of braces in a program forms a block that groups components of a program. public class Test { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Class block Method block
  • 23. Methods  What is System.out.println? It is a method:  a collection of statements that performs sequence of operations to display a message on the console.  It can be used even without fully understanding the details of how it works.  It is used by invoking a statement with a string argument. The string argument is enclosed within parentheses. And the argument is "Welcome to Java!" You can call the same println method with a different argument to print a different message.
  • 24. Main Method The main method provides the control of program flow. The Java interpreter executes the application by invoking the main method. The main method looks like this: public static void main(String args[]) { // Statements;
  • 25. class  The class is the essential Java construct. A class is a template or blueprint for objects. To program in Java, you must understand classes and be able to write and use them .  A program can contain more than one classes.
  • 26. Types of Java Edition  Java SE (Standard Edition)  Java EE (Enterprise Edition)  Java MC (Micro Edition)  Java TV (Television Edition)  Java Card (Sim Card)
  • 27. Types of Application made by java  Standalone Application  Enterprise Application  Mobile Application  Web Application
  • 28. Naming Convention  Java naming convention is a rule to follow as you decide what to name your identifiers such as class, package, variable, constant, method etc.  But, it is not forced to follow. So, it is known as convention not rule.  All the classes, interfaces, packages, methods and fields of java programming language are given according to java naming convention.
  • 29. First Program class Name { public static void main(String args[]) { System.out.println("Hello Java"); } }
  • 30. What happens at Runtime? Classloader: is the subsystem of JVM that is used to load class files. Bytecode Verifier: checks the code fragments for illegal code that can violate access right to objects. Interpreter: read bytecode stream then execute the instructions.
  • 31. Can you save a java source file by other name than the class name?  Yes, if the class is not public.
  • 32. Can you have multiple classes in a java source file?  Yes , A class can contains more than one class.
  • 33. Variables in Java  A variable is a container which holds the value while the java program is executed. A variable is assigned with a data-type.  Data Type describes the size of variable ,default value, Which type of value are stored.  Variable is a name of memory location. Eg. int a=10;
  • 34. Types of variable There are three types of variables in java:
  • 35. Types of Variables  1. Local Variable: A variable declared inside the method is called local variable.  2. Instance Variable: A variable declared inside the class but outside the method, is called instance variable . It is not declared as static.  3. Static variable: A variable which is declared as static is called static variable. It cannot be local.
  • 36. Data Types  Data types represent the different values to be stored in the variable. In java, there are two types of data types:  Primitive data types  Non-primitive data types
  • 37. Java Heap and Stack Memory Heap Memory Stack Memory Heap Memory is created by the Java Virtual Machine when it starts. The memory is used as long as the application is running. When an object is created, it is always created in Heap and has global access. That means all objects can be referenced from anywhere in the application. Stack Memory is the temporary memory where variable values are stored when their methods are invoked. After the method is finished, the memory containing those values is cleared to make room for new methods. When a new method is invoked, a new block of memory will be created in the Stack.
  • 38. Heap and Stack Memory e.g. class Student8{ int rollno; String name; static String college ="ITS"; Student8(int r,String n){ rollno = r; name = n; } ..void display () { System.out.println(rollno+" "+name+" "+college);} public static void main(String args[]){ Student8 s1 = new Student8(111,"Karan"); Student8 s2 = new Student8(222,"Aryan"); s1.display(); s2.display(); } }
  • 39. Operators in java  Operator in java is a symbol that is used to perform operations.
  • 40. How to take input from user  By using Scanner Class
  • 42. OOPs Concept  Object means a real word entity such as pen, chair, table etc. Object- Oriented  Programming is a methodology or paradigm to design a program using classes and objects.  Programming simplifies the software development and maintenance by providing some concepts:
  • 43. Object and Class  Object : Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.  Class : Collection of objects is called class. It is a logical entity.
  • 44. Abstraction  Hiding internal details and showing functionality is known as abstraction. For example: phone call, we don't know the internal processing.  In java, we use abstract class and interface to achieve abstraction.
  • 45. Encapsulation  Binding (or wrapping) code and data together into a single unit is known as encapsulation. For example: capsule, it is wrapped with different medicines.  A java class is the example of encapsulation. Java bean is the fully encapsulated class because all the data members are private here.  We can create a fully encapsulated class in java by making all the data members of the class private. Now we can use setter and getter methods to set and get the data in it
  • 46. Inheritance and Polymorphism  Inheritance : When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.
  • 47. When one task is performed by different ways i.e. known as polymorphism. Polymorphism
  • 48. Java Package  A java package is a group of similar types of classes, interfaces and sub-packages.  Package in java can be categorized in two form, built-in package and user-defined package.  There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
  • 49. Advantages of Package  Java package is used to categorize the classes and interfaces so that they can be easily maintained.  Java package provides access protection.  Java package removes naming collision
  • 51. How to access package from another package  There are three ways to access the package from outside the package. 1. Using Package Name.* 2. import package.classname; 3. fully qualified name.
  • 52. Using PackageName.* //save by A.java package pack; public class A{ public void msg() { System.out.println("Hello"); } } //save by B.java package mypack; import pack.*; class B { public static void main(String args[]) { A obj = new A(); obj.msg(); } } Output Hello
  • 53. Using PackageName.ClassName //save by A.java package pack; public class A{ public void msg() { System.out.println("Hello"); } } //save by B.java package mypack; import pack.A; class B { public static void main(String args[]) { A obj = new A(); obj.msg(); } }
  • 54. Using FullyQualified Name //save by A.java package pack; public class A{ public void msg() { System.out.println("Hello"); } } //save by B.java package mypack; class B { public static void main(String args[]) { pack.A obj = new pack.A(); //using fully qualified name obj.msg(); } }
  • 55. Abstract and Interface  Abstract class and Interface both are used to achieve abstraction where we can declared abstract and non-abstract method.  A class which is declared with abstract keyword is called abstract class.  An Interface keyword is used to declare interface.  A class that implement interface must implement all the methods declared in the interface.
  • 56. Access Modifiers in Java  The access modifiers in java specifies accessibility (scope) of a data member, method, constructor or class.  There are many non-access modifiers such as static, abstract etc.
  • 57. default access modifier  If you don't use any modifier, it is treated as default by default. The default modifier is accessible only within package. package pack; class A{ void msg() {System.out.println("Hello");} } //save by A.java package mypack; import pack.*; class B{ public static void main(String args[]) { A obj = new A();//Compile Time Error obj.msg();//Compile Time Error } } //save by B.java In this example, we have created two packages pack and mypack. the scope of class A and its method msg() is default so it cannot be accessed from outside the package.
  • 58. public access modifier  The public access modifier is accessible everywhere. It has the widest scope among all other modifiers. //save by A.java package pack; public class A{ public void msg() { System.out.println("Hello"); } } //save by B.java package mypack; import pack.*; class B{ public static void main(String args[]){ A obj = new A(); obj.msg(); } }
  • 59. private access modifier  The private access modifier is accessible only within class. class A { private int data=40; private void msg() { System.out.println("Hello java"); } } public class Simple{ public static void main(String args[]){ A obj=new A(); System.out.println(obj.data);//Compile Time Error obj.msg();//Compile Time Error } } In this example, we have created two classes A and Simple. A class contains private data member and private method. We are accessing these private members from outside the class, so there is compile time error.
  • 60. protected access modifier The protected access modifier is accessible within package and outside the package but through inheritance only.The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class. In this example, we have created the two packages pack and mypack. The A class of pack package is public, so can be accessed from outside the package. But msg method of this package is declared as protected, so it can be accessed from outside the class only through inheritance. //save by A.java package pack; public class A{ protected void msg() {System.out.println("Hello");} } //save by B.java package mypack; import pack.*; class B extends A{ public static void main(String args[]){ B obj = new B(); obj.msg(); } }
  • 61. Java Array  Java array is an object that contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array.  Array can contains primitives data types as well as objects of a class depending on the definition of array. In case of primitives data types, the actual values are stored in contiguous memory locations. In case of objects of a class, the actual objects are stored in heap segment.
  • 62. Advantage & Disadvantage of Java Array Advantage of Java Array : 1. Code Optimization : It makes the code optimized, we can retrieve or sort the data easily. 2. Random access : We can get any data located at any index position.  Disadvantage of Java Array : 1. Size Limit : We can store only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in java.
  • 63. Creating an Array in java  One-DimensionalArrays: The general form of a one-dimensional array declaration is  type var-name[]; OR type[] var-name;  The element type for the array determines what type of data the array will hold.  Like -- array of int type, we can also create an array of other primitive data types like char, float, double..etc or user defined data type(objects of a class).  // both are valid declarations ---  int intArray[]; or int[] intArray;  intArray is an array variable, no array actually exists. It simply tells to the compiler that this(intArray) variable will hold an array of the integer type. To link intArray with an actual, physical array of integers, you must allocate one using new and assign it to intArray.
  • 64. Instantiating an Array in Java  When an array is declared, only a reference of array is created. To actually create or give memory to array, you create an array like this:  SYNTAX --- : var-name = new type [size];  // Here, type specifies the type of data being allocated, size specifies the number of elements in the array, and var-name is the name of array variable that is linked to the array.
  • 65. Accessing Java Array Elements  The index begins with 0 and ends at (total array size)-1. All the elements of array can be accessed using Java for Loop.
  • 67. Jagged Array  Jagged Array are arrays of arrays with each element of the array holding the reference of other array. These are also known as multidimensional array. Examples: --  A multidimensional array is created by appending one set of square brackets ([]) per dimension.
  • 69. Array Literal  In a situation, where the size of the array and variables of array are already known, array literals can be used.  The length of this array determines the length of the created array.  There is no need to write the new int[] part in the latest versions of Java.
  • 70. Passing Array to Method in java .
  • 71. Iterator interface  Iterator interface provides the facility of iterating the elements in forward direction only.  Methods of Iterator interface : No. Method Description 1 public boolean hasNext() It returns true if iterator has more elements. 2 public Object next() It returns the element and moves the cursor pointer to the next element. 3 public void remove() It removes the last elements returned by the iterator. It is rarely used.
  • 72. Methods of Collection interface . No. Method Description 1 public boolean add(Object element) is used to insert an element in this collection. 2 public boolean addAll(Collection c) is used to insert the specified collection elements in the invoking collection. 3 public boolean remove(Object element) is used to delete an element from this collection. 4 public boolean removeAll(Collection c) is used to delete all the elements of specified collection from the invoking collection. 5 public boolean retainAll(Collection c) is used to delete all the elements of invoking collection except the specified collection. 6 public int size() return the total number of elements in the collection. 7 public void clear() removes the total no of element from the collection. 8 public boolean contains(Object element) is used to search an element. 9 public boolean containsAll(Collection c) is used to search the specified collection in this collection. 10 public Iterator iterator() returns an iterator. 11 public Object[] toArray() converts collection into array. 12 public boolean isEmpty() checks if collection is empty. 13 public boolean equals(Object element) matches two collection. 14 public int hashCode() returns the hashcode number for collection.
  • 74. Collections in Java  Collection represents a single unit of objects i.e. a group.  Collections in java is a framework that provides an architecture to store and manipulate the group of objects.  All the operations that you perform on a data such as searching, sorting, insertion, manipulation, deletion etc. can be performed by Java Collections.  Java Collection framework provides many interfaces (Set, List, Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet etc).
  • 75.  What is framework in java : 1. provides readymade architecture. 2. represents set of classes and interface. 3. is optional.  What is Collection framework : Collection framework represents a unified architecture for storing and manipulating group of objects. It has: 1. Interfaces and its implementations i.e. classes 2. Algorithm
  • 76. Two ways to iterate the elements of collection in java  There are two ways to traverse collection elements: 1. By Iterator interface. 2. By for - each loop.
  • 77. Iterate the elements from collection through foreach loop
  • 78. Iterate the elements from collection through iterator interface
  • 79. Java Non-generic Vs Generic Collection  Java collection framework was non-generic before JDK 1.5. Since 1.5, it is generic.  Java new generic collection allows you to have only one type of object in collection. Now it is type safe so typecasting is not required at run time.  Let's see the old non-generic example of creating java collection. ArrayList al=new ArrayList(); //creating old non-generic arraylist  Let's see the new generic example of creating java collection. ArrayList<String> al=new ArrayList<String>(); //creating new generic arraylist  In generic collection, we specify the type in angular braces. Now ArrayList is forced to have only specified type of objects in it. If you try to add another type of object, it gives compile time error.
  • 80. Type Casting  Assigning a value of one type to a variable of another type is known as Type Casting.
  • 81. Widening Casting(Implicit)  Automatic Type casting take place when,  The two types are compatible  The target type is larger than the source type
  • 82. Narrowing or Explicit type conversion  When you are assigning a larger type value to a variable of smaller type, then you need to perform explicit type casting.
  • 83. Exception and Exception handling What is exception :  Exception is an abnormal condition.  In java, exception is an event that disrupts the normal flow of the program. It is an object which is thrown at runtime. What is exception handling :  The exception handling is a mechanism to handle the runtime errors so that normal flow of the application can be maintained.  such as ClassNotFound, IO, SQL, Remote etc.
  • 84. Types of Exception  There are mainly two types of exceptions:  checked  unchecked  where error is considered as unchecked exception.  The sun microsystem says there are three types of exceptions:  Checked Exception  Unchecked Exception  Error
  • 85. Checked Exception  The classes that extend Throwable class except RuntimeException and Error are known as checked exceptions .  Checked exceptions are checked at compile-time.  Example : IOException, SQLException, ClassNotFound Exception etc
  • 86. Unchecked Exception  The classes that extend RuntimeException are known as unchecked exceptions  Example : ArithmeticException, NullPointerException, NumberFormatException, IndexOutOfBoundsException -- ( ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException ) etc.  Unchecked exceptions are not checked at compile-time rather they are checked at runtime.
  • 87. Error  Error is irrecoverable .  Example : StackOverFlowError, VirtualMachineError, OutOfMemoryError, AssertionError, etc.
  • 88. Common Scenarios Where Unchecked Exception may occur  There are given some scenarios where unchecked exceptions can occur.  They are as follows:  Scenario where ArithmeticException occurs  Scenario where NullPointerException occurs  Scenario where NumberFormatException occurs  Scenario where ArrayIndexOutOfBoundsException occurs  Scenario where StringIndexOutOfBoundsException occurs
  • 89. ArithmeticException  If we divide any number by zero, there occurs an ArithmeticException.  int a=50/0;//ArithmeticException
  • 90. NullPointerException  If we have null value in any variable, performing any operation by the variable occurs an NullPointerException.  //NullPointerException  String s=null; System.out.println(s.length());
  • 91. NumberFormatException  The wrong formatting of any value, may occur NumberFormatException.  Suppose I have a string variable that have characters, converting this variable into digit will occur NumberFormatException.  String s="abc";  int i=Integer.parseInt(s);//NumberFormatException
  • 92. ArrayIndexOutOfBoundsException  If you are inserting any value in the wrong index, it would result ArrayIndexOutOfBoundsException as shown below:  int a[]=new int[5]; a[10]=50; //ArrayIndexOutOfBoundsException
  • 93. StringIndexOutOfBoundException  This exception is thrown by the methods of the String class, in order to indicate that an index is either negative, or greater than the size of the string itself. Moreover, some methods of the String class thrown this exception, when the specified index is equal to the size of the string.
  • 94. Common Scenarios Where checked Exception may occur  Scenario where IOException occurs  Scenario where SQLException occurs  Scenario where ClassNotFound Exception occurs
  • 95. IOException  IOException is the general class of exceptions produced by failed or interrupted I/O Operations.  As This is the checked Exception, It must be handled by the programmer else program does not compile.  Below are some scenarios when IOException would be thrown.  You were reading network file and got disconnected.  Reading Local file which is not available any more.  Using some stream to read the data and some other process closes the stream.  You are trying to read/write a file and don’t have permission  You were writing a file and disk space is not available anymore
  • 96.