Introduction
Introduction
1. Introduction
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 1
JAVA Means DURGASOFT
Java was Introduced in 1996 January.But it was started by Sun MicroSystems in 1991. At
that time Sun MicroSystems had a requirement to prepare a software electronic consumer
devices in 1991.They need a programming language to prepare those devices.30 members
team with James Gosling & patrickNaughton starts "Green" project.For this project they
need a simple programming language that is simple,tight coded and architectural neutral
programming language.
Ans:The electronic consumer devices with less memory,less power,less execution time the
programming language which is used to prepare these devices must be simple programming
language.
Stack Output:
--------------------------------------------------
JAVA:
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 2
JAVA Means DURGASOFT
Ex:
s.push("A");
s.pop();
s.peep();
-----------------------------
To write less no.of instructions in a programming language,then that is called as tight coded
programming language.It achieving more complex requirements.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 3
JAVA Means DURGASOFT
James Gosling always likes to see a "Oak Tree" through his cabin
window.Immediately he thought to put this "Oak" name for his new programming
language.But his team rejected this name.Because this "Oak PL" is already existed.So all
the Green Project people think a new name for a new Programming language.
Dec 1992:
Then Sun MicroSystems decided to prepare its own browser.So patrik Naughton
and Janadhan paine in 1995,Dec prepared "Hot Java" browser using Java programming
language.
Sun MicroSystems got very good reputation for this "Hot Java Browser". The key
concept for this browser is "Applets" so in January 23,1996--->JDK 1.0 version released.
Java Details:
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 4
JAVA Means DURGASOFT
Java Evolutions:
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 5
JAVA Means DURGASOFT
1.C and C++ are Static programming Languages But Java is a dynamic
programming language:
If any programming language allows memory allocation at compilation time then that
programming language is called as Static programming language.
In C and C++,memory will be allocated for the primitive data Types at compilation time
only.
If any programming language allows memory allocation at runtime then that programming
language is called as Dynamic Programming language.
Ex: JAVA
2.C and C++ are required pre-processor but Java is not required pre-processor:
In case of C and C++,the complete predefined library in the form of header files.
Ex:stdio.h
conio.h
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 6
JAVA Means DURGASOFT
math.h
If we want to include header files in C and C++ applications we have to use "#include<>"
statements.
Ex: #include<stdio.h>
#include<conio.h>
#include<math.h>
In C and C++ applications,it is mandatory to use header files and #include<> statement so
that pre-processor is required in C and C++.
Ex: java.util
java.io
java.net
import java.io.*;
import java.net.*;
when we compile java files compiler will recognize import statements, where compiler will
check whether the specified packages are available or not,if not, compiler will rise an error
like "package java.util does not exist".If the specified package is available in java predefined
library then compiler will not load package content to the memory, at runtime JVM will load
the required classes or interfaces of the specified package, this type of loading is called as
"Dynamic Loading".
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 7
JAVA Means DURGASOFT
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 8
JAVA Means DURGASOFT
3.C and C++ are platform Dependent but Java is platform independent:
If any programming language allows its applications to compile and to execute on the same
operating system then that programming language is called as "Platform Dependent
Programming Language".
If we compile C program on windows operating system then compiler will generate .obj or
.exe file with the same windows operating system representations.If we want to execute C
program then we must require the same windows operating system,this nature of C
programming language is "Platform Dependent Programming Language".
Compilation of “C”
If any programming language allows its applications to compile on one operating system
and to execute on another operating system then that programming language is called as
"Platform InDependent Programming Language".
Ex: JAVA
If we compile Java program on windows operating system then compiler will generate .class
file, it is neutral every operating system, which contains bytecode,it is an intermediate code,
it is not directly executable code. If we want to execute neutral bytecode then we must
require converters to convert neutral bytecode to the local operating system
representations.
To perform the above conversions and to make Java as platform independent programming
language,Sun MicroSystems has provided a tool called as "JVM"[Java Virtual Machine].
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 9
JAVA Means DURGASOFT
Compilation of JAVA
The process of getting variables and methods from one class to another class is called as
Inheritance.
1.Single Inheritance
2.Multiple Inheritance
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 10
JAVA Means DURGASOFT
1.Single Inheritance:
The process of getting variables and methods from only one super class to one or more
no.of subclasses is called as Single Inheritance.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 11
JAVA Means DURGASOFT
2.Multiple Inheritance:
The process of getting variables and methods from more than one super class to one or
more no.of sub classes is called as Multiple Inheritance.
If we declare same variable with different data and same method with different
implementation at both the super classes in multiple inheritance and if access that variable
and that method in sub class then which super class variable will be accessed and which
super class method will be accessed is a confusion state.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 12
JAVA Means DURGASOFT
Java is a simple programming language,it should not allow confusion oriented feature,so
that multiple inheritance is not possible in Java
5.pointers are available in C and C++ but pointers are not possible in JAVA:
1.Pointer variables will be recognized and initialized at the time of compilation, pointer
variables must require static memory allocation but JAVA is following dynamic memory
allocation.
3.Pointer variables are suitable for platform dependent programming language but Java is
platform independent programming language.
4.pointer variables will reduce security for the application data but Java is more secure
programming language,it has to provide very good security for the application data.
5.Pointers will increase confusion to the developers but Java is a simple programming
language, it should not provide confusion to the developers.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 13
JAVA Means DURGASOFT
6.Destructors are required in C++ but Destructors are not required in JAVA:
In Object Oriented Programming language,to create objects we will use "constructor" and to
destroy objects we will use destructors.
In case of C++,developers must take responsibility to create objects and to destroy object,
with this, developers must require both constructors and destructors.
In case of Java, Developers should take responsibility only to create object, not to destroy
objects will be destroyed automatically by an implicit tool called as "Garbage Collector".
Due to the availability of "Garbage Collector" in Java it is not required to use Destructors in
Java.
NOTE:Java has declared some few predefined operators like +,*...as overloaded operators
implicitly,but Java has not given any environment to do operator overloading explicitly at
developers level.
int b=20;
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 14
JAVA Means DURGASOFT
String str1="abc";
String str2="def";
In any programming language,if we pass primitive data as parameters to the methods then
the parameter passing mechanism will be call by value.
In the case of C and C++,if we pass pointer variable as parameter to the methods then the
parameter passing mechanism will be "call be reference" because, pointer variable are able
to store address location directly.
In the case of Java,if we pass reference variables as parameter to the methods then the
parameter passing mechanism will be call by value only,because,in Java application
reference variables are able to store object reference variable value,which is not address
location.
9.In C and C++,2 bytes of memory is allocated for integer and 1 byte of
memory is allocated for characters but in Java 4 bytes of memory is allocated
for integers and 2 bytes of memory is allocated for character.
In general,in C and C++,memory allocation for the primitive dataTypes is not fixed,which is
variable depending on type of operating system which we used.
In case of Java,memory allocation for the primitive dataTypes is fixed irrespective of the
operating system which we used.In case of Java,4 bytes of memory is allocated for integers
and 2 bytes of memory is allocated for characters.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 15
JAVA Means DURGASOFT
Java Features:
To expose the nature of Java, Java has given the following features:
1.Simple
2.Object Oriented
3.platform Independent
4.Arch.Neutral
5.Portable
6.Robust
7.Secure
8.Dynamic
9.Distributed
10.Multi Threaded
11.Interpretive
12.HighPerformance
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 16
JAVA Means DURGASOFT
1.Simple:
Java has eliminated all the confusion oriented features like multiple inheritance,operator
overloading,pointers...
Java applications will take less memory and less execution time.
2.Object-Oriented:
Java is Object-Oriented Programming language,because it able to store the data in the form
of objects.
3.platform Independent:
4.Arch.Neutral:
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 17
JAVA Means DURGASOFT
5.Portable:
Java is portable programming language because it able to allow its applications on any
operating system and also to execute on any hardware system.
6.Robust:
If any programming languages is having very good at memory management system and
also exception handling features then that programming language is called as Robust
programming language.
java is having very good at exception handling mechanisms due to the availability of very
good predefined library to represent each and every exceptional features.
7.Secure:
Java has provided implementation for all the network security algorithm to provide network
security.
8.Distributed:
If we design any Java application with out using client-server arch. then that
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 18
JAVA Means DURGASOFT
9.Multi-Threaded:
Single Thread Model will allow only one thread at a time to perform tasks,it increase
execution time,it decrease application performance.
Multi Thread model is able to allow to create and execute more then one thread at a time,
Java is a multi threaded programming language,it will provide very good environment to
design and execute more than one thread at a time.
11.Interpretive:
1)To check use provided syntax voilations we must require compilation for Java program.
12.HighPerformance:
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 19
JAVA Means DURGASOFT
Java is a high performance programming language due to its rich set of features like
Robust,Dynamic,Secure,object oriented,platform Independent...
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 20
JAVA Means DURGASOFT
Comment Section:
Syntax:
//------description-------
Syntax:
/*
----
---Description----
----
*/
3.Documentation Comment:
Syntax:
/*
*---------------
--------
*-------
*/
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 21
JAVA Means DURGASOFT
In general we will utilize documentation comment to prepare API documentation but it is not
suggestable or recommended.
To simply API documentation,JAVA has provided a predefined tool in the form "javadoc".
C:\abc\Employee.java
c:\abc>javadoc Employee.java
In java applications,to describe metadata JDK5.0 version has provided a new feature called
as "Annotation".
Ans:In java applications,if we provide metadata by using comments then that metadata will
be available upto .java file,it will not be available upto .class files and upto RUNTIME of our
application,because,LexicalAnalyzer will remove the provided commented metadata from
Java application as part of compliation.
As per the application requirement,if we want to bring the metadat upto .java file,upto
.class file and upto RUNTIME of our application then we have to use "Annotation".
Q)In Java applications to provide metadata at runtime we are able to use XML
documents but what is the requirement to go for annotations?
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 22
JAVA Means DURGASOFT
Ans:To provide metadata upto runtime of our java applications if we use XML documents
then we are able to get following problems:
2)We have to check whether XML documents are located properly or not.
3)We have to check whether XML tags are formatted properly or not.
4)We have to check whether we are using right parsing mechanism or not to access the
data from XML documents.
To Overcome all the above problems we have to use a java alternative that is
"Annotations".
Example:
If we want to design any servlet by using XML document then we have to provide almost all
10 lines of code in XML file.
web.xml:
<web-app>
<servlet>
<servlet-name>ls</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ls</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 23
JAVA Means DURGASOFT
LoginServlet.java
--------
If we design any servlet by using annotations then it is sufficient to provide only one line of
java code[Annotation]
@webServlet("/login")
--------------------
NOTE:In JAVA/J2EE applications,we can utilize annotations as an alternative for XML tech or
XML documents.
2.Package Section:
1.Modularity
2.Abstraction
3.Security
4.Sharability
5.Re usability
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 24
JAVA Means DURGASOFT
1.Predefined packages
Ex: java.io
java.util
java.awt
2.User-defined Package
If we want to declare user defined packages in java programme then we have to use
the following Syntax.
package Package_Name;
Where package_Name must be unique,it should not be duplicated and it should not
be sharable.
To provide package names,Java has a given convention like to include our company
domain name in reverse.
Ex:
package com.durgasoft.icici.transaction;
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 25
JAVA Means DURGASOFT
transaction---->module name
Ans:No,it is not possible to provide more than one package declaration statements
with in a single java file,because,always package declaration statement must be first
statement in java file
Ex:
abc.java
package p1;----valid
package p2;--->Invalid
package p3;--->Invalid
import Section:
In general,we are able to design java applications by distributing all the classes and
interfaces over multiple no of packages.
In the above context,if we want to use a particular package classes and interfaces in
the present java file,first,we have to make available that package provided classes
and interfaces to present java file.
To make available a particular package provided classes and interfaces to the
present java file,we have to import the respective package to present java file
To import a particular package into present java file,we have to use the following
syntaxes.
import package_Name.*;
It will import all the classes and intefaces from the specified package.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 26
JAVA Means DURGASOFT
Ex:
import java.io.*;
import package_Name.Member_Name;
It will import only the specified class or interface from the specified package.
Ex:
import java.io.BufferedReader
Ans:No,It is not mandatory to import packages in java file inorder to use the classes and
interfaces of a particular package,because it is possible to use classes by using their fully
qualified names without using "import" statements.
Ex:java.io.BufferedReader,java.util.ArrayList
import java.io.*;
NOTE:In java files,we are able to provide at most one package declaration
statement but we are able to provide more than one import statement.
classes/interfaces section:
In java applications,the main purpose of classes and interfaces is to represent all real
world entities like Persons,Animals,Students,Customers,Account....
In java program,to write classes and interfaces we have to use classes/interfaces
section.
In java files,we are not having any restrictions about the no classes and interfaces,it
is possible to provide any no of classes and interfaces with in a single java file but it
is suggestable to provide one class or one interface per java file.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 27
JAVA Means DURGASOFT
Note:In java,a single .java file may contains more than one class but a
single .class file contains only one class or one interface.
2.To define starting point and ending point for the application execution.
In java applications,we will provide main() method in a class called as "Main Class",it
is mandatory for each and every java application beacuse main() method is
mandatory to start application execution.
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 28
JAVA Means DURGASOFT
DURGA SOFTWARE SOLUTIONS ,202 HUDA Maitrivanam, Ameerpet , Hyd. Ph: 040-64512786 Page 29