javarevisited

javarevisited


Inversion of Control and Dependency Injection design pattern with real world Example - Spring tutorial

Posted: 15 Dec 2012 07:29 AM PST

Inversion of Control and Dependency Injection is a core design pattern of Spring framework. IOC and DI design pattern is also a popular design pattern interview question in Java. As name suggest Inversion of control pattern Inverts responsibility of managing life cycle of object e.g. creating object, setting there dependency etc from application to framework, which makes writing Java application even more easy. Programmer often confused between IOC and DI, well both words used interchangeably in Java world but Inversion of Control is more general concept and Dependency Injection is a concrete design pattern. Spring framework provides two implementation of IOC container in form of Application Context and BeanFactory which manages life-cycle of bean used by Java application. As you may know necessity is mother of invention, it benefit to first understand problem solved by IOC and Dependency Injection design pattern. This makes your understanding more clear and concrete. We have touched basics of Dependency Injection and Inversion of control in our article 10 OOPS and SOLID design principles for Java programmer and this Java article tries to explain it by taking a real life example of Service based architecture popular in enterprise Java development. In this Spring or design pattern tutorial we will first see normal implementation of AutditService class, a class in this example which provides auditing in enterprise Java application and than use of dependency Injection. This will  allow us to find out problems and how they are solved by Dependency injection design pattern. . Also there are multiple way to inject dependency in spring e.g. Setter Injection or Constructor Injection, which uses setter method and constructor for injecting dependency, see Setter injection vs Constructor injection  to find out when to use them.
Read more »

'javac' is not recognized as an internal or external command - cause and solution

Posted: 15 Dec 2012 12:30 AM PST

So you are trying to compile your Java source file and getting "'javac' is not recognized as an internal or external command". If this is your first Java program or HelloWorld than I suggest to go through How to compile and run HelloWorld in Java because that explains what do you need before you compile and run any Java program. If you have crossed that level and knows about How to set PATH in Java then there is something wrong while setting PATH in Java. Anyway let's see when does you get this error and from where does 'javac' is not recognized as an internal or external command comes. This is an standard error in Windows command line when you type a command which is not available in System PATH, here javac command which is used to compile Java source file and produces class files are not in PATH. Best way to verify this is executing following command :

# echo %PATH%

If you see your JDK installation folder or JAVA_HOME in PATH and included bin directory which contains all java binaries including javac and java commands which is used to compile and run Java program. Most likely your PATH may not have JDK/bin in PATH, if that's the case just include bin folder of JDK in your PATH. See how to set PATH for Java in Windows for step by step guide.

Cause of 'javac' is not recognized as an internal or external command

Cause of 'javac' is not recognized as an internal or external command  fix solution
Other cause of  " javac is not recognized as an internal or external command " could be that you only have JRE in your System and not JDK, which means you can only run already compiled Java program and can not compile Java program because JRE doesn't contain javac in there bin folder. To know more about JRE and JDK, see difference between JRE and JDK. In this case you need to download and install Java in your System. You can download current version of Java from Oracle's site.

Another possible reason of  " javac is not recognized as an internal or external command "  is setting PATH with incorrect directory e.g. path may not contain forward slash or missed something. Best way to verify this is just copy path of JDK from PATH variable and execute in command line, if you can not get into that directory which means path to JDK installation folder is incorrect. In this case go to bin directory of JDK installation directory and copy its address from address bar and add into PATH to make this work.

So root cause of  "javac is not recognized as an internal or external command " is that system is not able to find javac command from its PATH. just double check PATH and add bin folder of JDK installation directory in path, if not included already. Remember to close and re open command prompt once you make this change, this will fix  " javac is not recognized as an internal or external command " error.

Other Java tutorials for Beginners


Post a Comment