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 com.netcse.java; | |
public class Main { | |
int id; | |
String name; | |
Main(int i, String n){ | |
id = i; | |
name = n; |
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
/** | |
* Created by Google on 8/22/2015. | |
*/ | |
package com.example.google.interview; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; |
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
class Worker { | |
private static long count = 0; | |
public synchronized void increment() { | |
for (int i = 0; i < 10; i++) { | |
count++; | |
} | |
} |
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
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Random; | |
class App { | |
public static void main(String[] args) { | |
Worker worker = new Worker(); | |
worker.main(); |
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 com.netcse.java; | |
public class Main { | |
private static final String OS_NAME = System.getProperty("os.name").toString(); | |
public static void main(String[] args) { | |
System.out.println("Hello world java programming in this world is nothing but java"); | |
System.out.println(OS_NAME); | |
System.out.println(System.getProperty("os.arch").toString()); |
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 com.netcse.java; | |
public class Main { | |
public static void main(String[] args) { | |
StackTraceElement[] stackTraceElement = Thread.currentThread().getStackTrace(); | |
for (StackTraceElement s : stackTraceElement) { | |
System.out.println(s.toString()); | |
} |
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
primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){ | |
@Override | |
public void handle(KeyEvent event) { | |
if(event.getCode() == KeyCode.ESCAPE){ | |
primaryStage.close(); | |
} | |
} | |
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
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( | |
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel"); | |
getRootPane().getActionMap().put("Cancel", new AbstractAction() | |
{ | |
public void actionPerformed(ActionEvent e) | |
{ | |
System.exit(0); | |
} | |
}); |
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
// The following code snippet without generics requires casting: | |
List list = new ArrayList(); | |
list.add("hello"); | |
String s = (String) list.get(0); | |
// When re-written to use generics, the code does not require casting: | |
List<String> list = new ArrayList<String>(); | |
list.add("hello"); | |
String s = list.get(0); // no cast |
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
class Main { | |
static int max(int x, double y) { | |
return (x > y) ? x : (int) y; | |
} | |
static int max(double x, int y) { | |
return (x > y) ? (int) x : y; | |
} |
OlderNewer