1 +introduction
1 +introduction
Introduction
1 http://youtube.com/durgasoftware
Core Java
Java History
Java Details
Home : SUN Mc Systems (Oracle Corporation)
Author : James Gosling
Objective : To prepare simple electronic consumer goods.
Project : Green
First Version : JDK 1.0 (1996, Jan-23rd)
Used Version : Some org JDK5.0, Some other JAVA 6, JAVA 7
Latest Version : JAVA7, JAVA8, This April – JAVA 9
Type of Software : Open Source Software
Strong Features : Object-oriented, Platform Independent, Robust, Portable, Dynamic,
Secure.......
2 http://youtube.com/durgasoftware
Core Java
3 http://youtube.com/durgasoftware
Core Java
In C and C++ applications, memory will be allocated for primitive data types at
compilation time only, not at runtime.
If any programming language allows memory allocation for primitive data types at
runtime, not at compilation time then that programming language is called as Dynamic
Programming Language.
EX: JAVA
In java applications, memory will be allocated for primitive data types at runtime only, not
at compilation time.
Note: In Java applications, memory will be allocated for primitive data types at the time of
creating objects only, in java applications, objects are created at runtime only.
EX:
stdio.h
conio.h
math.h
---
----
4 http://youtube.com/durgasoftware
Core Java
If we want to use predefined library in C and C++ applications, we have to include header
files in C and C++ applications, for this, we have to use #include<> statement.
EX:
#include<stdio.h>
#include<conio.h>
#include<math.h>
If we compile C and C++ applications then Pre-Processor will perform the following
actions.
5 http://youtube.com/durgasoftware
Core Java
In java , the complete predefined library is provided in the form of classes and interfaces
in packages
EX:
java.io
java.util
java.sql
If we want to use predefined library in java applications then we have to include packages
in java application, for this we have to use "import" statements
EX:
import java.io.*;
import java.util.*;
import java.sql.*;
If we compile java program then compiler will perform the following actions.
While executing java program, when JVM[Java Virtual Machine] encounter any class or
interface from the specified package then only JVM will load the required classes and
interfaces to the memory at runtime, loading predefined library at runtime is called as
"Dynamic Loading".
Pre-Processor is not required in JAVA , because, java does not include header files and
#include<> statements, alternativily, JAVA has clases and interfaces in the form of
packages and import statements.
6 http://youtube.com/durgasoftware
Core Java
2. #include<> statements are used to include the predefined library which is available in
the form of header files.
import statements are used to include the predefined library which are available in the
form of packages.
5. By using Single #include<> statement we are able to include only one header file.
EX:
#include<stdio.h>
#include<conio.h>
#include<math.h>
By using single import statement we are able to include more than one class or more
than one interface of the same package.
8 http://youtube.com/durgasoftware
Core Java
Q)What are the differences between .exe file and .class file?
1. .exe file is available upto C and C++ only.
.class file is available upto Java.
In C and C++, to manipulate data through memory locations , C and C++ have provided a
type of varable called as "Pointer" variable.
Pointer is a variable in C and C++, it able to store address locations of the data structers,
where Data Structer may be a variable, an array, a struct, or may be another pointer
variable.
2. Pointer variables are able to refer a block of memory by storing its address locations.
Reference variables are able to refer a block of memory (Object) by storing object
reference values, where Object reference value is hexa decimal form of hashcode,
where hashcode is an unique identity provided by Heap manager.
9 http://youtube.com/durgasoftware
Core Java
From the above 7 Object Oriented Features, the following features are most powerfull
features.
1. Encapsulation
2. Abstraction
3. Inheritance
4. Polymorphism
10 http://youtube.com/durgasoftware
Core Java
EX:
class Employee{ // Super class
int eno;
String ename;
float esal;
String eaddr;
---
----
}
On the basis of the above two types of inheritances, three more Inheritances are defined.
3. Multi Level inheritance.
4. Hierarchical Inheritance.
5. Hybrid Inheritance.
11 http://youtube.com/durgasoftware
Core Java
If we declare same variable with different values and same method with different
implementatiuon in both the super classes and if we access that common variable and
method at sub class then which super class variable and method will be accessed is big
confusion for the compiler and JVM, JAVA is simple pl, it will not allow any confusion
oriented features, so JAVA does not allow Multiple Inheritances.
Note: Java define "extends" keyword in such a way to allow only ne super class name , not
to allow more than one super class name.
12 http://youtube.com/durgasoftware
Core Java
In Java, to destroy objects automatically , JAVA has provided an internal component called
as "Garbage Collector", it will destroy unused objects in Java applications.
In C++, Developers are responsible to destroy Objects, because, in C++ Garbage Collector
kind of component is not existed, Therefore Developers must use "Destructors" todestroy
objects.
1. Class
2. Object
3. Encapsulation
4. Abstraction
5. Inheritance
6. Polymorphism
7. Message Passing
From the above list of Object oriented Features the following features are the most
powerfull features.
1. Encapsulation
2. Abstration
3. Inheritance
4. Polymorphism
13 http://youtube.com/durgasoftware
Core Java
Polymorphism:
--> "Polymorphism" is a Greak word, where Poly means Many and Morphism means
Structers / Forms.
--> If one thing is existed in more than one form then it is called as "Polymorphism".
--> The main advantage of Polymorphism is "Flexibility".
--> There are two types of Polymorphisms.
1. Static Polymorphism
2. Dynamic Polymorphism
1. Static Polymorphism:
--> If the Polymorphism is existed at compilation time then it is called as Static
Polymorphism.
EX: Overlooading
2. Dynamic Polymorphism:
--> If the Polymorphism is existed at runtime then that Polymorphism is called as Dynamic
Polymorphism.
EX: Overridding
Overloading:
--> There are two types of overloadings.
1. Method Overloading
2. Operator Overloading
1. Method Overloading:
--> If we declare more than one method / Function with the same name and with different
parameter list then it is
called as Method Overloading.
EX:
---
class A{
void add(int i, int j){
---implementation integer addition----
}
void add(float f1, float f2){
---implementation for Float Addition----
}
void add(String str1, String str2){
---Concatination on two String values----
}
}
14 http://youtube.com/durgasoftware
Core Java
2. Operator Overloading:
--> If we declare any operator with more than one functionality then it is called as
Operator Overloading.
EX:
int a = 10;
int b = 20;
int c = a + b; // + is for Arithmetic Addition.
System.out.println(c); //30
Note: As per JAVA internal requirement, JAVA has defined some of the predefined
operators as overloaded Operators with fixed functionalities, but, JAVA has not given any
env to define operator overloading explicitly at developer level.
EX: +, *, %,..
In any PL, if we pass address locations as parameters to the methods then the parameter
passing mechanism is "Call By Reference" Parameter Passing Mechanism.
In C and C++, if we pass pointer variables as parameters to the methods or functions then
the parameter passing mechanism is "Call By Reference", because, Pointer variables are
able to store address locations.
15 http://youtube.com/durgasoftware
Core Java
In Java, if we pass reference variable as parameter to the methods or functions then the
parameter passing mechanism is "Call By Value" only, because, in JAVA, reference
variables are not storing address locations, reference variables are able to store Object
reference value, where Object reference value is hexa decimal form of Hashcode, where
Hashcode is an integer value provided by Heap manager as an unique identity for each
and every object.
In Java, memory allocation for the primitive data types is fixed irrespective of the
Operating System which we used.
In Java, all characters are represented in the form of UNICODE values, where to store
UNICODE values one byte of memory is not sufficient, we must provide 2 bytes of memroy
for characters.
16 http://youtube.com/durgasoftware
Core Java
--> I have a software product, it has customers all over India, All Indians are able to
understasnd English, so i provided all the product Services in the form of English. One fine
day, i found Customers from Japan, Germany, Itly,..... and these customers are not good in
English and they are not undestanding my product services .
Solutions
1. Can i prepare a seperate Product for each and every customer language ---> Not
Suggestible.
2. Single product, but, it has to understand Customer Locality and it has to give services as
per customer locality
in customer understandable language.
Note: Java isa able to provide very good Internationalization support because of
UNICODE representation only.
17 http://youtube.com/durgasoftware
Core Java
Java Features
To show the nature of java programming language, JAVA has provided the following
features.
1) Simple
2) Object Oriented
3) Platform independent
4) Arch Nuetral
5) Portable
6) Robust
7) Secure
8) Dynamic
9) Distributed
10) Multi Threadded
11) Interpretive
12) High Performance
1) Simple:
Java is simple programming language, because,
1) Java applications will take less memory and less execution time.
2) Java has removed all most all the confusion oriented features like pointers,
multiple inheritance,.....
3) Java is using all the simplified syntaxes from C and C++.
2) Object Oriented:
Java is an object oriented programming language, because, JAVA is able to store data
in the form of Objects only.
3) Platform Independent:
Java is platform independent programming Language, because, Java allows its
applications to compile on one operating system and to execute on another operating
system.
4) Arch Nuetral:
Java is an Arch Nuetral Programming language, because, Java allows its applications to
compile on one H/W Arch and to execute on another H/W Arch.
5) Portable:
Java is a portable programming language, because, JAVA is able to run its applications
under all the operating systems and under all the H/W Systems.
18 http://youtube.com/durgasoftware
Core Java
6) Robust:
Java is Robust programming language, because,
1) Java is having very good memory management system in the form of heap memory
Management SYstem, it is a dynamic memory management system, it allocates
and deallocates memory for the objects at runtime.
2) JAVA is having very good Exception Handling mechanisms, because, Java has
provided very good predefined library to represent and handle almost all the
frequently generated exceptions in java applications.
7) Secure:
Java is very good Secure programming language, because,
1) JAVA has provided an implicit component inside JVM in the form of "Security
Manager" to provide implicit security.
2) JAVA has provided a seperate middleware service in the form of JAAS [Java
Authetication And Autherization Service] inorder to provide web security.
3) Java has provided very good predefined implementations for almost all well known
network security alg.
8) Dynamic:
If any programming language allows memory allocation for primitive data types at
RUNTIME then that programming language is called as Dynamic Programming
Language.
9) Distributed:
By using JAVA we are able to prepare two types of applications
1) Standalone Applications
2) Distributed Applications
1) Standalone Applications:
If we design any java application with out using client-Server arch then that java
application is called as Standalone application.
19 http://youtube.com/durgasoftware
Core Java
2) Distributed Applications:
If we design any java application on the basis of client-server arch then that java
application is called as Distributed application.
To prepare Distributed applications, JAVA has provided a seperate module that is
"J2EE/JAVA EE".
JAVA is following Multi Thread Model, JAVA is able to provide very good environment
to create and execute more than one thread at a time, due to this reason, JAVA is
Multi threaded Programming Language.
11) Interpretive:
JAVA is both compilative programming language and Interpretive programming
language.
20 http://youtube.com/durgasoftware
Core Java
To use lower case letters and Upper case letters seperatly in java applications, JAVA has
provided the following conventions.
All class names , abstract class names, interface names and enum names must be started
with upper case letter and the sub sequent symbols must also be upper case letters.
EX:
String
StringBuffer
InputStreamReader
All java variables must be started with lower case letters, but, the subsequent symbols
must be upper case letters.
EX:
in, out, err
pageContext, bodyContent
All java methods must start with lower case letter , but, the sub sequent symbols must be
upper case letters
EX:
concat(--)
forName(--)
getInputStream()
Note: All the above conventions are mandatory for predefined library, they are optional
form User defined library, but, suggestible.
21 http://youtube.com/durgasoftware
Core Java
EX:
1)String str=new String("abc"); ----> Valid
2)string str=new string("abc");-----> Invalid
3)class Employee{ ----> Valid and Suggestible
---
}
1) Comment Section
2) Package Section
3) Import Section
4) Classes/Interfaces Section
5) Main Class Section
1.Comment Section:
Before starting implementation part, it is convention to provide some description about
our implementation, here to provide description about our implementation we have to
use Comment Section. Description includes author name, Objective, project details,
module details, client details,......
To provide the above specified description in comment section, we will use comments.
Syntax:
// --- description------
22 http://youtube.com/durgasoftware
Core Java
Syntax:
/*
---
--description-----
----
*/
3.Documentation Comment.
It allows description in more than one page.
Syntax:
/*
*----
*----
---
---
*----
*/
Note: We will use documentation comments to prepare API kind of documentations, but,
it is not suggestible.
EX: Employee.java
17) }
18) publc void delete(String eid) {
19) ---
20) }
21) }
Employee.txt[html/pdf]
2)Name: ename
Data Type: String
Access Mod: public
----
----
Methods: 1)Name: add
Return type: void
access mod: public
parameters: eid, ename, esal, eaddr
------
Constructors: 1)Employee
----
To simpify API documentation for JAVA applications, JAVA has provided an implicit
command , that is, "javadoc".
On Command Prompt:
D:\javaapps>javadoc Employee.java
--- Generating xxx.html files----
Note: If we provide metadata with comments then we are unable to access that metadata
programatically, but, if we provide metadata with Annotations then we are able to access
that metadata through java program.
To overcome all the above problems we need a java alternative , that is, Annotations.
25 http://youtube.com/durgasoftware
Core Java
2)Package Section:
1.Package is the collection of related classes and interfaces as a single unit.
2.Package is a folder contains .class files representing related classes and interfaces.
1) Modularity
2) Abstraction
3) Security
4) Reusability
5) Sharability
1) Predefined Packages
2) User defined Packages
1.Predefined Packages:
These packages are provided by Java programming language along with java software.
EX: java.io
java.util
java.sql
----
----
26 http://youtube.com/durgasoftware
Core Java
EX:
package p1;
package p1.p2.p3;
If we want to use package declaration statement in java files then we have to use the
following two condition.
1.Package declaration statement must be the first statement in java file after the
comment section.
2.Package name must be unique, it must not be sharable and it must not be duplicated.
abc.java
EX: www.durgasoft.com
durgasoft.com
com.durgasoft
package com.durgasoft.icici.transactions.deposit;
com.durgasoft---> company domain name in reverse.
icici ----------> project name/ client name
transactions----> module name
deposit---------> sub module
3.Import Section:
The main intention of "import" statement is to make available classes and interfaces of a
particular package into the present JAVA file inorder to use in present java file.
Syntax 1:
import package_Name.*;
--> It able to import all the classes and interfaces of the specified package into the present
java file.
27 http://youtube.com/durgasoftware
Core Java
Syntax 2:
import package_Name.Member_Name;
--> It able to import only the specified member from the specified package into the
present java file.
abc.java
package p1;
//package p2;-----> Error
//package p3;-----> Error
import java.io.*;
import java.util.*;--> No Error
import java.sql.*;---> No Error
---
----
---
Note: Specifying class names or interface names along with their respective package
names is called as "Fully Qualified Names".
EX: java.io.BufferedReader
java.util.ArrayList
java.sql.Connection
28 http://youtube.com/durgasoftware
Core Java
----
----
4.Classes/Interfaces Section:
The main intention of classes and interfaces is to repersent all real world entities in the
form of coding part.
EX: Account, Employee, Product, Customer, Student,......
Syntax:
public static void main(String[] args){
----instructions----
}
Note:main() method is a conventional method with fixed prototype and with user defined
implementation part.
29 http://youtube.com/durgasoftware