This guide has more than 100+ AI Tools & Prompts to help you learn how to use ChatGPT to enhance your life.

For programming

  1. Tabnine: https://www.tabnine.com/
  2. OpenAI Codex: https://openai.com/blog/openai-codex/
  3. GitHub Copilot: https://github.com/features/copilot
  4. AI Commit: https://github.com/abi/autocommit
  5. DeepCode: https://www.deepcode.ai/
  6. AI2Sql: https://www.ai2sql.io/
  7. Replit: https://replit.com/site/ghostwriter
  8. Akkio: https://www.akkio.com/
  9. Httpie: https://httpie.io/blog/ai
  10. Mutable: https://mutable.ai/
  11. Sheetplus: https://sheetplus.ai/
  12. ExcelFormulaBot: https://excelformulabot.com/

    Marketing Tools.

       
  1. Frase: https://www.frase.io/
  2. Bertha: https://bertha.ai/
  3. ContentEdge: https://www.contentedge.com/
  4. ChatGPT3: https://chat.openai.com/
  5. Hemingwayapp: https://hemingwayapp.com/
  6. Surfer SEO: https://surferseo.com/
  7. Ponzu: https://www.ponzu.ai/
  8. Jasper: https://www.jasper.ai/
  9. Copy Smith: https://copysmith.ai/
  10. PepperType: https://peppertype.ai/
  11. Scalenut: https://www.scalenut.com/
  12. Mutiny: https://www.mutinyhq.com/
  13. Simplified : https://simplified.com/ai-writer/
  14. MoonBeam: https://www.gomoonbeam.com/
  15. Smartly: https://www.smartly.io/
  16. Seventh Sense: https://www.theseventhsense.com/
  17. Copy AI : https://www.copy.ai/
  18. MarketMuse: https://www.marketmuse.com/
  19. WriteSonic: https://writesonic.com/
  20. Phrasee: https://phrasee.co/
Sales Tools.

          
  1. Creatext: https://www.creatext.ai/
  2. Exceed: https://exceed.ai/
  3. Creaitor: https://www.creaitor.ai/
  4. Twain: https://www.usetwain.com/
  5. Lavender: https://www.lavender.ai/
  6. Regie: https://www.regie.ai/
  7. People: http://people.ai/
  8. Smartwriter: https://www.smartwriter.ai/
  9. Octane: https://www.octaneai.com/
  10. Warmer: http://warmer.ai/
Writing AI Tools.

        
  1. Copy AI : https://www.copy.ai/
  2. Jasper: https://www.jasper.ai/
  3. WriteSonic: https://writesonic.com/
  4. ChatGPT3: https://chat.openai.com/
  5. Headlime: https://headlime.com/
  6. PepperType: https://peppertype.ai/
  7. MarkCopy: https://www.markcopy.ai/
  8. Quillbot: https://quillbot.com/
  9. Rytr: https://rytr.me/
  10. MoonBeam: https://www.gomoonbeam.com/
  11. Simplified : https://simplified.com/ai-writer/
  12. Lex Page: https://lex.page/
  13. Copy Smith: https://copysmith.ai/
  14. Subtxt: https://subtxt.app/
  15. Ellie Email Assistant: https://tryellie.com/
  16. Wordtune: https://www.wordtune.com/
  17. Sudowrite: https://www.sudowrite.com/
  18. Novel: https://novelai.net/
  19. Compose: https://www.compose.ai/

Chatbots Tools.
            
  1. Landbot: https://landbot.io/
  2. Cresta: https://cresta.com/
  3. Kaizan: https://kaizan.ai/
  4. WotNot: https://wotnot.io/
  5. Cohere: https://cohere.ai/
  6. Tidio: https://www.tidio.com/
  7. Typewise: https://www.typewise.app/
  8. Quickchat: https://www.quickchat.ai/
 Daily Workplace Tools.
          
  1. Notion AI: https://www.notion.so/product/ai
  2. Craft: https://www.craft.do/
  3. Mem: https://mem.ai/
  4. Taskade: https://www.taskade.com/
  5. You: https://you.com/
  6. Todoist: https://todoist.com/integrations/apps/ai-assistant

