complete java software development guide - chapter 2
DESCRIPTION
Java is a very easy and widely used language. In this chapter we rae discussing about your first java application. Modern object-oriented programs help us build models to manage the complexity found in a problem domain.TRANSCRIPT
![Page 1: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/1.jpg)
Your First Java Application
Chapter 2
Complete Java – Software Development Guide
Apex T. G. India Pvt. Ltd
![Page 2: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/2.jpg)
2
Program Concepts
Modern object-oriented programs
help us build models to manage the complexity found in a problem
domain.
The problem domain describes real-world objects and concepts that a
computer program is trying to solve.
![Page 3: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/3.jpg)
2
Models
A model is a simplification of a complex system. A good model:
Helps to identify the most important aspects of a problem.
Helps a programmer to focus on the problem he or she is trying to solve
instead of on the complexity of the problem’s data.
![Page 4: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/4.jpg)
2
What is a metaphor?
A metaphor is a word or phrase used in place of another word or
phrase to denote a likeness.
Computer programs use “metaphors” to represent real objects.
![Page 5: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/5.jpg)
2
Objects
Objects represent real-world things:
Ship
Rudder
Wheel
Instruments
Objects have:
properties(characteristics)
methods(behaviors)
![Page 6: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/6.jpg)
2
Classes and Objects
A class is a definition of atype:
Like a template, a class defines the characteristics and behaviors of the
type.
An object is aninstanceof a class:
Can be instantiated and manipulated
An object’s characteristics are defined by the class that was used to
create the object.
![Page 7: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/7.jpg)
2
Fields
Fields define the properties of a class.
Can be intrinsic types (int,boolean…)
Can be user-defined objects
Stateis the current value of a field in an object.
![Page 8: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/8.jpg)
2
Methods
Methods describe the capabilities of the class.
Every method must be called from another method. The only exception
ismain(),which is called by the OS.
Methods can accept parameters.
![Page 9: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/9.jpg)
2
Object Relationships
Association
A method of one object calls the method of another object.
Composition
Some objects are composed of other objects.
![Page 10: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/10.jpg)
2
Specialization
Hierarchies of classes move from a
generalized class to a more specific
class.
![Page 11: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/11.jpg)
2
Creating Programs
Syntax and Semantics
A language’s exact keywords, punctuation, and order of terms are called
its syntax.
Semantics refers to the meaning of one’s instructions; what the program
is trying to accomplish.
![Page 12: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/12.jpg)
2
Writing a Java Program
Writing a Java program requires five steps:
Analyze
Design
Write
Compile
Test
![Page 13: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/13.jpg)
2
Compiling the Code
Programs must be compiled in order for the CPU to understand and
execute the instructions.
Java byte code is run through the Java Virtual Machine (JVM), which
translates the code for the CPU.
.java files are compiled by the javac (java compiler) program into .class
files.
![Page 14: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/14.jpg)
2
Types of Java Programs
Applet
Requires an .HTML file with the<applet>tag to reference the .class file
Can also be run using the appletviewer.exe program file
Application
Run by the java.exe program file
Run without a browser interface, often using the console window
![Page 15: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/15.jpg)
2
HelloWorld.java Analysis
The keywordimportallows existing class libraries to be reused.
The keywordpublicsignifies that a class is visible to other classes.
Braces{}indicate the beginning and end of a block of code.
Braces must always be “balanced”
Align opening and closing braces
![Page 16: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/16.jpg)
2
More HelloWorld.javaAnalysis
The keywordvoidsignifies that a method does not return a value.
Identifiers are the names given to classes, fields, and methods.
Identifiers are case sensitive.
Identifiers often use camel case notation.
![Page 17: Complete Java Software Development Guide - Chapter 2](https://reader034.vdocuments.net/reader034/viewer/2022051818/54c1b9404a79591a6e8b4584/html5/thumbnails/17.jpg)
Thanks
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
Stay Connected with us for more chapters on JAVA