-
An interface is a description of the behaviour an implementing class will have. The implementing class ensures, that it will have these methods that can be used on it. It is basically a contract or a promise the class has to make.
-
An abstract class is a basis for different subclasses that share behaviour which does not need to be repeatedly created. Subclasses must complete the behaviour and have the option to override predefined behaviour (as long as it is not defined as final or private).
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
class Solution { | |
public int minPathSum(int[][] grid) { | |
int row = grid.length; | |
int col = grid[0].length; | |
//dp[i][j] stores the value of minimum path sum at the [i][j] | |
int[][] dp = new int[row][col]; | |
//initilize the value in dp[][] | |
dp[0][0] = grid[0][0]; |
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
import scala.collection.mutable.ArrayBuffer | |
import java.util.concurrent._ | |
class Producer(queue :BlockingQueue[String]) extends Runnable { | |
val str = "item" | |
def run(): Unit = { | |
while(true){ | |
try { |
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
//For Java, the compiler generates a .java file with a class for each message type, | |
//as well as a special Builder classes for creating message class instances. | |
syntax = "proto2"; | |
//package declarations, helps to prevent naming conflicts between diffrent projects | |
package tutorial; | |
//in what java package name your generated class should live |
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
#Reference: https://docs.djangoproject.com/en/1.9/ref/templates/api/#writing-your-own-context-processors | |
#This file is in yourapp/ directory | |
+from .models import Foo | |
+ | |
+def foo(request): | |
# you might need this line for unit tests | |
if request.user.is_authenticated and request.user.is_active: | |
+ count = len(Foo.objects.filter(user = request.user)) | |
+ return {"foo_count" :count} |
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
//The original sample is from here: http://syntx.io/how-to-send-an-http-request-from-android-using-httpurlconnection/ | |
//Deprecated funcitons and non-working code are modeifed. | |
//For more reference, please visit: http://developer.android.com/reference/java/net/HttpURLConnection.html | |
//I am using Google Books APIs for this sample. | |
//The returned book objects might have different format according to the language/country. (The second book obejct in data.json is the Japanese version) | |
//execute the AsyncTask some place in the UI thread | |
//new CatalogClient().execute("https://www.googleapis.com/books/v1/mylibrary/bookshelves/3/volumes?country=US"); | |