Design Tools.

           
Speech Tools.

           
  1. Resemble: https://www.resemble.ai/
  2. Broadn: https://www.broadn.io/
  3. Podcast: https://podcast.ai/
  4. Fliki: https://fliki.ai/
  5. Wellsaidlabs: https://wellsaidlabs.com/
  6. Voicemod: https://www.voicemod.net/ai-voices/
  7. Otter: https://otter.ai/
  8. TLDR This: https://tldrthis.com/
  9. Glasp AI: https://glasp.co/ai-summary
  10. Sembly: https://www.sembly.ai/
  11. Summari: https://www.summari.com/products/chrome
  12. Coqui: https://coqui.ai/
Leisure Time Tools.

        
  1. HairStyle: https://www.hairstyleai.com/
  2. AI Detector: https://crossplag.com/detecting-if-a-text-is-ai-generated/
  3. AI Community: https://huggingface.co/
  4. Talk to Books: https://books.google.com/talktobooks/
Workplace Tools.

            
  1. Designs: https://designs.ai/
  2. Beautiful: https://www.beautiful.ai/
  3. Slides: https://www.slidesai.io/
  4. Synthesia: https://www.synthesia.io/
  5. Pitch: https://pitch.com/
  6. Poised: https://www.poised.com/
  7. Lalal: https://www.lalal.ai/
  8. Krisp: https://krisp.ai/
  9. Murf: https://murf.ai/
  10. Jukebox: https://openai.com/blog/jukebox/
  11. Narakeet: https://www.narakeet.com/
  12. Big Speak AI: https://bigspeak.ai/
  13. Descript: https://www.descript.com/
  14. Assembly: https://www.assemblyai.com/
  15. Article Audio: https://article.audio/
  16. BeyondWords: https://beyondwords.io/
  17. Lumen5: https://lumen5.com/
  18. Supercreator: http://supercreator.ai/
  19. Movio: https://www.movio.la/
  20. Zoomscape: https://zoomscape.ai/
  21. Presentation: https://presentations.ai/
Text to SQL Tools.

           
  1. AI2sql: https://www.ai2sql.io/
  2. Seek: https://www.seek.ai/
Image Generating & Processing Tools.

     
  1. Profile Picture: https://www.profilepicture.ai/
  2. Photosonic: https://photosonic.writesonic.com/
  3. Remove BG: https://www.remove.bg/
  4. Artbreeder: https://www.artbreeder.com/
  5. Magiceraser: https://magicstudio.com/magiceraser
  6. Krea: https://www.krea.ai/
  7. Lexica: https://lexica.art/
  8. Removal: https://removal.ai/
  9. Image Enlarger: https://imglarger.com/
  10. Watermark Removal : https://www.watermarkremover.io/
  11. Rodebudai: https://www.rosebudai.com/
  12. Hypotenuse: https://www.hypotenuse.ai/
  13. Nyx: https://nyx.gallery/
  14. AI Avatar: https://avatarai.me/
  15. Cutout Pro: https://www.cutout.pro/
  16. Passport Photo: https://passphoto.ai/
  17. Picso: https://picso.ai/
  18. Playground: https://www.playgroundai.com/
  19. Runway: https://runwayml.com/
  20. Profile Pic Maker: https://pfpmaker.com/
  21. HotPot: https://hotpot.ai/
  22. Mage: https://www.mage.space/

