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}) |
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 { |
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; |
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; |
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); | |
} |
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() |
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 | |
} | |
} |
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 | |
} | |
} |
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 | |
} | |
} |
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