This file contains 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
package staticExample; | |
public class Frog { | |
static int frogCount = 0; | |
public Frog(){ | |
frogCount += 1; | |
} | |
public static void main(String[] args){ |
This file contains 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
package staticExample; | |
public class Foo { | |
int x = 3; | |
public static void main (String [] args) { | |
System.out.println("x is " + x); | |
}//“Hey, I have no idea which Foo object’s x variable you’re trying to print!” | |
//Remember, it’s the class running the main() method, not an instance of the class. | |
} |
This file contains 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
package staticExample.staticOverride; | |
public class Animal { | |
static void doStuff() { | |
System.out.print("a "); | |
} | |
} |
This file contains 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
package floatAndDoubleComparison; | |
public class Test1 { | |
public static void main(String[] args) { | |
double a = 99999.8d; | |
double b = 99999.65d; | |
System.out.println(a + b); | |
float a2 = 99999.8f; | |
float b2 = 99999.65f; |
This file contains 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
package charLiteral; | |
//Refer : https://gist.github.com/rajeevprasanna/8755247 | |
public class CharLiteral { | |
public static void main(String[] args) { | |
char a = 0x892; | |
System.out.println(a);// ? | |
char b = 982; |
This file contains 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
package implicitIntCating; | |
public class TestX { | |
public static void main(String[] args) { | |
byte a = 3; | |
byte b = 4; | |
byte c = (byte) (a + b); | |
System.out.println(c); // 7 |
This file contains 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
package variablePassing; | |
public class ReferenceTest { | |
public static void main(String[] args) { | |
int a = 1; | |
ReferenceTest rt = new ReferenceTest(); | |
System.out.println("Before modify() a = " + a); | |
rt.modify(a); | |
System.out.println("After modify() a = " + a); |
This file contains 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
package variablePassing; | |
public class InstanceVariableShadowing { | |
static int size = 7; | |
static void changeIt(int size) { | |
size = size + 200; | |
System.out.println("size in changeIt is " + size); | |
} |
This file contains 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
package variablePassing; | |
// Refer : https://gist.github.com/rajeevprasanna/8755845 | |
public class ShadowReferenceVariables { | |
public Bar myBar = new Bar(); | |
void changeIt(Bar myBar) { //myBar is copy reference pointing to inst1 | |
myBar.barNum = 99; //inst1 bar variable is modified | |
System.out.println("myBar.barNum in changeIt is " + myBar.barNum); //99 |
This file contains 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
package arrays; | |
public class ArrayInitialization { | |
public static void main(String[] args) { | |
// Declare and create an array holding three references to int arrays | |
int[][] scores = new int[3][]; | |
// the first element in the scores array is an int array of four int elements |
OlderNewer