Last active
July 28, 2018 17:56
-
-
Save gladiatorAsh/034055c552f1ef08358a7a792b31f0f6 to your computer and use it in GitHub Desktop.
Basics of Programming
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. String equals vs == | |
| public static void main(String[] args) | |
| { | |
| System.out.println("abc"=="abc"); | |
| System.out.println("abc".equals("abc")); | |
| OtherClass my1=new OtherClass("Hello"); | |
| OtherClass my2=new OtherClass("Hello"); | |
| System.out.println(my1==my2); | |
| System.out.println(my1.equals(my2)); | |
| } | |
| 2. Class implementing two interfaces | |
| public class HelloWorld | |
| { | |
| // arguments are passed using the text field below this editor | |
| public static void main(String[] args) | |
| { | |
| OtherClass myObject = new OtherClass("Hello World!"); | |
| System.out.println(myObject); | |
| System.out.println(myObject.getNum(2,3)); | |
| I1 myObject1 = new OtherClass("New Object!"); | |
| System.out.println(myObject1.getNum(2,3)); | |
| I2 myObject2 = new OtherClass("New Object!"); | |
| System.out.println(myObject2.getNum(2,3)); | |
| } | |
| } | |
| // you can add other public classes to this editor in any order | |
| public class OtherClass implements I1,I2 | |
| { | |
| private String message; | |
| private boolean answer = false; | |
| public OtherClass(String input) | |
| { | |
| message = "Why, " + input + " Isn't this something?"; | |
| } | |
| public String toString() | |
| { | |
| return message; | |
| } | |
| public int getNum(int num1, int num2){ | |
| return num1+num2; | |
| } | |
| } | |
| interface I1{ | |
| int getNum(int num1, int num2); | |
| } | |
| interface I2{ | |
| int getNum(int num1, int num2); | |
| } | |
| 3. 0=="0" in JS | |
| function display(){ | |
| console.log("0"==0); | |
| console.log(""==0); | |
| console.log("1"==0); | |
| console.log("1"===0); | |
| console.log(0=="0"); | |
| console.log(0==""); | |
| console.log(1==""); | |
| console.log(1=="6"); | |
| console.log(1=="1"); | |
| console.log(true=="6");//Check | |
| console.log(true==[1]); | |
| } | |
| 4. setTimeout Syntax | |
| a. function display(){ | |
| for(var i=0;i<=6;i++){ | |
| setTimeout(function(){ | |
| console.log(i); | |
| },5); | |
| } | |
| } | |
| //undefined | |
| b. | |
| function display(){ | |
| for(var i=0;i<=6;i++){ | |
| setTimeout(console.log(i),5); | |
| } | |
| } | |
| //0 1 2 3 4 5 6 | |
| 5. System.out.println(2+ +3 - -4); //9 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment