Skip to content

Instantly share code, notes, and snippets.

View gist:6963e23edaf7c4b6371decdb0118fe07
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
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
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
public interface PaymentStrategy {
public void pay(int amount);
}
public class CreditCardStrategy implements PaymentStrategy {
private String name;
private String cardNumber;
View gist:57ca7817072bbae5bf398aec15ea7eb5
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
class Singleton {
//static field
private static Singleton object;
//private Construtor
private Singleton() {}
//static method
public static synchronized Singleton getInstance()
View gist:22ce1e575e9124c8cfcd30351186c891
public class Triangle implements Polygon {
@Override
public void calculateArea() {
// TODO
}
}
View gist:49e2569819078bb5f689524c500f0111
public class Rectangle implements Polygon {
@Override
public void calculateArea() {
// TODO
}
}
View gist:925cd7d9f9f4a17fb512e524177a6259
public class Square implements Polygon {
@Override
public void calculateArea()
{
// TODO
}
}