Introduction to Java - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Java

Description:

Blocks groups of statements enclosed in { and } ... Enclose classes, method statements, or statements inside controls structures. Can be nested. ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 24
Provided by: mikem52
Learn more at: http://cob.jmu.edu
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Java


1
Introduction toJava
2
Java Characteristics
  • Simple (relatively)
  • Object-Oriented
  • Distributed
  • Interpreted
  • Robust and Reliable
  • Secure and safe (relatively)
  • Platform-Independent (Architecture-Neutral)
  • Distributed and Portable
  • Fast (but not the fastest)
  • Multithreaded

3
Object Oriented Programming
  • Encapsulation keeping data and its related
    functionality together (non-OOP left them
    independent)
  • Data hiding providing an interface to the user,
    and hiding the implementational details of this
    interface. This leads to simpler programming
    tasks.
  • Inheritance ability for one class to inherit
    properties (data and functionality) from other
    classes. This leads to reusable code. (Classes
    are arranged in a hierarchy of classes
    (categories) and subclasses (sbucategories)
  • Polymorphism ability for the same message to be
    interpreted by objects of different types in
    different ways.

Instances
Classes
4
The Java Programming Process
Write Source Code in Java
java.exe is the VIRTUAL MACHINE
5
Anatomy of a Java Program
  • Comments documentation. Compiler ignored these.
  • Reserved Words keywords of the language.
  • Modifiers keywords that describe properties of
    methods, classes, or variables.
  • Statements action instructions telling the CPU
    what to do.
  • Blocks groups of statements enclosed in and
  • Classes object-oriented constructs involving
    methods and variables arranged in inheritance
    hierarchies.
  • Methods functions, members of classes.
  • The main method the starting point of a Java
    application.
  • Package group of related classes.

6
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

7
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Commentsuse // for single line or / / for
multiple lines
8
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Package indicates a grouping of classes.
9
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Reserved words keywords of the language with
specific meaning to the compiler.
10
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Modifiers reserved words that specify
characteristics or properties of data, methods,
and classes.
11
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Statements action instructions. Always end with
semicolon ()
12
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Blocks groups of statements (sometimes called
compound statements). Enclose classes, method
statements, or statements inside controls
structures. Can be nested.
13
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Classes complex data structures encapsulating
data and actions. Classes are composed of methods
(functions) and variables (attributes)
14
A Simple Application
  • Example 1.1
  • //Welcome.java This application program prints
  • // Welcome to Java!
  • package chapter1
  • public class Welcome
  • public static void main (String args)
  • System.out.println("Welcome to Java!")

Methods named blocks of statements that can be
called, take arguments (parameters), return
values. Note all Java applications must have a
main method as an entry point to the program.
15
Options for Building and Running Java Applications
  • Command Line (in DOS mode)
  • Get into command window
  • Call JDK programs for operations
  • Text-mode debugging
  • Using an Integrated Development Environment (e.g.
    NetBeans)
  • GUI interface
  • Menus/toolbars for operations
  • Graphical debugging

Well discuss this later
16
Suns Java Development Kit (JDK)
  • Includes the following tools
  • found in bin subdirectory of the java directory
  • Java Compiler (javac.exe)
  • Java Virtual Machine (java.exe)
  • Java AppletViewer (AppletViewer.exe)
  • Java Debugger (jdb.exe)
  • Where to get the JDK
  • from http//java.sun.com/javase/downloads/netbeans
    .html
  • also includes Netbeans IDE

Its Free and Open Source!!!
17
Using Command-Line Technique for Writing,
Compiling and Running Java Applications
  • Use any text editor to create your .java source
    code file (for example, Notepad).
  • Copy the compile.bat and run.bat files (available
    for download from my web site) to the same folder
    as your .java source code file.
  • Make sure the path in the batch files are correct
    (see next slide).
  • Use the Command Prompt (DOS window) to access the
    folder and run the batch files.

18
File Paths
  • If you installed the Java SDK and NetBeans from
    Suns Java Site, the path to your file will be
  • c\Program Files\Java\jdk1.5.0_12
  • If you are using java in the lab (installed on
    the D drive), the path to the JDK is
  • D\Program Files\Java\jdk1.5.0_12

In both cases, the javac.exe and java.exe
programs are in the bin subfolder
19
(No Transcript)
20
What is NetBeans?
  • Integrated Development Environment (IDE)
  • Analogous to Microsoft Visual Studio
  • Tools include
  • Project workspace
  • Color-coded, smart editing
  • GUI building tools (e.g. form builders)
  • Compiler
  • Execution
  • Debugging tool

21
What is NetBeans? (continued)
  • Can build entire projects consisting of multiple
    source files and classes
  • Includes GUI building tools for easy placement of
    components (controls)
  • Like form builders in VB
  • Menu/toolbar interfaces for compile/execute/debug

22
NetBeans Interface (for edit, compile, execute,
and debug)
Projects window
Editor window
Output window
Debug windows
23
Using the Examples from Liangs Textbook
  • All Textbook examples are located downloadable
    from my web site.
  • Create a Liang7eSamples project using NetBeans.
  • In the Liang7eSamples folder, there is a src
    subfolder. In that subfolder, you can copy the
    folders I provide in my exampleseach subfolder
    of src is a package, and contains the java
    programs of the chapter
  • NOTE Liang has a web site with more resources
    http//prenhall.com/liang.
Write a Comment
User Comments (0)
About PowerShow.com