Code Study
Code Study
INTRODUCTION TO JAVA
Is a development platform for building java applications. Learn about different JDK versions, then install a
JDK in your development environment and use it to compile a java program
Packages
Is simply a way of organizing your classes and other files together. The packages are always folded.
You can also create another package inside the package. Simply you can call packages folders, and inside
the package, we store classes whereby each class name should start with uppercase.
Note
When you are working with the default package there is no need for you to specify which package you
are working with but if you are working with your package you have to specify the packages otherwise it
will give you an error
The keyword that is used to create a package is a package. Every java class belongs to a package example
java. Lang. system (java is a package of lang and system but also lang is a package of system class) when
you use any class that doesn’t belong to a particular package you have to import it but by default system.
Out. Println class has been imported that why when we try to print anything there is no need to import
the package. When you import the class, you have to classify it package and its class.
Note
When you want to import all the classes or folders in the new package you can import them by writing
the package name followed by star (*) this will import all the classes in the new package. If you have a
package inside package that mixes with classes, the package won't be imported because Star is only used
for classes.
Variable
When it comes time to create variables, we have two data types primitive and reference data type.
When you see a new simply is the reference data type
2,147,483,648
- 9,223,372,036,854,775,808 to
9,223,372,036,854,777,807
Decimal digits
Decimal digits
Array
It provides the fixed-size data structure that stores the elements of the same type.
Interface
It is implemented by java classes
Enumeration
It is a special kind of class that is type-safe. Each element inside the enum is an instance of the enum.
Annotations
It provides away to associate metadata with program elements
Class
It is a set of instructions. It describes the content of the object
Math class
This is the class that help to simplify the work flow of in coding by operating different operation in the
program such as calculating exponent, cos and many other
All math faction in java
Math.class (this will print the class were math is found which is class java. Lang. Math)
Math.E (this will print the E faction which is most use in caracaras 2.718281828459045)
Math.PI (this will print the PI number 3.141592653589793)
Math.abs ( this will print the opposite number if the number is negative and will print the same number
if the number is positive)
Math.acos (this returns the arc cosine of the value; the returned angle between 0 and PI and if you
import the number that is more than 1 is not goanna work)
Math.addExact (this add two number that have been separated by comer 3, 4 =7 and eliminate the
rounding error)
Math.asin ( Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.
Special cases)
Math.atan ( Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.
Special cases
Math.atan2 (Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar
coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the
range of -pi to pi. Special cases)
Math.cbrt (this is the same as say square )
Math.ceil (Returns the smallest (closest to negative infinity) double value that is greater than or equal to
the argument and is equal to a mathematical integer. Special cases)
Math.copySign (this copies the sign of the second number and put it to the fist number)
Math.cos (Returns the trigonometric cosine of an angle. Special cases)
Math.cosh (Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be
(ex + e-x)/2 where e is Euler's number.)
Math.decrementExact ( this decrement any value by one)
Math.exp (Returns Euler's number e raised to the power of a double value. Special cases)
Math.expm (Returns ex -1. Note that for values of x near 0, the exact sum of expm1(x) + 1 is much closer
to the true result of ex than exp(x).
Special cases)
Math.floor (Returns the largest (closest to positive infinity) double value that is less than or equal to the
argument and is equal to a mathematical integer. Special cases)
Math.floorDiv (Returns the largest (closest to positive infinity) int value that is less than or equal to the
algebraic quotient. There is one special case, if the dividend is the Integer.MIN_VALUE and the divisor is
-1, then integer overflow occurs and the result is equal to Integer.MIN_VALUE.
Normal integer division operates under the round to zero rounding mode (truncation). This operation
instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode
gives different results from truncation when the exact result is negative)
Comparison operators
Comparison operators what allow us to compare values
Arrays
The null value
Is the value of an object that represents nothing
String text; // null ( when creating a variable of string and not assigning anything the variable string will
contain null as its object
String text; = “some text”
Arrays in java
Is the collection of variables of the same data type
- An array in Java is an object
- An array variable references a group of data or a collection of variables of the same date type
- The size of an array is fixed
-
Creating array and default values
datatype[] arrayName; // null (First we declare the data type of array and then we put a square bracket to
indicate that we want group data of this data type and then we give the array name and this array, for now,
its contains nothing or null
arrayName = new dataTaype [10]; // address of the 10 elements of type datatype
datatype [] arrayName = new datatype [ 10 ];
int [] numbers = new int [20];
Default values
When an array is created, its elements are assigned the following default values
- 0 for numeric primitive data types
- \u0000 for char types
- False for Boolean types
- Null for references types
Array initializers
double[] numbers = {1.9, 2.9, 3.4, 3.5};
this statement will do the something as
double[] numbers = new double [4];
numbers[0] = 1.9;
numbers[1] = 2.9;
numbers[2] = 3.4;
numbers[3] =3.5;
double[] numbers;
numbers = {1.9, 2.9, 3.4, 3.5}; // this will give an error
Printing arrays
Int [] number = {5,0,8,0,10};
System. Out. println (numbers); // this will print the address
For (int i = 0; i <numbers .lenghth; i++)
System. Out. print (numbers[i] + “ “);
Java is object-oriented this means everything to be an object and to create an object we need a class
In Java, we don’t put the semi colon at the end of the block({}) because it does show that that is the end
but we put semi colon inside the statement because we have to show where deas the statement is end