Oracle Certification Associate 1Z0-808: Difference between revisions

From My Limbic Wiki
Line 75: Line 75:
Since Java 7 we can use "_" to makes number easier to read.
Since Java 7 we can use "_" to makes number easier to read.
* Can be anywhere except: beginning of literal, end of literal and right before or right after the decimal point.
* Can be anywhere except: beginning of literal, end of literal and right before or right after the decimal point.
* Error: Illegal Underscore ==> the code does not compile
{| class="wikitable"
{| class="wikitable"
!KeyWord
!KeyWord

Revision as of 18:32, 4 June 2020

Links

Installation

Windows

<source lang="Shell"> C:\Program Files\Java </source>

  • Java Se Development Kit 8
    • Java FX SDK
    • Private JRE - Java Runtime Edition
    • Java Mission Control Tools

Can also be installed:

    • Development Tools
    • Source Code
    • Public JRE

Linux

<source lang="Shell"> sudo apt-get install oracle-java8-installer cd /usr/lib/jvm/java-8-oracle

  1. Java version

java -v

  1. Java Compiler

javac -version </source>

Basics

Main Method

<source lang="Java"> public static void main(String[] args]) </source>

Comments

<source lang="Java"> // Single Line Comment

/* Multi Line Comment

  • /

/**

* Java Doc Comment
* @param
* @return 
*/

</source>

Import Conflicts

<source lang="Java"> import java.util.*; import java.sql.*;

// ==> in code = COMPILATION error Date date; </source>

Static Imports

It is not a good idea to do static imports a lot in a projet because it makes difficult to understand where the methods / constants come from

  • Static imports are for importing static members
  • Classic imports are for importing classes

it can be used for methods and constants for example <source lang="Java"> import static java.lang,Math.*;

// Instead of typing Math.min(1,2); we can just type min(1,2) // Because of the static import </source>

Primitives

It is not a good practice to use "l" instead of "L" while declaring long numbers because "l" looks like a "1" number so it can be confusing

Since Java 7 we can use "_" to makes number easier to read.

  • Can be anywhere except: beginning of literal, end of literal and right before or right after the decimal point.
  • Error: Illegal Underscore ==> the code does not compile
KeyWord Size Examples Smallest Data-Type
Boolean - true
Numbers without decimal points
byte 8-bits 1
short 16-bits 12 comment
int 32-bits 100 Default all numbers in Java
long 64 bits 12 Requires "L" letter to avoid compilation error, even when stored in long variable
float 32-bits 123.45 Requires letter "f" following the numbers
double 64-bits 123.45 Default all primitives or all that similar types
char 16-bits 'a'

Octal Numbers

Octal Numbers are numbers from 0 to 7. They can be used in java as

<source lang="Java"> // Valid int octalNumber = 07;

// Invalid - Number is too large, Compilation Error ! int octalNumber = 08; // it is not an octal number

// Valid - BUT coding standards prohibit use of octal literals, as they may be easily confused with decimal literals int octalNumber = 010 // 8 in decimal;

// Valid int declaration int octalNumber = 022; // 18 in decimal

// Valid int declaration int octalNumber = 8;

System.out.println(octalNumber); // print it's int value // Integer to octal String Integer.toOctalString();

</source>

Hexadecimal

Hexadecimals are numbers from 0 to 9 and letters from A to F <source lang="Java"> // Valid int firstHexNumber = 0xF; // 15 in decimal int secondHexNumber = 0x1E; // 30 in decimal

// Print the decimal value System.out.println(firstHexNumber); // print the Hexadecimal value: Integer.toHexString(firstHexNumber); </source>


Binary

<source lang="Java"> // Valid int firstBinary = 0xF; // 15 in decimal int secondBinary= 0x1E; // 30 in decimal

// Print the decimal value System.out.println(firstBinary ); // print the Hexadecimal value: Integer.toBinaryString(firstHexNumber); </source>