Tanya Srivastava - 1619213115
Tanya Srivastava - 1619213115
Tanya Srivastava - 1619213115
On
JAVA
By
TANYA SRIVASTAVA
1619213115
As part of curriculum, and for the partial fulfilment of the requirements for
completion of 4th year B.TECH. from GL Bajaj Institute Of Engineering And
Technology, Greater Noida. The report consists of brief study and description
of Java. All the contents are broadly explained and it is constructed from the
practical basis. All content is the main content that I have recorded and it
contains overall work I have been executing.
Contents
1. Introduction………………………………………………………………………….1-4
1.1. Creation of Java
1.2. Evolution of Java
1.3. Application of Java
1.4. Features of Java
2. Training Work Undertaken………………………………………………………...5-25
2.1. Setting class path for Java
2.2. What is Java?
2.3. Difference between JDK & JRE
2.4. First Java Program
2.5. Datatypes of Java
2.6. Identifiers in Java
2.7. Type Casting
2.8. Variable
2.9. Concept of Array
2.10. Multidimensional Array
2.11. Java Operator
3. Results and Discussions…………………………………………………………26-34
3.1. Introduction to JDBC
3.2. What’s new in JDBC 4.0
3.3. JDBC Driver
4. Conclusion and Future scope…………………………………………………… .35
Bibliography………………………………………………………………………. 36
List of Figures
1.1. Platform
Independent……………………………………………………………………...3
Java is one of the world's most important and widely used computer languages, and it has
held this distinction for many years. Unlike some other computer languages whose influence
has wearied with passage of time, while Java's has grown.
As of 2015, Java is one of the most popular programming languages in use, particularly for
client-server web applications, with a reported 9 million developers using and working on it.
The initial name was Oak but it was renamed to Java in 1995 as OAK was a registered
trademark of another Tech company.
In Java 1.2 Swing and Collection framework was added and suspend (), resume () and stop ()
methods were deprecated from Thread class.
No major changes were made into Java 1.3 but the next release that was Java 1.4 contained
several important changes. Keyword assert, chained exceptions and channel based I/O
System was introduced.
Generics
Annotations
Autoboxing and auto unboxing
Enumerations
For-each Loop
Varargs
Static Import
Formatted I/O
Concurrency utilities
Next major release was Java SE 7 which included many new changes, like :
And the latest addition to the lot is, Java SE 8, it was released on March 18, 2014. Some of the
major new features introduced in JAVA 8 are,
Lambda Expressions
New Collection Package java.util.stream to provide Stream API.
Enhanced Security
Naashon JavaScript Engine included
Parallel Array Sorting
The JDBC-ODBC Bridge has been removed etc.
Java is widely used in every corner of world and of human life. Java is not only used in
softwares but is also widely used in designing hardware controlling software components.
There are more than 930 million JRE downloads each year and 3 billion mobile phones run
java.
Following are some other usage of Java :
The prime reason behind creation of Java was to bring portability and security feature into a
computer language. Beside these two major features, there were many other features that
played an important role in molding out the final form of this outstanding language. Those
features are :
1) Simple
Java is easy to learn and its syntax is quite simple, clean and easy to understand. The
confusing and ambiguous concepts of C++ are either left out in Java or they have been re-
implemented in a cleaner way.
Eg : Pointers and Operator Overloading are not there in java but were an important part of C+
+.
2) Object Oriented
In java everything is Object which has some data and behavior. Java can be easily extended
as it is based on Object Model.
3) Robust
Java makes an effort to eliminate error prone codes by emphasizing mainly on compile time
error checking and runtime checking. But the main areas which Java improved were Memory
Management and mishandled Exceptions by introducing automatic Garbage
Collector and Exception Handling.
4) Platform Independent
Unlike other programming languages such as C, C++ etc. which are compiled into platform
specific machines. Java is guaranteed to be write-once, run-anywhere language.
5) Secure
When it comes to security, Java is always the first choice. With java secure features it enable
us to develop virus free, temper free system. Java program always runs in Java runtime
environment with almost null interaction with system OS, hence it is more secure.
6) Multi-Threading
Java multithreading feature makes it possible to write program that can do many tasks
simultaneously. Benefit of multithreading is that it utilizes same memory and other resources
to execute multiple threads at the same time, like While typing, grammatical errors are
checked along.
7) Architectural Neutral
Compiler generates bytecodes, which have nothing to do with a particular computer
architecture, hence a Java program is easy to interpret on any machine.
8) Portable
Java Byte code can be carried to any platform. No implementation dependent features.
Everything related to storage is predefined, example: size of primitive data types
9) High Performance
Assuming that you have installed Java in C:\ Program files/ Java / JDK directory
Assuming that you have installed Java in C:\program files\ java\ JDK directory, do the following:
Step 1: Edit the C:\autoexec.bat file and add the following line at the end.
Assuming that you have installed Java in C:\program files\ java\ JDK directory, do the
following:
Step 1: Environment variable path should be set to point where java binaries have been
installed. Refer to your shell if you have trouble doing this.
For Example: If you use bash as your shell, then you would add following line to the end.
JVM control execution of every Java program. It enables features such as automated
exception handling, Garbage-collected heap.
JVM Architecture
Fig 2.2. JVM Architecture
Class Loader :
Method area :
Heap :
Stack :
Local variables and partial results are store here. Each thread has a private JVM stack
created when the thread is created.
Program register :
Program register holds the address of JVM instruction currently being executed.
Executive Engine :
Execution engine controls the execute of instructions contained in the methods of the classes.
Native method interface gives an interface between java code and native code during
execution.
Native Libraries consist of files required for the execution of native code.
JRE : The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine,
and other components to run applets and applications written in the Java programming
language. JRE does not contain tools and utilities such as compilers or debuggers for
developing applets and applications.
class Hello
void : It is the return type, meaning this function will not return anything.
main : main() method is the most important method in a Java program. This is the method which
is executed, hence all the logic must be inside the main() method. If a java class is not having a
main() method, it causes compilation error.
String[] args : This represents an array whose type is String and name is args. We will discuss
more about array in Java Array section.
Step 3: Open command prompt and go to the directory where you saved your first java program
assuming it is saved in C:\
Step 4: Type javac Hello.java and press Return(Enter KEY) to compile your code. This
command will call the Java Compiler asking it to compile the specified file. If there are no errors
in the code the command prompt will take you to the next line.
Step 6: You will be able to see Hello world program printed on your command prompt.
After writing your Java program, when you will try to compile it. Compiler will perform some
compilation operation on your program.
After compiling when you will try to run the byte code(.class file), the following steps are
performed at runtime:-
1. Class loader loads the java class. It is subsystem of JVM Java Virtual machine.
2. Byte Code verifier checks the code fragments for illegal codes that can violate access
right to the object.
3. Interpreter reads the byte code stream and then executes the instructions, step by step.
Java language has a rich implementation of data types. Data types specify size and the type of
values that can be stored in an identifier.
In java, data types are classified into two categories :
Once a primitive data type has been declared its type can never change, although in most
cases its value can change. These eight primitive type can be put into four groups.
Integer
byte : It is 1 byte(8-bits) integer data type. Value range from -128 to 127. Default value zero.
example: byte b=10;
short : It is 2 bytes(16-bits) integer data type. Value range from -32768 to 32767. Default
value zero. example: short s=11;
int : It is 4 bytes(32-bits) integer data type. Value range from -2147483648 to 2147483647.
Default value zero. example: int i=10;
long : It is 8 bytes(64-bits) integer data type. Value range from -9,223,372,036,854,775,808
to 9,223,372,036,854,775,807. Default value zero. example: long l=100012;
Floating-Point Number
float : It is 4 bytes(32-bits) float data type. Default value 0.0f. example: float
ff=10.3f;
double : It is 8 bytes(64-bits) float data type. Default value 0.0d. example: double
db=11.123;
Characters:
This group represent char, which represent symbols in a character set, like letters and
numbers.
Boolean:
This group represent Boolean, which is a special type for representing true/false values.
They are defined constant of the language. example: boolean b=true;
Example :
int x = 10;
byte y = (byte)x;
Widening Casting(Implicit)
int i = 100;
When you are assigning a larger type value to a variable of smaller type, then you need to
perform explicit type casting.
Example :
{
double d = 100.04;
2.8. Variable
What is a variable?
When we want to store any information, we store it in an address of the computer. Instead of
remembering the complex address where we have stored our information, we name that
address. The naming of an address is known as variable. Variable is the name of memory
location.
1. Instance variables
2. Static Variables
3. Local Variables
1) Instance variables
Instance variables are variables that are declare inside a class but outside any method,
constructor or block. Instance variable are also variable of object commonly known as field
or property. They are referred as object variable. Each object has its own copy of each
variable and thus, it doesn't effect the instance variable if one object changes the value of the
variable.
class Student
String name;
int age;
2) Static variables
Static are class variables declared with static keyword. Static variables are initialized only
once. Static variables are also used in declaring constant along with final keyword.
class Student
String name;
int age;
Here institute Code is a static variable. Each object of Student class will share instituteCode
property.
Note: A static variable can never be defined inside a method i.e it can never be a local
variable.
Example:
Suppose you make 2 objects of class Student and you change the value of static variable from
one object. Now when you print it from other object, it will display the changed value. This is
because it was declared static i.e it is constant for every object created.
package studytonight;
class Student{
int a;
void change(){
System.out.println(id);
o1.change();
Student.id = 1;
o2.change();
3) Local variables
Local variables are declared in method, constructor or block. Local variables are initialized
when method, constructor or block start and will be destroyed once its end. Local variable
reside in stack. Access modifiers are not used for local variable.
float discount;
discount=price*(20/100);
return discount;
An array can be either primitive or reference type. It gets memory in heap area. Index of
array starts from zero to size-1.
Features of Array
Syntax :
datatype[] identifier;
or
datatype identifier[];
Both are valid syntax for array declaration. But the former is more readable.
Example :
int[ ] arr;
char[ ] arr;
short[ ] arr;
long[ ] arr;
Initialization of Array
Example :
int[] arr = new int[10]; //this creates an empty array named arr of integer type whose size is 10.
or
int[] arr = {10,20,30,40,50}; //this creates an array named arr whose elements are given.
As mention ealier array index starts from 0. To access nth element of an array. Syntax
arrayname[n-1];
Example : To access 4th element of a given array
The above code will print the 4th element of array arr on console.
J2SE 5 introduces special type of for loop called foreach loop to access elements of array.
Using foreach loop you can access complete array sequentially without using index of array.
Let us see an example of foreach loop.
class Test
for(int x : arr)
System.out.println(x);
10
20
30
40
2.10. Multi-Dimensional Array
A multi-dimensional array is very much similar to a single dimensional array. It can have
multiple rows and multiple columns unlike single dimensional array, which can have only
one full row or one full column.
Array Declaration
Syntax:
datatype[ ][ ] identifier;
or
datatype identifier[ ][ ];
Initialization of Array
Example:
or
Syntax:
array_name[m-1][n-1]
Example:
Arithmetic operators
Relation operators
Logical operators
Bitwise operators
Assignment operators
Conditional operators
Arithmetic operators
Arithmetic operators are used in mathematical expression in the same way that are used in
algebra.
Operator Description
% remainder of division
++ Increment operator increases integer value by one
Relation operators
Operator Description
> Check if operand on the left is greater than operand on the right
Logical operators
|| Logical OR (a || b) is true
Java defines several bitwise operators that can be applied to the integer types long, int, short,
char and byte
Operator Description
| Bitwise OR
^ Bitwise exclusive OR
A b a & b a | b a ^ b
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
The bitwise shift operator shifts the bit value. The left operand specifies the value to be
shifted and the right operand specifies the number of positions that the bits in the value are to
be shifted. Both operands have the same precedence.
Example:
a = 0001000
b = 2
a << b = 0100000
a >> b = 0000010
Assignment Operators
+= adds right operand to the left operand and assign the a+=b is same
result to left as a=a+b
-= subtracts right operand from the left operand and assign a-=b is same as
the result to left operand a=a-b
*= mutiply left operand with the right operand and assign a*=b is same
the result to left operand as a=a*b
/= divides left operand with the right operand and assign a/=b is same
the result to left operand as a=a/b
%= calculate modulus using two operands and assign the a%=b is same
result to left operand as a=a%b
Chapter 3
Results and Discussions
JDBC 4.0 is new and advance specification of JDBC. It provides the following advance
features
Connection Management
Auto loading of Driver Interface.
Better exception handling
Support for large object
Annotation in SQL query.
3.3. JDBC Driver
JDBC Driver is required to process SQL requests and generate result. The following are the
different types of driver available in JDBC.
JDBC-ODBC bridge
Advantage
Easy to use
Allow easy connectivity to all database supported by the ODBC Driver.
Disadvantage
This type of driver make use of Java Native Interface(JNI) call on database specific native
client API. These native client API are usually written in C and C++.
Advantage
Disadvantage
This driver translates the JDBC calls into a database server independent and Middleware
server-specific calls. Middleware server further translate JDBC calls into database specific
calls.
Advantage
Disadvantage
Thin Driver
This is Driver called Pure Java Driver because. This driver interact directly with database. It
does not require any native database library, that is why it is also known as Thin Driver.
Fig 3.5. Thin Driver
Advantage
Disadvantage
Java is everywhere: on all platforms and devices and in all countries around the world. It
enables developers to make programs work just about anywhere. And it inspired the
evolution of an incredible technology community. The brilliance of Java is the platform
independency. Thanks to the internet and the community spirit around it, so many people
have been able to make a difference, earn a place in the spotlight with their own framework
or tool, be recognized for their contribution, and really influence the Java world.
With time the importance and popularity of Java is on rise as it has the magic in its
remarkable abilities to innovate and morph as the technology landscape changes. It is still the
most pervasive platform, whether you want to use it for developing smart card applications,
mobile applications, or server-side enterprise applications. One cannot think of any
programming language with a more comprehensive set of APIs. It is a great language for
beginners to start out with, and to continue across the curriculum. It is the language of choice
for developing. Basically, Java is not just a Programming language but it is a programming
atmosphere to develop and deploy enterprise applications. It is important for information
technology industry to develop and create multiple web-based or server based applications to
enhance the industrial competency. There is huge scope for this programming language.
If one talks about job opportunities in field of Java, knowledge of it is required with many
new technologies and roles such as ‘Java-UI Developers’, ’Android Developers’ and many
others. Hence, there are numerous jobs opportunities available in Java, J2EE combining with
other new technologies. These are among the higher paid jobs in IT industry, as it comes
under software development. One should have the proficient skills to get an employment with
IT organizations as many organizations are looking for the professionals, who can manage
multiple projects in J2EE and augments the industrial efficiency.
References
Online lectures.
https://docs.java.org/3/tutorial/