View gist:6963e23edaf7c4b6371decdb0118fe07
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
1. Write a MongoDB query to display all the documents in the collection restaurants. | |
db.restaurants.find().pretty() | |
or | |
db.restaurants.find() | |
2. Write a MongoDB query to display the fields restaurant_id, name, borough and cuisine for all the documents in the collection restaurant | |
db.restaurants.find({}, {"restaurant_id":1, "name":1,"borough":1 , "cuisine":1}) | |
3. Write a MongoDB query to display the fields restaurant_id, name, borough and cuisine, but exclude the field _id for all the documents in the collection restaurant. | |
db.restaurants.find({}, {"restaurant_id":1, "name":1,"borough":1 , "cuisine":1, "_id":0}) |
View gist:fc1faab091372d81399f28de3b895dac
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
Step 1 : Create abstract and concrete classes | |
//abstract class Pizza | |
public abstract class Pizza { | |
public abstract void bakePizza(); | |
} | |
//CheesePizza subclass | |
public class CheesePizza extends Pizza { |
View gist:7341e898ef3136d0d4086293307d5056
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 Person { | |
private final String firstName; // required | |
private final int age; | |
private final String phone; | |
private Person(PersonBuilder builder) { | |
this.firstName = builder.firstName; | |
this.age = builder.age; | |
this.phone = builder.phone; |
View gist:2430f35943363f2f0dbc8f207ecccb78
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
public interface PaymentStrategy { | |
public void pay(int amount); | |
} | |
public class CreditCardStrategy implements PaymentStrategy { | |
private String name; | |
private String cardNumber; |
View gist:57ca7817072bbae5bf398aec15ea7eb5
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
interface DatabaseExecuter { | |
public void executeDatabase(String query); | |
} | |
class DatabaseExecuterImpl implements DatabaseExecuter { | |
@Override | |
public void executeDatabase(String query) { | |
System.out.println("Going to execute Query: " + query); | |
} |
View gist:383999f5bcb23b431d5959d384ae6438
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 Singleton { | |
//static field | |
private static Singleton object; | |
//private Construtor | |
private Singleton() {} | |
//static method | |
public static synchronized Singleton getInstance() |
View gist:22ce1e575e9124c8cfcd30351186c891
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
public class Triangle implements Polygon { | |
@Override | |
public void calculateArea() { | |
// TODO | |
} | |
} |
View gist:49e2569819078bb5f689524c500f0111
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
public class Rectangle implements Polygon { | |
@Override | |
public void calculateArea() { | |
// TODO | |
} | |
} |
View gist:925cd7d9f9f4a17fb512e524177a6259
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
public class Square implements Polygon { | |
@Override | |
public void calculateArea() | |
{ | |
// TODO | |
} | |
} |
View gist:7a3a7760226f84905a59ad7cec44cf70
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
interface Polygon { | |
void calculateArea(); | |
} |
NewerOlder