Twitter Tools.

         
  1. Tribescaler: https://tribescaler.com/
  2. Postwise: http://postwise.ai/
  3. TweetHunter: https://tweethunter.io/
  4. TweetGPT: https://github.com/yaroslav-n/tweetGPT

  •  Blog Writing Prompts.

    1. "I'm looking for a [type of blog post] that will speak directly to my [ideal customer persona] and persuade them to take [desired action] on my [website/product]."
    2. "I'm looking for a [type of blog post] that will establish trust and credibility with my [ideal customer persona] by highlighting the successes and testimonials of previous customers who have used my [product/service]."
    3. "I need a [type of blog post] that will convince my [ideal customer persona] to purchase my [product/service] by highlighting its unique benefits and addressing any potential objections."
    4. "I need a [type of blog post] that will make my [ideal customer persona] feel [emotion] about my [product/service] and persuade them to take [desired action] with a sense of urgency."
    5. "I need a [type of blog post] that will overcome objections and concerns my [ideal customer persona] may have about my [product/service] and convince them to take [desired action]."
    6. "I'm looking for a [type of blog post] that will showcase the unique features and benefits of my [product/service] to [ideal customer persona] and persuade them to make a purchase."
    7. "I'm looking for a [type of blog post] that will clearly explain the features and benefits of my [product/service] to [ideal customer persona] and persuade them to make a purchase with a strong call-to-action."
    8. "I'm looking for a [type of blog post] that will draw in my [ideal customer persona] with a strong headline and hook, and then convince them to take [desired action] with persuasive language and compelling evidence."
    9. "I need a [type of blog post] that will address the pain points and needs of my [ideal customer persona] and show them how my [product/service] is the solution they've been searching for."
    10. "I need a [type of blog post] that will speak directly to the needs and pain points of my [ideal customer persona] and persuade them to take [desired action] with a sense of urgency and strong offer."
    11. "I'm looking for a [type of blog post] that will showcase the value and benefits of my [product/service] to [ideal customer persona] and convince them to take [desired action] with social proof and credibility-building elements."
    12. "I'm looking for a [type of blog post] that will educate my [ideal customer persona] on a specific [topic] and persuade them to take [desired action] on my [website/product]."
    13. "I need a [type of blog post] that will tell a story about my [product/service] and how it has helped [ideal customer persona] achieve their [goal] in a relatable and engaging way."
    14. "I'm looking for a [type of blog post] that will engage my [ideal customer persona] with a unique and compelling perspective on [subject] and persuade them to take [desired action] on my [website/product]."
    15. "I need a [type of blog post] that will provide valuable and relevant information to my [ideal customer persona] and persuade them to take [desired action] on my [website/product]."
  • YouTube Ad Scripts Prompts.

    1. "I need a YouTube ad script that will provide valuable and relevant information to my [ideal customer persona] and persuade them to take [desired action] on my [website/product]."
    2. "I need a YouTube ad script that will showcase the unique features and benefits of my [product/service] to my [ideal customer persona] and persuade them to make a purchase with social proof and credibility-building elements."
    3. "I need a YouTube ad script that will overcome objections and concerns my [ideal customer persona] may have about my [product/service] and convince them to take [desired action] with a sense of urgency."
    4. "I'm looking for a YouTube ad script that will introduce my [product/service] to my [ideal customer persona] and persuade them to take [desired action] with a strong call-to-action and compelling visuals."
    5. "I'm looking for a YouTube ad script that will showcase the value and benefits of my [product/service] to my [ideal customer persona] and persuade them to take [desired action] with a strong offer and clear call-to-action."
    6. "I'm looking for a YouTube ad script that will clearly explain the features and benefits of my [product/service] to my [ideal customer persona] and persuade them to make a purchase with a sense of urgency."
    7. "I need a YouTube ad script that will tell a story about my [product/service] and how it has helped [ideal customer persona] achieve their [goal] in a relatable and engaging way."
    8. "I'm looking for a YouTube ad script that will draw in my [ideal customer persona] with a strong headline and hook, and then convince them to take [desired action] with persuasive language and compelling evidence."
    9. "I'm looking for a YouTube ad script that will speak directly to the needs and pain points of my [ideal customer persona] and persuade them to take [desired action] with a sense of urgency and strong offer."
    10. "I need a YouTube ad script that will address the pain points and needs of my [ideal customer persona] and show them how my [product/service] is the solution they've been searching for."
    11. "I'm looking for a YouTube ad script that will establish trust and credibility with my [ideal customer persona] by highlighting the successes and testimonials of previous customers who have used my [product/service]."
    12. "I need a YouTube ad script that will educate my [ideal customer persona] on a specific [topic] and persuade them to take [desired action] on my [website/product]."
    13. "I need a YouTube ad script that will showcase the unique selling points of my [product/service] and persuade my [ideal customer persona] to make a purchase with a sense of urgency and exclusive offers."
    14. "I'm looking for a YouTube ad script that will draw in my [ideal customer persona] with a relatable and authentic message, and then persuade them to take [desired action] with a strong call-to action and compelling visuals."
    15. "I'm looking for a YouTube ad script that will engage my [ideal customer persona] with a unique and compelling perspective on [subject] and persuade them to take [desired action] on my [website/product]."
  • YouTube Video Ideas Prompts.

    1. "I need a YouTube video idea that will both go viral and persuade my [ideal customer persona] to take [desired action] on my [website/product] with a strong call-to-action and compelling visuals."
    2. "I'm looking for a YouTube video idea that will tell a unique and relatable story about my [product/service] and how it has helped [ideal customer persona] achieve their [goal]."
    3. "I need a YouTube video idea that will showcase the unique features and benefits of my [product/service] in a fun and creative way, and persuade my [ideal customer persona] to make a purchase."
    4. "I'm looking for a YouTube video idea that will showcase the value and benefits of my [product/service] to my [ideal customer persona] and persuade them to take [desired action] with a strong offer and clear call-to-action."
    5. "I'm looking for a YouTube video idea that will provide valuable and relevant information to my[ideal customer persona] about [subject] and persuade them to take [desired action] on my [website/product]."
    6. "I need a YouTube video idea that will overcome objections and concerns my [ideal customer persona] may have about my [product/service] and convince them to take [desired action] with a sense of urgency."
    7. "I'm looking for a YouTube video idea that will go viral and showcase my [product/service] to my [ideal customer persona] in a creative and entertaining way."
    8. "I need a YouTube video idea that will showcase the success stories of previous customers who have used my [product/service] and persuade my [ideal customer persona] to make a purchase."
    9. "I need a YouTube video idea that will engage my [ideal customer persona] with a unique and compelling perspective on [subject] and persuade them to take [desired action] on my [website/product]."
    10. "I need a YouTube video idea that will provide a behind-the-scenes look at my [company/brand] and persuade my [ideal customer persona] to take [desired action] with a sense of authenticity and relatability."
    11. "I'm looking for a YouTube video idea that will provide a step-by-step guide on how to use my [product/service] and persuade my [ideal customer persona] to make a purchase with clear and compelling instructions."
    12. "I'm looking for a YouTube video idea that will draw in my [ideal customer persona] with a relatable and authentic message, and then persuade them to take [desired action] with a strong call-to-action and compelling visuals."
    13. "I'm looking for a YouTube video idea that will showcase the unique selling points of my [product/service] and persuade my [ideal customer persona] to make a purchase with a sense of urgency and exclusive offers."
    14. "I need a YouTube video idea that will demonstrate how my [product/service] can solve the specific pain points and needs of my [ideal customer persona] in a relatable and engaging way."
    15. "I need a YouTube video idea that will compare my [product/service] to similar options on the market and persuade my [ideal customer persona] to choose us with clear and compelling evidence."
     

 using java program with spring I need to create a java threadpool executor and this threadpool executor in application level. I have multiple kafka consumers reading records as batches from kafka topic. These consumers should run inside the threadpool executor and we need to shutdown the executor while application stops

  1. First, create a configuration class with the thread pool executor configuration:

