Show Menu
Cheatography

Java Cheat Sheet by

Data Types

byte
8 bits
short
16 bits
int
32 bits
long
64 bits
boolean
( no bit just true/ false)
char
16 bit unicode
float
32 bit decimal
double
64 bit decimal

Swap

package com.company;

import java.lang.System;

public class Main {

    public static void swap(int[] list, int e1, int e2)
    {
        int temp;
        temp = list[e1];
        list[e1] = list[e2];
        list[e2] = temp;

        System.out.print("\nafter swap: ");
        for (int i = 0; i < 5; i++)
        {
            System.out.print(list[i] + " ");
        }

    }

    public static void main(String[] args)
    {
        int [] mylist = new int [] {1, 2, 3, 4, 5};

        System.out.print("before swap: ");
        for (int i = 0; i < 5; i++)
        {
            System.out.print(mylist[i] + " ");
        }

        swap(mylist, 1, 2);
        swap(mylist, 0, 4);
        swap(mylist, 1, 3);
    }
}
 

notes

/n = new line
/t = tap
/" = "
/* = multiple

Make new class:
Click src > main > new > Java class (then type the code)

Arrays

- List use when shopping
- can make 2 ways:

int[] ex1 = new int [3];
ex1[0]= 1;
ex2[1]= 2;
ex3[2]= 3;

While loops

While loops

        int count = 0;
        while (count < mylist.lenght) {
            System.out.print( mylist[count] + "");
            
            count ++;

Do...While

- It make the code run and check the condition.
(if the condition correct or not and have 1 letter)

int count=0;
do{
         System.out.print(count + " ");
         count ++ ;
}while (count < 10);

Ans 0 1 2 3 4 5 6 7 8 9
 

Java Progra­mming Process

Java is a high level progra­mming language that is readable by human called JVM ( Java Virtual Machine ).
Compiler - translate the program into machine language that can be executed directly on the computer.
(called native compiler because it produces on execut­able).
Java bytecodes - the java complier translate your java program to be an interm­ediate level, which can be executed only by JVM.
JVM is the another run program of Java. It referred to Java runtime.
The standard enviro­nment is distribute by Oracle and is called the Java runtime enviro­nment (JRE).
Java runtime a program that execute compiled Java byte codes.
JDK (Java Develo­pment Kit) contains a complete class library of utilities that help you accomplish most common tasks.

String

String (same with array int but int use for the number but string use for word.)

String name = "­Yuy­u"

Char

Char is same with string but char for only letter!!

String letter = "­A";

For loops

 For loops (do everything in () )
            Characters
            String name = "yuyu";
               for (char y : name.toCharArray()){
                   System.out.print(y + " ");
               }
            Ans y u y u 
                    
                int [] mylist = {2,4,6};
                for (int i = 0; i < mylist.length; i++)
                {
                    System.out.print( mylist [i] + " ");
                }
            Ans 2 4 6
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet