| onblur | when an element loses focus |
button, input, label, select, textare, body |
| onchange | selection in an element loses focus and value changes when focus returns |
input, select, textarea |
| onclick | mouse press and release |
most elements |
| onfocus | element gains focus |
button, input, label, select, textarea, body |
| onload | when the element completes loading |
body, img |
| onmousedown | mouse button is pressed |
most elements |
| onmousemove | mouse moves |
most elements |
| onmouseout | mouse moves off element |
most elements |
| onmouseover | mouse moves over element |
most elements |
| onreset | form reset requests |
form |
| onresize | window changes size |
body |
| onselect | text selected |
input, textarea |
| onsubmit | form submission requested |
form |
| JavaScript | Java | |
|---|---|---|
| Language Type | Object Oriented / Interpreted | Object Oriented / Compiled |
| Comments | // & /*...*/ | // & /*...*/ |
| Console Output | document.write() | System.out.print() System.out.println() |
| Dialog Output | window.alert() | JOptionPane.showMessageDialog(); |
| Concatenation Operator | + | + |
| Variables | var age = 43; var gpa = 3.5; var name = "Jim"; var isMale = true; var middleInit = 'G'; |
int age = 43; double gpa = 3.5; String name = "Jim"; boolean isMale = true; char middleInit = 'G'; |
| Console Input | name=document.getElementById('name'); age=parseInt(document.getElementById('age')); gpa=parseFloat(document.getElementById('gpa')); |
name=reader.nextLine(); age=reader.nextInt(); gpa=reader.nextDouble(); |
| Dialog Input | name=window.prompt("Enter Name"); age=parseInt(window.prompt("Enter age")); gpa=parseFloat(window.prompt("Enter GPA")); |
name=JOptionPane.showInputDialog("Enter Name"); age=Integer.parseInt(JOptionPane.showInputDialog("Enter Age")); gpa=Double.parseDouble(JOptionPane.showInputDialog("Enter GPA")); |
| Math Methods | Math.sqrt(num); Math.pow(base,exp); Math.min(num1, num2, ...); Math.max(num1, num2, ...); Math.round(num); Math.ceil(num); Math.floor(num); Math.abs(num); Math.random(); Math.PI; |
Math.sqrt(num); Math.pow(base,exp); Math.min(num1, num2); Math.max(num1, num2); Math.round(num); Math.ceil(num); Math.floor(num); Math.abs(num); Math.random(); Math.PI; |
| String Methods | str.length; str.indexOf(string); str.lastIndexOf(string); str.charAt(num); str.toUpperCase(); str.toLowerCase(); str.substring(start, [end]); str.substr(start, length); |
str.length; str.indexOf(string); str.lastIndexOf(string); str.charAt(num); str.toUpperCase(); str.toLowerCase(); str.substring(start, [end]); str.equals(string); str.equalsIgnoreCase(); str.compareTo(string); str.compareToIgnoreCase(string); |
| Conditions | if(condition) code else code |
if(condition) code else code |
| For Loop | for(var x=0; x<5; x++) | for(int x=0; x<5; x++) |
| While Loop | while(condition) | while(condition) |
| do...while | do{...}while(condition); | do{...}while(condition); |
| Functions | function funcName (age, gpa){ code; return value;} |
public static int funcName(int age, double gpa){ code; return value;} |
| Arrays | var arr=[]; arr[0]=53; |
int [] arr=new int[10]; arr[0]=53; |