@Configuration public class ExecutorConfig { @Bean public Executor taskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(10); executor.setMaxPoolSize(20); executor.setQueueCapacity(50); executor.setThreadNamePrefix("ConsumerThread-"); executor.initialize(); return executor; } }

  1. In your main class, create the kafka consumers and run them inside the thread pool executor:

@SpringBootApplication public class Application { private final Logger logger = LoggerFactory.getLogger(Application.class); @Autowired private Executor taskExecutor; public static void main(String[] args) { SpringApplication.run(Application.class, args); } @PostConstruct public void runConsumers() { for (int i = 0; i < 5; i++) { taskExecutor.execute(new KafkaConsumer("topic" + i)); } } class KafkaConsumer implements Runnable { private final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class); private final String topic; KafkaConsumer(String topic) { this.topic = topic; } @Override public void run() { logger.info("Running Consumer for topic: " + topic); //Code to run the kafka consumer for the topic } } }


  1. To shutdown the thread pool executor while application stops, we can add a shutdown hook in the main class:

  2. @SpringBootApplication
  3. public class Application { private final Logger logger = LoggerFactory.getLogger(Application.class); @Autowired private Executor taskExecutor; public static void main(String[] args) { SpringApplication.run(Application.class, args); } @PostConstruct public void runConsumers() { for (int i = 0; i < 5; i++) { taskExecutor.execute(new KafkaConsumer("topic" + i)); } } @PreDestroy public void shutDownExecutor() { if (taskExecutor instanceof ThreadPoolTaskExecutor) { ((ThreadPoolTaskExecutor) taskExecutor).shutdown(); } } class KafkaConsumer implements Runnable { private final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class); private final String topic; KafkaConsumer(String topic) { this.topic = topic; } @Override public void run() { logger.info("Running Consumer for topic: " + topic); //Code to run the kafka consumer for the topic } } }

  4. To shutdown the thread pool executor while application stops, we can add a shutdown hook in the main class:

  5. @SpringBootApplication public class Application { private final Logger logger = LoggerFactory.getLogger(Application.class); @Autowired private Executor taskExecutor; public static void main(String[] args) { SpringApplication.run(Application.class, args); } @PostConstruct public void runConsumers() { for (int i = 0; i < 5; i++) { taskExecutor.execute(new KafkaConsumer("topic" + i)); } } @PreDestroy public void shutDownExecutor() { if (taskExecutor instanceof ThreadPoolTaskExecutor) { ((ThreadPoolTaskExecutor) taskExecutor).shutdown(); } } class KafkaConsumer implements Runnable { private final Logger logger = LoggerFactory.getLogger(KafkaConsumer.class); private final String topic; KafkaConsumer(String topic) { this.topic = topic; } @Override public void run() { logger.info("Running Consumer for topic: " + topic); //Code to run the kafka consumer for the topic } } }

 This program also creates an ArrayList called "numbers" and adds some integers to it.

 It then uses a for loop to iterate through the ArrayList, and compares each element to

 the current smallest element. If a smaller element is found, it

 is assigned to the variable "smallest". Finally, the smallest element is printed to the console.


 import java.util.ArrayList;


public class SmallestElementArrayList {

    public static void main(String[] args) {

        ArrayList<Integer> numbers = new ArrayList<>();

        numbers.add(3);

        numbers.add(2);

        numbers.add(5);

        numbers.add(1);

        numbers.add(4);


        int smallest = numbers.get(0);

        for (int i = 1; i < numbers.size(); i++) {

            if (numbers.get(i) < smallest) {

                smallest = numbers.get(i);

            }

        }

        System.out.println("Smallest element in the ArrayList is: " + smallest);

    }

}

Here is a simple java program for apache kafka consumer. This java program is ready to use in your code base or project.
 import java.util.Collections; 
import java.util.Properties; 
 import org.apache.kafka.clients.consumer.ConsumerConfig; 
import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.consumer.ConsumerRecords;
 import org.apache.kafka.clients.consumer.KafkaConsumer;
 public class KafkaConsumerExample {

 public static void main(String[] args) {

 Properties props = new Properties();
 props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(ConsumerConfig.GROUP_ID_CONFIG, "myGroupId"); props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");

 KafkaConsumer consumer = new KafkaConsumer<>(props);
 consumer.subscribe(Collections.singletonList("myTopic")); 

 while (true) {
 ConsumerRecords records = consumer.poll(100); 
 for (ConsumerRecord record : 

records) { 

 System.out.println(record.value()); 
 } 
 } 
 } 
}

This example assumes that Kafka is running on the local machine at port 9092, 
 continuously poll for new messages on the topic and print the value of each message it receives.

Note that for production use, you should consider adding error
 handling and offset committing logic to the consumer code.
Its very easy to remove unnecessary imports and characters while saving a file in eclipse.This will help to avoid sonar issues in our code base.

go to eclipse-> preferences->Java -> Editor->Save Actions and give the below checkbox options as looks in picture below.




also do the advanced level setting by clicking configure button













Lets assume we want to go to a trip to Paris.What we will do ? You have to plan everything

1) Book your flights
2)Book your hotels to stay
3)Book your car rental for travelling in Paris
4)Book your amenity pass for visiting different places

assume that you have done all the booking advance and there is an email from flight authority that the flight scheduled is cancelled and it is rescheduled to next day. What you will do?

you have to reschedule all the above bookings to next day and to communicate all the different agencies(hotel/car rental/amenity pass center). This is a pain for you by this unexpected channges happened right?  Now think about a situation that your booking is done by a travel agency including 
all the booking and because of flight delay they rescheduled everything by themself without charging
any extra dollar from you and you will be able to travel on the same day without any delay !!

How it will feel ? nice right. You dont bother about the rescheduling and re booking of all your tickets, travel agency will take care of everything. Would that be better than booking tickets by ourselves? If yes, then welcome to dependency injection.


The whole example is easily clonable or download from GitHub repository

Dependency injection is a framework that takes care of creating objects for us without having to worry about providing the right tickets so to say.

Explanation

Consider we have a class Student and this class need to write a test need help on another class WriteTest() which will help us to write a test for a student.
   package com.johnjustin;

public class AttendExam {
 
 public void writeTest(final String ExamName, final String subject) {
     System.out.printf("writeTest : %s, %s%n", ExamName, subject);
   }

}

package com.johnjustin;

public class Student {
  private AttendExam attendExam = new AttendExam();

  public void writeTest(){
    attendExam.writeTest("Engineering", "Mathematics");
  }
}


This is the simplest way to fulfill the requirement but we know that this has some limitations

1)There is a tight dependency on AttendExam class on Student class.
2) if there is a design change planned on writeTest() method with different parameters and there might be changes happened for different types of exams like online exam and offline written exam
we should go to all the places wherever this AttendExam written will be changed.
3)After sometimes there is new requirement came and we have to implement 2 types of tests.Online assessment and offline written test at this scenario it will be difficult for us to maintain same AttendExam class.
These limitations can be improved by changing the way we think and refactor our code in a modular way.We can avoid these limitations by implementing dependency injection by modular way.


