You are on page 1of 5

JAVA:

 Every line ends with a ; unless the next symbol is a {


 Every { has a }
 Classes start with capital letters, methods and variables start with lower case letters
 Classes start capital letters and have no ( )
 Methods start lowercase letters and have a ( )
 Variables always start with a lowercase letter
 = means ‘gets the value of’
 == means ‘equals’ when comparing numbers
 .equals() means ‘equals’ when comparing words

Variables:

 String: “cat” “DA1 2HW”


 Int: 23 0 -98 39290 -321
 Double: 1.2 -5.93 3.3333
 Boolean: true / false
 Char: ‘a’ ‘3’ ‘@’ ‘A’ ‘-’
- Strings cannot do calculations

INPUT:

 Import java.util.* BEFORE main ()


 Declare a Scanner
 Declare a String variable to catch input
 Use the Scanner to assign input from keyboard to variable

Input is best received as a String

We use: String anything = kb.nextLine();

Converting String to int:

To convert String to int, we use a


function called Integer.parseInt( );
Example:
String snumber = kb.nextLine();
int num = Integer.parseInt(snumber);

Converting String to double:

To convert String to double, we use a


function called Double.parseDouble( );
Example:
String snumber = kb.nextLine();
double price = Double.parseDouble(snumber);
IF-ELSE:
- Only IF gets a condition ELSE does not
if (condition)
{
something
}
else
{
something else
}

AND/OR:
• AND in Java: &&
• OR in Java: ||
LOOP (FROM TO) FOR: Known number of repetitions

Making random numbers: Min+(int)(Math.random()*((Max - Min) + 1))


Write down the minimum number and maximum number you need, and use the
formula!
So let’s makes numbers between 1 and 10:

1 +(int)(Math.random()*((10 - 1) + 1))
LOOP WHILE: Unknown number of repetitions

ARRAYS:
 Inicializarla: int a [ ] = new int [number of element]
 a = name of the array
 int = type of each element
METODOS:
Method rules:
 Starts with a lower case letter
 Ends with a set of brackets: ()
 Has to say what comes back
 Methods that return a value are called return type methods.
 You have to specify what type of data is being returned: int, String, char, etc.
 Methods that don’t return a value are called void methods.
 Some people call void methods procedures and return type methods
functions
ARCHIVOS:
There are two types of files in computing:
 Text files (that contain ASCII/Unicode characters) – e.g. TXT, CSV
 Random Access Files (that contain binary objects) – e.g. JPG, MP3
 Setting up the file connection
Steps to remember:
1. Import: java.io.*
2. Throw away any IOExceptions (throws IOException) that could
potentially occur in the main method
 Connecting to the file
 Steps to remember:
1. First add a File Reader
2. Then add that File Reader to a Buffered Reader

In the end, always .close()

You might also like