Professional Documents
Culture Documents
___________________________________________________________________________________________________
Copyrights Reserved Page 1 of 18
Topics Covered
Introduction to Java
Data Types Variables
Array Operators
Control Statements and
Introduction to Classes
___________________________________________________________________________________________________
Copyrights Reserved Page 2 of 18
Introduction to Java
Java programming language is being used for programming web applications. It is
also widely used for mobile and electronic items. Java is a high-level object-oriented
programming language developed by the Sun Microsystems. Though it is associated with
the World Wide Web but it is older than the origin of Web.
History of Java :
In the early 90s, extending the power of network computing to the activities of
everyday life was a radical vision. In 1991, a small group of Sun engineers called the "Green
Team" believed that the next wave in computing was the union of digital consumer devices
and computers. Led by James Gosling, the team worked around the clock and created the
programming language that would revolutionize our world – Java.
The Green Team demonstrated their new language with an interactive, handheld
home-entertainment controller that was originally targeted at the digital cable television
industry. Unfortunately, the concept was much too advanced for the them at the time. But it
was just right for the Internet, which was just starting to take off. In 1995, the team
announced that the Netscape Navigator Internet browser would incorporate Java technology.
Today, Java not only permeates the Internet, but also is the invisible force behind many
of the applications and devises that power our day-to-day lives. From mobile phones to
handheld devises, games and navigation systems to e-business solutions, Java is everywhere!
___________________________________________________________________________________________________
Copyrights Reserved Page 3 of 18
Complex Data Structures, unions Structures, unions, Classes
Types classes
Automatic Yes, with warnings if Yes, with warnings if Not at all if loss
coercions loss could occur loss could occur could occur; must
cast explicitly
Features of Java :
Object-oriented
Simpler language
___________________________________________________________________________________________________
Copyrights Reserved Page 4 of 18
Compared to earlier OO languages like C++, it is simple
Designed considering the pitfalls of earlier languages
Robust
Architecture Neutral / Portable :
Java code compiled on Windows can be run on Unix without recompilation
Secure :
Built -in security features like absence of pointers and confinement of the java program
within its runtime environment.
Support for Multi-threading at language level
Designed to handle Distributed applications
___________________________________________________________________________________________________
Copyrights Reserved Page 5 of 18
a) Java SE :
Java SE or Java Standard Edition provides tools and API's that you can use to create
server applications, desktop applications, and even applets. These programs developed using
Java SE can be run on almost every popular operating system, including Linux, Macintosh,
Solaris, and Windows.
b) JEE :
Based on the foundation framework of the standard edition, Java Enterprise Edition
helps in web application service, component model and enterprise class service oriented
architecture (SOA).
c) JME :
Java Micro Edition or JME for short is an accumulation of Java APIs that are used for
the development of software for devices like mobile phones, PDAs, TV set-top boxes, game
programming. The platform of micro edition generally consists of an easy user interface, a
robust security model and a wide variety of built-in networks for running Java based
application.
New Features in SE 6 :
Here are the list of new Features added to the JDK 6.
1. Changes in I/O 10. Enhancements in java.lang.Class and
___________________________________________________________________________________________________
Copyrights Reserved Page 6 of 18
2. Collections Framework Enhancement java.lang.reflect
3. Changes in jar and zip 11. Enhancement in RMI for JDKTM 6
4. Java Web Start enhancements in 12. JAVA SE 6 Security Enhancements
version 6 13. Serialization Changes and
5. JMX API Enhancements Enhancements in JAVA SE
Development Kit 6
6. Java Platform Debugger Architecture
Enhancements 14. JavaTM Virtual Machine Technology
7. Java SE 6 Monitoring and 15. Scripting for the Java Platform
Management Enhancements 16. Leveraging Security in the Native
8. New Package java.util.spi in JDK 6 Platform Using Java SE 6 Technology
9. Networking features and 17. JAX-Web Services 2.0 With the Java
enhancements in Java SE version 6.0 SE 6 Platform
Java Tool :
To commence with Java programming, significance of Java Compiler.
Java Compiler :
Java Interpreter :
___________________________________________________________________________________________________
Copyrights Reserved Page 7 of 18
Java Debugger :
Java debugger helps in finding and the fixing of bugs in Java language programs. The
Java debugger is denoted as jdb. It works like a command-line debugger for Java classes.
Java (Header File Generator) :
In Java programming we need to implement some native methods. You must be
wondering about what's native methods.
Firstly, The native methods are in pure C code, not C++. The function prototypes are in
an object-oriented form of C which are being provided by java , but they are still not object
methods. Secondly, We can call native methods applications only. However due to some
security reasons, we cannot call applets from native methods. Thirdly, native methods are
platform-specific. This is the most important point to remember, you have to build a
dynamically loadable library to link your java application with the native operating system
(Windows OS, Machintosh, Linux, Unix ..). For each native platform your application targets,
a dynamically loadable library is needed to be shipped.. That means any system-specific code
has to be ported along with the java code.
Javadoc (Documentation):
This tool is used to generate API documentation into HTML format from Java source
code. It is interesting to know that Javadoc is the industry standard for documenting Java
classes.
Compile and Run a Java Program :
This tutorial will take you step by step through the process of writing a java program,
compiling and running it. The best way to learn is to compile and run these programs
yourself. Comments such as /* this is a comment */ or // this is another comment are
inserted to explain what does the line of code do. The programs are kept simple for the
purpose of concentrating on the main idea in question.
Type the following program and save it in a file with the name "First.java"
___________________________________________________________________________________________________
Copyrights Reserved Page 8 of 18
/*
This is my first java program
*/
// This is the class definition, First is the name of the class
class First{
// this program will begin with a call to main() defined as follows
public static void main(String args[]){
System.out.println("My first java program");
}
}
Compile the First program as follows
c:\jdk\application>javac First.java
The java compiler creates a file called First.class in the directory application. This
class contains the program but in bytecode form ready to run.
Run the program as follows
c:\jdk\application>java First
The output of this program is : My first java program
NOTE :
1-java is case sensitive, first is different from First.
2-By convention the name of the file should match the name of the class.
Private Data members and methods All members within the same
Class only
(No keyword, usually we call Data members, methods, All classes in the same
it default) classes and interfaces package
Protected Data members and methods All classes in the same
package as well as all sub
classes ie even sub classes
residing in a
___________________________________________________________________________________________________
Copyrights Reserved Page 10 of 18
The 'main' method :
Java objects are used in one of two ways. The most common way is as a programming
component that is instantiated by another program. However, some objects are endowed
with the ability to be run as programs (it has to start running somewhere!). This is achieved
by putting a 'main' method in the object. Thus:
// Hello World
class HelloWorld {
private static void main (String[] args){
System.out.println("Hello, world!");
}
}
will result in a Java program that can be run and will print out 'Hello, world!'.
Build path :
When the Java compiler compiles the program from the source code as you've typed it
into code that can be run using a Java capable machine it needs to know where all of the
requisite pieces are. This is typically done in one of several ways. One way is that the
necessary files can all be placed in the same directory as the files you're writing, but this is a
difficult way to manage projects. As a second method, the compiler, when run from a
command line, allows a command line option to be entered that defines the "classpath",
which lists all directories that should be 'checked' for pieces needed by your code. A third
method allows a system variable to be defined that stores the 'classpath' permanently. A
fourth method is perhaps the simplest: the development environment can be configured to
examine a given build path. This is of special importance because libraries of pre-made Java
objects are often distributed and can be stored once and used in many different Java projects
simply by setting the build path.
API Specifications :
Java classes are documented using an API specification; API stands for Application
Programming Interface, and it provides the documentation necessary to make use of the
pieces that a collection of Java code provides. Of greatest importance, the Java language itself,
aside from core elements like syntax and data types, is described by the API that documents
all of the Java objects (like Vector, mentioned above) that are available in the core Java
environment.
Data Types :
___________________________________________________________________________________________________
Copyrights Reserved Page 11 of 18
Type Range
Operators :
The following are the operators supported by the Java programming language.
Simple Assignment Operator :
= Simple assignment operator
___________________________________________________________________________________________________
Copyrights Reserved Page 12 of 18
Arithmetic Operators :
+ Additive operator (also used for String concatenation)
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator
Unary Operators :
+ Unary plus operator; indicates positive value (numbers are positive
without this, however)
- Unary minus operator; negates an expression
++ Increment operator; increments a value by 1
-- Decrement operator; decrements a value by 1
! Logical compliment operator; inverts the value of a boolean
Equality and Relational Operators :
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Conditional Operators :
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for if-then-else statement)
Type Comparison Operator :
instanceof Compares an object to a specified type
Bitwise and Bit Shift Operators :
~ Unary bitwise complement
<< Signed left shift
>> Signed right shift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
___________________________________________________________________________________________________
Copyrights Reserved Page 13 of 18
| Bitwise inclusive OR
Arrays :
An array is a container object that holds a fixed number of values of a single type. The
length of an array is established when the array is created. After creation, its length is fixed.
You've seen an example of arrays already, in the main method of the "Hello World!"
application. This section discusses arrays in greater detail.
Summary of Introduction:
History of Java
Comparing C, C++ and Java:
Basics of Java Technology
Different Editions and Releases of Java Technology
Java Tool
Compile and Run a Java Program
Command Line Arguments
Polymorphism
Inheritance
___________________________________________________________________________________________________
Copyrights Reserved Page 14 of 18
Packages
Access specifiers
Jar Files
Data Types
SESSION : I
1. What is Oops?
2. What is Java?
3. How many types of comments are used in Java?
4. What is a Keywords, Data types, Control Statements, Operators in java ?
5. What are the primitives data types and wrapper classes?
6. What is the argument type of a program's main() method And what is its return type?
Step1:
class HelloWorld {
___________________________________________________________________________________________________
Copyrights Reserved Page 17 of 18
Reference Book
___________________________________________________________________________________________________
Copyrights Reserved Page 18 of 18