Title: Introduction to Java
1Introduction to Java
2History of Java Brief Overview
- May 23, 1995
- Sun formally announces Java and HotJava at
SunWorld '95. - May 23, 1995
- Netscape announces its intention to license Java
for use in Netscape browser. - September 21, 1995
- Sun-sponsored Java development conference held in
New York City. - September 25, 1995
- Sun announces expanded alliance with Toshiba and
a joint project to develop remote information
retrieval products which incorporate Java. - September 26, 1995
- Sunsoft announces suite of business-oriented
development products incorporating Java. - October 30, 1995
- At the Internet World Conference in Boston, Lotus
Development Corp., Intuit Inc., Borland
International Inc., Macromedia Inc.,and Spyglass
Inc. announce plans to license Java.
3History, cont.
December 4, 1995 Sun and Netscape announce
Javascript, a scripting language based on the
Java language which is designed to be accessible
to non-programmers. December 4, 1995 Sun,
Netscape and Silicon Graphics announce new
software alliance to develop Internet
interactivity tools. December 4, 1995 Borland,
Mitsubishi Electronics, Sybase and Symatec
announce plans to license Java. December 6, 1995
IBM and Adobe announce licensing agreement with
Sun for use of Java. December 7, 1995 Microsoft
announces plans to license Java during
announcement of suite of new Internet products,
including Visual Basic Script.
4Why Program in Java?
- Easy to learn and use, unlike C and other
programming languages - Code is portable
- Solves the problem of cross-platform application
development - Can be extended to to do anything the machine can
do - Suitable for building large applications
- Is an OOP (object-oriented programming) language
- Gives you the ability to to develop complex
programs in a systematic, modular manner. - You can create modules that can be used over and
over in a variety of programs. - These modules group related data and instructions
for performing actions on the data.
5Objects and Classes
- Objects consist of related data and the
instructions for performing actions on that data - The design for an object is called a class.
- Classes define the type of data and actions that
will be associated with an object of that class,
but not the actual data for an individual object. - Classes are required to create objects.
- Many objects of the same class may be needed in
an application.
Class
Objects
DVD class title genre year
Shrek Comedy 2001
Coach Carter Drama 2005
A class can be used to create many objects each
object will have the same type of data and
possible actions, but each object maintains its
own set of data.
6Packages
- A package, also called a library, is a group of
related classes. - An example may be a package which contains
classes related to a particular task, such as
input and output.
7An application is also contained in a package.
It contains a controlling class and can contain
other classes
Packages are importable an application can use
classes from another package
8A Java Application a package with at least one
class that contains a main() method
/ SchoolAddress.java Mrs. Seiy
September This program displays the school
name and address on the screen / package
firstApplication / The SchoolAddress class
displays the school name and address on the
screen. / public class SchoolAddress public
static void main(String args) //start class
definition System.out.println (Carlisle
School) System.out.println (300 Carlisle
Road) System.out.println (Axton, VA
24054) //end class definition
9Types of Comments
/ / enclose single or multiline
comments // adding a comment to the
end of a statement or for a
single line comment / / used for
documentation copied into a separate HTML
document to create external documentation
/ SchoolAddress.java Mrs. Seiy
September This program displays the school
name and address on the screen / package
firstApplication / The SchoolAddress class
displays the school name and address on the
screen. / public class SchoolAddress public
static void main(String args) //start class
definition System.out.println (Carlisle
School) System.out.println (300 Carlisle
Road) System.out.println (Axton, VA
24054) //end class definition
10/ SchoolAddress.java Mrs. Seiy
September This program displays the school
name and address on the screen / package
firstApplication / The SchoolAddress class
displays the school name and address on the
screen. / public class SchoolAddress public
static void main(String args) //start class
definition System.out.println (Carlisle
School) System.out.println (300 Carlisle
Road) System.out.println (Axton, VA
24054) //end class definition
Statements set of instructions end with a
semi-colon related statements are enclosed by
curly braces
11/ SchoolAddress.java Mrs. Seiy
September This program displays the school
name and address on the screen / package
firstApplication / The SchoolAddress class
displays the school name and address on the
screen. / public class SchoolAddress public
static void main(String args) //start class
definition System.out.println (Carlisle
School) System.out.println (300 Carlisle
Road) System.out.println (Axton, VA
24054) //end class definition
Declares a package name. If a name is not given,
the computer will name it Default.
12- /
- SchoolAddress.java
- Mrs. Seiy
- September
- This program displays the school name and address
on the screen - /
- package firstApplication
- /
- The SchoolAddress class displays the school
name and address on the screen. - /
- public class SchoolAddress
- public static void main(String args)
//start class definition - System.out.println (Carlisle School)
- System.out.println (300 Carlisle Road)
- System.out.println (Axton, VA 24054)
-
- //end class definition
Class Declaration. Public means it is
available to anyone. This class does not define
any data or actions for objects. It does contain
the main( ) method which means it is the
applications controlling class (the programs
starting point).
13- /
- SchoolAddress.java
- Mrs. Seiy
- September
- This program displays the school name and
address on the screen - /
- package firstApplication
- /
- The SchoolAddress class displays the school
name and address on the screen. - /
- public class SchoolAddress
- public static void main(String args)
//start class definition - System.out.println (Carlisle School)
- System.out.println (300 Carlisle Road)
- System.out.println (Axton, VA 24054)
-
- //end class definition
Defines the main( ) method. A method is a named
set of statements that perform a single,
well-defined task. The main( ) method is placed
in the controlling class which means its
statements are automatically run when the program
is executed. static void means that it is a
method of the class and does not generate a value.
14- Lab MyAddress.java
- Study the SchoolAddress application closely
- Put the handout and your text away
- Create an application which displays your name
and address on the screen - Can you complete MyAddress.java on your own??