1)Create Interface
2)Implement Interface
3)integrate DI using any(Spring/Guice) framework

these three steps will help to decouple the tight dependencies between classes and it will be easy to migrate newer version of changes and updation of existing features without changing the current codes.

Create Interface

We will create an interface AssessmentService where we define a common method writeTest with parameters.So there must be different types of test either online test or written test both classes will inherit this AssessmentService and implement writeTest for their own exam implementation.
package com.johnjustin;

public interface AssessmentService {
 
 void writeTest(String subject, String testName);

}

Implement Interfaces

We have listed some limitations above and there is requirement to implement 2 types of tests online assessment and offline written tests. We have created 2 different classes OnlineExamService and WrittenExamService for these tests and it will inherit the feature of AssessmentService interface's writeTest method.
    package com.johnjustin;

/**
 * @author John Justin
 *
 */
public class WrittenExamService implements AssessmentService{
 
 public void writeTest(final String ExamName, final String subject) {
     System.out.printf("Written Exam for : %s, %s%n", ExamName, subject);
   }


}
    package com.johnjustin;

/**
 * @author John Justin
 *
 */
public class OnlineExamService implements AssessmentService{
 
 public void writeTest(final String ExamName, final String subject) {
     System.out.printf("Online Exam for : %s, %s%n", ExamName, subject);
   }

}
Use interfaces to reduce loosely couple the classes. We have to use this AssessmentService in our Student class and implement required type of assessment(Online/Written) according to the need.This is a key element in the design. It improves modularity, extendibility.
  
     package com.johnjustin;
