Java Basics
Java Basics
Java Basics:
O b j e c t O r i e n t e d P ro g r a m m i n g
Tutorial Document created by Brandon Perkins
In this section:
Legal information
What is Java?
Ethical Values: Professional and Personal
Basic Java Elements
Legal Information
The information on this document is considered common knowledge within the community of
computer programmers and engineers, in businesses, education, and to hobbyists at home. The
information on this document can be found anywhere, but like other advanced programmers
(career or hobby), I want to try to make it as easy to understand as possible for those that are
interested in learning and for those who have already started but need a push in the right direction.
Although this document was created by me, all of the information that I share has been obtained
through school education and self-exploration. Although the information is considered common
knowledge, I would like to make a few acknowledgements to those I have to thank for giving me
the skills I need to help me study for my future career as a computer engineer:
A few more legal formalities that I would like to get out of the way. The JAVA
language originated and is owned by Sun Microsystems. Also the compiler
that may be used and referenced in these documents is called JCreator.
JCreator software was developed and is owned by Xinox Software, a company
based in Deft, Netherlands. For more information, the following links are
www.jcreator.com and www.sun.com/java/.
I am not fond of legal formalities like this, and although it’s considered
common knowledge, this is considered a moral ethical choice which will be
covered in this document as well. If someone feels that I have left something
out important regarding the ‘Legal Information’ section, then please contact
Page 1
and inform me so that I may make the appropriate changes. I check my email
as often as I can so I will most likely see any notifications sent. My email is
[email protected]. Only email me if it is about these documents.
What is JAVA?
• Reusability of code
• Focus on data rather than procedure
• Simple, secure, and robust use of code
• Portable
• Dynamic
• Data hidden and protected from external functions
• Etc., www.oracle.com to find more about its features
Page 2
Java Basics: Object Oriented Programming
Four Principles of OOP
All of this information is better explained as you learn more about the
language and learn how to do more with your programs. All of this
information comes from the textbook named in the sources given that was
provided as study notes given to me from my AP Computer Science teacher. It
is an old book and not considered up to date with the Java language’s current
version.
Remember the legal section at the beginning of this document. Even though
all the information in this document is considered for the most part to be
common knowledge (comes from more than one source or is a commonly
known fact), it is considered ethical to still give credit and recognition where
it’s due. Same goes with computer programming or engineering. When a
group of people has been asked to work on a project, it’s ethical to do your
part and not let everyone else do all the work. It’s also ethical to give credit
Page 3
where it’s due, everyone who does their part would be given proper credit for
the work.
What are ethics? There is always confusion between what is ethical and what
is legal. Simply put they are two different things which I will illustrate below:
Legal Ethical
Plenty of people would be affected by this action. The stores and their
customers who buy them could be using the batteries for trivial uses or for
something life changing (like smoke detectors). The employees of the
production line could get in a lot of trouble from this and may lose their job.
The manager who took this action and possibly even the company could get
into trouble as well. Pretend that it was something else instead of batteries,
something more important. The consequences could be worse.
Page 4
Java Basics: Object Oriented Programming
This action would most likely not be illegal since there are not actually any
laws that can regulate this. It is however unethical, because defective products
are knowingly being shipped out and sold to unsuspecting customers.
Java is for the most part, a user-defined language. Objects, data variables,
classes, and more can be named and defined by the programmer. However,
there are special key elements that must be used to help define them.
Reserved words are unique java terms that help tell the compiler how it should
interpret the lines of code in a program. They cannot be used as names of
data variables, classes, objects, and so on. They are case sensitive and are
predefined in the java language. Most of these are used more than others,
and some may hardly be used at all.
volatile while
Page 5
remind him/her what the code, should he/she may need to go back to it for
reference. It also can be placed if the code would be shared with other
programmers and they need to understand what the code is doing.
Comments have no effect on the program itself; it is simply there. This is what
a comment may look like:
Data variables are used to store data that may change throughout the run of a
program. Variables have names given by the programmers, known as
identifiers, and should be unique to the program that the variables are used
for. Variables also have data types which describes what kind of data it stores.
Java has four main primitive data types: Integer, Boolean, Floating Point, and
Character. This table shows default values for built in java data types:
int 0
long 0L
float 0.0f
double 0.0d
boolean false
Like reserved words, some of these will be used more than others and some
will hardly be used at all.
IMPORTANT: When giving a data variable a name it is vital that you follow
these rules for naming them. Names can have lower and upper case letters
that can be anywhere in the name (ex: name, Name, naMe, NaMe, etc.). If you
Page 6
Java Basics: Object Oriented Programming
make a data variable with a name in all caps it will be considered to be a
constant variable (will be discussed in a later document). When using variables
in the program they are case sensitive. Variable names may contain numbers,
BUT the name CANNOT start with a number (ex: 3name is incorrect, na3me or
name3 is correct). Variable names cannot not contain spaces. Variable names
can be as long as you want, but it is strongly recommended to make
reasonably small names. Names can contain the special characters ‘$’ and ‘_’
but is recommended to avoid whenever possible (especially the ‘$’). It is also
highly discouraged to place them at the beginning of the variable’s name. If
you are going to use subsequent variable names (name used more than once
but each holds a different value) then just had a number to the end of it (ex:
name1, name2, name3, etc.). The name you use cannot be a java reserved
word or java keyword.
Classes are basically just outlines of objects, defining properties and behaviors.
Sometimes a program itself is just a single class.
Objects are instances of a class using the new operator. They are basically
data variables that store information that the class it came from was designed
to hold.
There are also instances, static, inheritances, and interfaces in java but those
will be discussed, later as you get farther into programming.
Page 7