PROGRAMMING LANGUAGE BASICS Part 1
PROGRAMMING LANGUAGE BASICS Part 1
PROGRAMMING LANGUAGE BASICS Part 1
Case Sensitivity - it states that Java is case sensitive, which means identifiers Hello
and hello would have different meanings in Java.
Class Names - the first letter should be in Upper Case. If several words are used to
form a name of the class, each inner word’s first letter should be in
Upper Case.
Method Names - these should start with a Lower Case letter. If several words are
used to form the name of the method, then each inner word’s first
letter should be in Upper Case.
Program File Name - the name of the program file should exactly match the class name.
Public static void main (String - Java program processing starts from the main() method which is a
args []) mandatory part of every Java program.
1. Access Modifiers - Java provides a number of access modifiers to set access levels for
classes, variables, methods and constructors.
*Final Modifiers - for finalizing the implementations of classes, methods and variables.
B. Reference Data Type - these are created using defined constructors of the classes. They are
used to access objects. These variables are declared to be of a specific
type that cannot be changed.
- default value is null.
- can be used to refer any object of the declared type or any
compatible type.
String Literals - these are specified like they are in most other languages by
enclosing a sequence of characters between a pair of double quotes.
Variable - it provides us with named storage that our programs can manipulate.
- it has a specific type which determines the size and layout of the
its memory; the range of values that can be stored within that
memory; and the set of operations that can be applied to the it.
Three Kinds of Variables in Java
2. Instance Variables - these are declared in a class, but outside a method, constructor or
any block.
- these are created when an object is created with the use of the
keyword 'new' and destroyed when the object is destroyed.
- hold values that must be referenced by more than one method,
constructor or block, or essential parts of an object's state that must be
present throughout the class.
- these can be declared in class level before or after use.
- these are visible for all methods, constructors and block in the class.
Normally, it is recommended to make these variables private (access
level). However, visibility for subclasses can be given for these
variables with the use of access modifiers.
- these have default values. For numbers, the default value is 0, for
booleans it is false, and for object references it is null. Values can be
assigned during the declaration or within the constructor.
- these can be accessed directly by calling the variable name inside
the class. However, within static methods (when instance variables
are given accessibility), they should be called using the fully qualified
name
.
3. Class / Static Variables - these are declared with the static keyword in a class, but outside a
method, constructor or a block.
- these are rarely used other than being declared as constants.
- these are stored in the static memory. It is rare to use static variables
other than declared final and used as either public or private
constants.
- these are created when the program starts and destroyed when the
program stops.
Constants - these are variables that are declared as public/private, final, and
static.
- these never change from their initial value.
Java Operators
1. Arithmetic Operators - these are used in mathematical expressions in the same way that
they are used in algebra.
2. Relational Operators
3. Bitwise Operators - this works on bits and performs bit-by-bit operation.
4. Logical Operators
5. Assignment Operators
6. Miscellaneous Operators
Constants
Not a Number (Double.NaN) - returns a double representation of an IEEE NaN. The NaN is often
generated during floating point calculations to signify n exceptional
situation.
Functions
arc cosine (Math.acos (value)) - returns the arc cosine of a, in the range of 0.0 through Pi.
arc sine (Math.asin (value)) - returns the arc sine of a, in the range of -Pi/2 through Pi/2.
arc tangent (Math.atan (value)) - returns the arc tangent of a, in the range of -Pi/2 through Pi/2.
two argument arc tangent - returns the polar angle of the rectangular coordinates (x,y).
(Math.atan2 (x,y))
ceiling (Math.ceil (value)) - returns the smallest whole number greater than or equal to a.
exp (Math.exp (value)) - returns the exponential number e (2.718…) raised to the power of a.
floor (Math.floor (value)) - returns the “floor” or largest whole number less than or equal to a.
logarithm (Math.log (value)) - returns the natural logarithm (base e) of value. To get the base 10
logarithm (ln), use Math.log (value) / Math.log (10).
max (Math.max (value_1, value - returns the greater of value_1 and value_2.
_2))
round (Math.round (value) - rounds off a floating point value by first adding 0.5 to it and then
returning the largest integer that is less than or equal to this new
value.