import com.johnjustin.AssessmentService;
import com.google.inject.Inject;

/**
 * @author John Justin
 *
 */
public class Student {

 private final AssessmentService assessmentService;
 
 @Inject
 private Student(AssessmentService assessmentService){
  
  this.assessmentService = assessmentService;
 } 
 
 public void attendExam() {
   assessmentService.writeTest("Engineering", "Mathematics");
    }
  
 
}

 
The Student class is not dependent on any implementation, but on a service defined by an interface. This means that we can use the Student class without having to worry about the underlying implementation of the assessment service. Furthermore, different Student instances can be instantiated using different assessment services.

Integrate DI using any(Spring/Guice) framework


dependency injection can help us initializing objects and provide these objects all the necessary resources . For example, the Student class requires an instance of AssessmentService. The dependency injection framework( Guice here) will provide that for us. So to create an instance of Student class.

The dependency injection framework(Guice) will create an instance of the Student class and provide an instance of the AssessmentServiceto the Student object.

How to integrate google Guice dependency frame work in our programe?
how does the dependency injection framework knows how to initialise the AssessmentService?

Usage of Dependency Injection requires that the software we write to declare the dependencies, and lets the framework or the container work out the complexities of service instantiation, initialization, sequencing and supplies the service references to the clients as required. To decouple Java components from other Java components the dependency to a certain other class should get injected into them rather that the class itself creates / finds this object.    

