SlideShare a Scribd company logo
1 of 35
Java is an object-oriented language that enables you to
create real world applications. The code reusability feature
of Java enables the developers to upgrade the existing
applications without rewriting the entire code of the
application.
Packages enable the reusability of classes and methods
across various applications.
The concept of files and I/O streams enables the developers
to store and retrieve the information from a flat or a text file.
Java provides various classes for developing GUI-based
applications. The Swing component provides a pluggable
look-and-feel that enables the developers to create light
weight applications.
The concept of multithreading enables the developers to
utilize multiple system resources simultaneously.
Rationale
In this session, you will learn to:
Identify the key features of Java technology
Write, compile, and run a simple Java technology application
Describe the function of the Java Virtual Machine
Define garbage collection
Identify the three tasks performed by the Java platform that
handle code security
Define modeling concepts
Identify the reuse of Java technology application code
Define class, member, attribute, method, constructor, and
package
Use the access modifiers private and public as
appropriate for the guidelines of encapsulation
Objectives
The Java technology is:
A programming language.
A development environment.
An application environment.
A deployment environment.
Java technology is used for developing both applets and
applications.
Applets are programs written in the Java programming
language that reside on web servers.
Applets are downloaded by a browser to a client’s system
and are run by that browser.
Applications are standalone programs that do not require a
web browser to execute.
What Is the Java™ Technology?
Java technology provides:
A language that is easy to program because it:
Eliminates many pitfalls of other languages.
Is object-oriented to help you visualize the program in real-life
terms.
Enables you to streamline the code.
An interpreted environment resulting in:
Speed of development.
Code portability.
A way for programs to run more than one thread of activity.
A means to change programs dynamically during their runtime
life by enabling them to download code modules.
A means of ensuring security by checking loaded code
modules.
Primary Goals of the Java Technology
The Java technology architecture uses the following
features to fulfill its goals:
The Java Virtual Machine (JVM)
Garbage collection
The Java Runtime Environment (JRE)
JVM tool interface
Primary Goals of the Java Technology (Contd.)
The JVM specification provides the hardware platform
specifications to which you compile all Java technology
code.
This specification enables the Java software to be
platform-independent because the compilation is done for a
generic machine, known as the JVM.
The compiler takes the Java application source code and
generates bytecodes.
Bytecodes are machine code instructions for the JVM.
The Java Virtual Machine
JVM provides definitions for the:
Instruction set
Register set
Class file format
Runtime stack
Garbage-collected heap
Memory area
Fatal error reporting mechanism
High-precision timing support
The Java Virtual Machine (Contd.)
Garbage collection:
Checks and frees memory that is no longer needed.
Provides a system-level thread to track memory allocation.
Happens automatically during the lifetime of a Java program.
Garbage Collection
The following figure displays the operation of the JRE.
The Java Runtime Environment
The main tasks performed by the JVM are:
Loading: It is performed by the class loader to load the code.
Verifying: It is performed by the bytecode verifier to verify the
code.
Executing: It is performed by the runtime interpreter to execute
the code.
JVM™ Tasks
The class loader:
Loads all classes necessary for the execution of a program.
Adds security by separating the namespaces for the classes of
the local file system from those imported from network sources.
The Class Loader
The JVM puts the code through a bytecode verifier that
tests the format of code fragments and checks code
fragments for illegal code.
The bytecode verifier ensures that:
The code adheres to the JVM specifications and does not
violate system integrity.
The code causes no operand stack overflows or underflows.
The types of parameters for all operational codes are correct.
No illegal data conversions, such as converting integers to
object references, have occurred.
The Bytecode Verifier
Let us see the demonstration of creating and executing a
simple Java application.
Demo: A Simple Java Application
The following figure displays how Java programs can be
compiled and then run on the JVM.
Demo: A Simple Java Application (Contd.)
The Java technology class declaration takes the following
form:
<modifier>* class <class_name>
{ <attribute_declaration>*
<constructor_declaration>*
<method_declaration>*
}
Declaring Java Technology Classes
The declaration of an object attribute takes the following
form:
<modifier>* <type> <name> [ = <initial_value>];
Declaring Attributes
The method declaration takes the following basic form:
<modifier>* <return_type> <name> ( <argument>* )
{ <statement>* }
Declaring Methods
To access object members, including attributes and
methods, dot notation(.) is used.
The dot notation is:
<object>.<member>
Accessing Object Members
Information hiding means ignoring the non-essential details
of an object and concentrating on its essential details.
This concept is also called as abstraction.
Information Hiding
Encapsulation provides data representation flexibility by:
Hiding the implementation details of a class.
Forcing the user to use an interface to access data.
Making the code more maintainable.
Encapsulation
A constructor is a set of instructions designed to initialize an
instance.
The basic declaration of a constructor takes the following
form:
[<modifier>] <class_name> ( <argument>* )
{ <statement>* }
Declaring Constructors
Every class has at least one constructor.
If the programmer does not supply any constructor, the default
constructor is present automatically.
The characteristics of default constructor are:
It takes no arguments.
It has empty body.
It enables you to create object instances with new classname()
without having to write a constructor.
Declaring Constructors (Contd.)
Let us see the demonstration of declaring constructors.
Demo: Constructors
A Java source file takes the following form:
[<package_declaration>]
<import_declaration>*
<class_declaration>+
Source File Layout
Packages help manage large software systems.
Packages can contain classes and sub-packages.
The following figure displays a sample package structure.
Software Packages
Java provides the package statement as a way to group
related classes.
The package statement takes the following form:
package <top_pkg_name>[.<sub_pkg_name>]*;
The package Statement
An import statement is used to tell the compiler where to
find the classes given in a particular package.
The import statement:
Precedes all class declarations.
Tells the compiler where to find classes.
The import statement takes the following form:
import
<pkg_name>[.<sub_pkg_name>]*.<class_name>;
or
import <pkg_name>[.<sub_pkg_name>]*.*;
The import Statement
Packages are stored in a directory tree starting with a
package name.
The following figure displays a sample class package
directory structure.
Directory Layout and Packages
The following figure displays a sample development
directory hierarchy for a development project.
Development
The Java compiler places the class files in the same
directory as the source files.
The class files can be rerouted to another directory using
the -d option of the javac command.
The simplest way to compile files within packages is to be
working in the directory one level above the beginning of the
package.
The following commands are used to compile all the files
within the shipping.domain package and have the
compiled classes in their correct package directory under
ShippingPrj/class/:
cd JavaProjects/ShippingPrj/src
javac -d ../classes shipping/domain/*.java
Compiling Using the -d Option
An application can be deployed on a client machine without
manipulating the user’s CLASSPATH environment variable.
Deployment is done by creating an executable Java archive
(JAR) file. To create an executable JAR file, perform the
following steps:
Create a temporary file that indicates the class name that
contains the main method:
Main-Class: mypackage.MyClass
Build the JAR file by adding an additional option (m) so that the
contents of this temporary file are copied into the META-
INF/MANIFEST.MF file:
jar cmf tempfile MyProgram.jar
Deployment
Run the program by executing the following command:
java -jar /path/to/file/MyProgram.jar
To deploy a library code in a JAR file, copy the JAR file into
the ext subdirectory of the lib directory in the main
directory of the JRE.
Deployment (Contd.)
Summary
In this session, you learned that:
The Java technology is:
A programming language.
A development environment.
An application environment.
A deployment environment.
JVM can be defined as an imaginary machine that is
implemented by emulating it in software on a real machine.
Java source files are compiled, get converted into a bytecode
file. At runtime, the bytecodes are loaded, checked, and run in
an interpreter.
Garbage collector checks for and frees memory no longer
needed, automatically.
Summary (Contd.)
The three main tasks performed by the JVM include:
Loading
Verifying
Executing
Abstraction means ignoring the non-essential details of an
object and concentrating on its essential details.
Encapsulation provides data representation flexibility by hiding
the implementation details of a class.
The dot operator enables you to access non-private attribute
and method members of a class.
A constructor is a set of instructions designed to initialize an
instance of a class.
Java provides the package statement as a way to group
related classes.
Summary (Contd.)
The import statement tells the compiler where to find the
classes which are grouped in packages.
The class files can be rerouted to another directory using the
-d option of the javac command.
An executable JAR file is used to deploy an application on a
client machine without manipulating the user’s CLASSPATH
environment variable.

More Related Content

More from Prashanth Shivakumar

More from Prashanth Shivakumar (6)

Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01Web Component Development with Servlet and JSP Technologies Unit 01
Web Component Development with Servlet and JSP Technologies Unit 01
 
RDBMS_Unit 01
RDBMS_Unit 01RDBMS_Unit 01
RDBMS_Unit 01
 
J2ME Unit_01
J2ME Unit_01J2ME Unit_01
J2ME Unit_01
 
Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01Data Structures and Algorithms Unit 01
Data Structures and Algorithms Unit 01
 
C++ Unit_01
C++ Unit_01C++ Unit_01
C++ Unit_01
 
C programming unit 01
C programming unit 01C programming unit 01
C programming unit 01
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Java Programming from Sun Microsystems Unit 01

  • 1. Java is an object-oriented language that enables you to create real world applications. The code reusability feature of Java enables the developers to upgrade the existing applications without rewriting the entire code of the application. Packages enable the reusability of classes and methods across various applications. The concept of files and I/O streams enables the developers to store and retrieve the information from a flat or a text file. Java provides various classes for developing GUI-based applications. The Swing component provides a pluggable look-and-feel that enables the developers to create light weight applications. The concept of multithreading enables the developers to utilize multiple system resources simultaneously. Rationale
  • 2. In this session, you will learn to: Identify the key features of Java technology Write, compile, and run a simple Java technology application Describe the function of the Java Virtual Machine Define garbage collection Identify the three tasks performed by the Java platform that handle code security Define modeling concepts Identify the reuse of Java technology application code Define class, member, attribute, method, constructor, and package Use the access modifiers private and public as appropriate for the guidelines of encapsulation Objectives
  • 3. The Java technology is: A programming language. A development environment. An application environment. A deployment environment. Java technology is used for developing both applets and applications. Applets are programs written in the Java programming language that reside on web servers. Applets are downloaded by a browser to a client’s system and are run by that browser. Applications are standalone programs that do not require a web browser to execute. What Is the Java™ Technology?
  • 4. Java technology provides: A language that is easy to program because it: Eliminates many pitfalls of other languages. Is object-oriented to help you visualize the program in real-life terms. Enables you to streamline the code. An interpreted environment resulting in: Speed of development. Code portability. A way for programs to run more than one thread of activity. A means to change programs dynamically during their runtime life by enabling them to download code modules. A means of ensuring security by checking loaded code modules. Primary Goals of the Java Technology
  • 5. The Java technology architecture uses the following features to fulfill its goals: The Java Virtual Machine (JVM) Garbage collection The Java Runtime Environment (JRE) JVM tool interface Primary Goals of the Java Technology (Contd.)
  • 6. The JVM specification provides the hardware platform specifications to which you compile all Java technology code. This specification enables the Java software to be platform-independent because the compilation is done for a generic machine, known as the JVM. The compiler takes the Java application source code and generates bytecodes. Bytecodes are machine code instructions for the JVM. The Java Virtual Machine
  • 7. JVM provides definitions for the: Instruction set Register set Class file format Runtime stack Garbage-collected heap Memory area Fatal error reporting mechanism High-precision timing support The Java Virtual Machine (Contd.)
  • 8. Garbage collection: Checks and frees memory that is no longer needed. Provides a system-level thread to track memory allocation. Happens automatically during the lifetime of a Java program. Garbage Collection
  • 9. The following figure displays the operation of the JRE. The Java Runtime Environment
  • 10. The main tasks performed by the JVM are: Loading: It is performed by the class loader to load the code. Verifying: It is performed by the bytecode verifier to verify the code. Executing: It is performed by the runtime interpreter to execute the code. JVM™ Tasks
  • 11. The class loader: Loads all classes necessary for the execution of a program. Adds security by separating the namespaces for the classes of the local file system from those imported from network sources. The Class Loader
  • 12. The JVM puts the code through a bytecode verifier that tests the format of code fragments and checks code fragments for illegal code. The bytecode verifier ensures that: The code adheres to the JVM specifications and does not violate system integrity. The code causes no operand stack overflows or underflows. The types of parameters for all operational codes are correct. No illegal data conversions, such as converting integers to object references, have occurred. The Bytecode Verifier
  • 13. Let us see the demonstration of creating and executing a simple Java application. Demo: A Simple Java Application
  • 14. The following figure displays how Java programs can be compiled and then run on the JVM. Demo: A Simple Java Application (Contd.)
  • 15. The Java technology class declaration takes the following form: <modifier>* class <class_name> { <attribute_declaration>* <constructor_declaration>* <method_declaration>* } Declaring Java Technology Classes
  • 16. The declaration of an object attribute takes the following form: <modifier>* <type> <name> [ = <initial_value>]; Declaring Attributes
  • 17. The method declaration takes the following basic form: <modifier>* <return_type> <name> ( <argument>* ) { <statement>* } Declaring Methods
  • 18. To access object members, including attributes and methods, dot notation(.) is used. The dot notation is: <object>.<member> Accessing Object Members
  • 19. Information hiding means ignoring the non-essential details of an object and concentrating on its essential details. This concept is also called as abstraction. Information Hiding
  • 20. Encapsulation provides data representation flexibility by: Hiding the implementation details of a class. Forcing the user to use an interface to access data. Making the code more maintainable. Encapsulation
  • 21. A constructor is a set of instructions designed to initialize an instance. The basic declaration of a constructor takes the following form: [<modifier>] <class_name> ( <argument>* ) { <statement>* } Declaring Constructors
  • 22. Every class has at least one constructor. If the programmer does not supply any constructor, the default constructor is present automatically. The characteristics of default constructor are: It takes no arguments. It has empty body. It enables you to create object instances with new classname() without having to write a constructor. Declaring Constructors (Contd.)
  • 23. Let us see the demonstration of declaring constructors. Demo: Constructors
  • 24. A Java source file takes the following form: [<package_declaration>] <import_declaration>* <class_declaration>+ Source File Layout
  • 25. Packages help manage large software systems. Packages can contain classes and sub-packages. The following figure displays a sample package structure. Software Packages
  • 26. Java provides the package statement as a way to group related classes. The package statement takes the following form: package <top_pkg_name>[.<sub_pkg_name>]*; The package Statement
  • 27. An import statement is used to tell the compiler where to find the classes given in a particular package. The import statement: Precedes all class declarations. Tells the compiler where to find classes. The import statement takes the following form: import <pkg_name>[.<sub_pkg_name>]*.<class_name>; or import <pkg_name>[.<sub_pkg_name>]*.*; The import Statement
  • 28. Packages are stored in a directory tree starting with a package name. The following figure displays a sample class package directory structure. Directory Layout and Packages
  • 29. The following figure displays a sample development directory hierarchy for a development project. Development
  • 30. The Java compiler places the class files in the same directory as the source files. The class files can be rerouted to another directory using the -d option of the javac command. The simplest way to compile files within packages is to be working in the directory one level above the beginning of the package. The following commands are used to compile all the files within the shipping.domain package and have the compiled classes in their correct package directory under ShippingPrj/class/: cd JavaProjects/ShippingPrj/src javac -d ../classes shipping/domain/*.java Compiling Using the -d Option
  • 31. An application can be deployed on a client machine without manipulating the user’s CLASSPATH environment variable. Deployment is done by creating an executable Java archive (JAR) file. To create an executable JAR file, perform the following steps: Create a temporary file that indicates the class name that contains the main method: Main-Class: mypackage.MyClass Build the JAR file by adding an additional option (m) so that the contents of this temporary file are copied into the META- INF/MANIFEST.MF file: jar cmf tempfile MyProgram.jar Deployment
  • 32. Run the program by executing the following command: java -jar /path/to/file/MyProgram.jar To deploy a library code in a JAR file, copy the JAR file into the ext subdirectory of the lib directory in the main directory of the JRE. Deployment (Contd.)
  • 33. Summary In this session, you learned that: The Java technology is: A programming language. A development environment. An application environment. A deployment environment. JVM can be defined as an imaginary machine that is implemented by emulating it in software on a real machine. Java source files are compiled, get converted into a bytecode file. At runtime, the bytecodes are loaded, checked, and run in an interpreter. Garbage collector checks for and frees memory no longer needed, automatically.
  • 34. Summary (Contd.) The three main tasks performed by the JVM include: Loading Verifying Executing Abstraction means ignoring the non-essential details of an object and concentrating on its essential details. Encapsulation provides data representation flexibility by hiding the implementation details of a class. The dot operator enables you to access non-private attribute and method members of a class. A constructor is a set of instructions designed to initialize an instance of a class. Java provides the package statement as a way to group related classes.
  • 35. Summary (Contd.) The import statement tells the compiler where to find the classes which are grouped in packages. The class files can be rerouted to another directory using the -d option of the javac command. An executable JAR file is used to deploy an application on a client machine without manipulating the user’s CLASSPATH environment variable.