The general concept between dependency injection is called Inversion of Control. A class should not configure itself but should be configured from outside.          

 We need to tell the dependency injection framework how to create an instance of AssessmentService. With Guice we do that by creating a module (a class that extends AbstractModule class) as illustrated below. 

We should tell the Guice dependency framework to how to create an instance of AssessmentService class.We should add an annotation in Student class in order to allow the dependency injection framework to inject the necessary parameters.
 
     package com.johnjustin;

import com.google.inject.AbstractModule;

/**
 * @author John Justin
 *
 */
public class ProjectModule extends AbstractModule {
 
 @Override
   protected void configure() {
     bind(AssessmentService.class).to(OnlineExamService.class);
   }

}
        package com.johnjustin;
import com.johnjustin.AssessmentService;
import com.google.inject.Inject;

/**
 * @author John Justin
 *
 */
public class Student {

 private final AssessmentService assessmentService;
 
 @Inject
 private Student(AssessmentService assessmentService){
  
  this.assessmentService = assessmentService;
 } 
 
 public void attendExam() {
   assessmentService.writeTest("Engineering", "Mathematics");
    }
  
 
}
Now we can create the main class and create its injection in it.
package com.johnjustin;

import com.google.inject.Guice;
import com.google.inject.Injector;

/**
 * @author  John Justin
 *
 */
public class Main {
 
 
  public static void main(final String[] args) {
      final Injector injector = Guice.createInjector(new ProjectModule());
      final Student student = injector.getInstance(Student.class);
      student.attendExam();
    }

}

Advantages of DI


Dependency injection is a pattern used to create instances of classes that other classes rely on without knowing at compile time which implementation will be used to provide that functionality.

Easily changing the the exam type from online exam service to written exam service.We only need to change the ProjectModule class to map the AssessmentService class to the WrittenExamService class as highlighted below.This one change will affect all classes initialised with the dependency injection framework without having to change any of these classes.
package com.johnjustin;

import com.google.inject.AbstractModule;

/**
 * @author John Justin
 *
 */
public class ProjectModule extends AbstractModule {
 
 @Override
   protected void configure() {
     bind(AssessmentService.class).to(WrittenExamService.class);
   }

}

The whole example is easily clonable or download from GitHub repository.Enjoy !!!!!