Home
Videos uploaded by user “Philip Starritt”
Java Clean Code Tutorial #3 - Builder Design Pattern Example
 
12:47
Episode 3 of the free Java Clean Code Training Series. So what is the builder pattern and why is it needed? The Gang of Four Builder pattern is an object creation software design pattern. It solves many problems and challenges such as the never-ending constructor parameter anti-pattern. Benefits of the java builder pattern: - No need to pass Null objects into the constructor. - You don’t need to guess or try to work out which constructor parameter maps to a certain object’s field. Error prone! - Easily made into an Immutable class. You can now share the object safely between threads or in a multi-threaded environment as you don’t need to worry about mutation of variable state. - Provides control over object construction steps and provides meaningful semantic method names. - Increases the use-ability, maintainability and readability of code when creating objects. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 4, Philip
Views: 13157 Philip Starritt
Project Lombok Java 8 Builder Example (Part 8)
 
01:49
In this tutorial I show you how to use Project Lombok Builder annotations in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide: https://projectlombok.org/setup/eclipse Java Project Lombok: https://projectlombok.org/ Eclipse IDE Download: http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all Project Lombok Builder annotation Example https://projectlombok.org/features/builder
Views: 2490 Philip Starritt
Spring Boot RESTful Web Service Tutorial - Java REST API
 
06:08
Simple tutorial on how to create a Java RESTful Web Service with Spring Boot. In this 5 minute tutorial I will show you how easy it is to expose a vanilla RESTful Webservice. Spring offers an extensive list of rich features and functionality for developing resilient web services. INITIALIZR - https://start.spring.io/ Spring Boot - http://projects.spring.io/spring-boot/ Thanks to Spring Boot. If you enjoyed the video, please share, comment & subscribe for more great content! Enjoy! Philip
Views: 13784 Philip Starritt
Spring Boot Security Example
 
21:56
In this Spring Boot Security tutorial I show you how to secure your RESTful endpoints & controllers with spring security. I first start off my creating a standard spring boot project and add a couple of RESTful endpoints via spring’s @RestController and @RequestMapping annotations. At this stage spring security is not on the classpath so the URLs are all open to HTTP requests. I then add the spring-boot-starter-security dependency to the classpath via a simple maven dependency and perform a project update. If spring security is on the classpath then the web application will automatically be secured with basic authentication on all HTTP endpoints when there is no bean annotated with @EnableWebSecurity. The default username and password is ‘user’ and a random UUID password is generated each time the application starts, you can see this in the start-up logs. Do not use this in production. After showing the automatic spring security basic authentication on all endpoints, I then create a java class annotated with @EnableWebSecurity. The class SecurityConfig extends WebSecurityConfigurerAdapter and overrides the configure(HttpSecurity http) method. This method disables the default HTTP Spring Security and allows us to define our own fine grained http security on our RESTful endpoints. I specified that the ant path expressions endpoints must have the defined roles associated with the login credentials. Within the bean annotated with EnableWebSecurity, I added and autowired an configureGlobal(AuthenticationManagerBuilder auth) method. This allows you to specify the type of authentication manager (LDAP, In-memory, Token based etc). I added two users with different roles and demo the application returning an http 403 unauthorized when an authenticated but unauthorized user attempted to access a specific endpoint. I hope you enjoyed this introductory spring security with spring boot example! Give it a go! Don’t forget to subscribe for more great tech videos :) Till next time, Phil Filmed at Newcastle County Down, Slieve Donard. Mourne Mountains. Links: Spring Security: https://projects.spring.io/spring-security/ Spring LDAP: http://projects.spring.io/spring-ldap/ Spring Security OAuth: http://projects.spring.io/spring-security-oauth/ Spring Security with Boot Tutorial: http://docs.spring.io/spring-security/site/docs/current/guides/html5/helloworld-boot.html Spring Security Reference: http://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/ Spring Boot Security Features: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-security.html OWASP (Open web application security project): https://www.owasp.org/index.php/Main_Page OWASP Java Projects: https://www.owasp.org/index.php/Category:OWASP_Java_Project Spring Tool Suite IDE: https://spring.io/tools HTTP 403 Forbidden: https://en.wikipedia.org/wiki/HTTP_403 HTTP Status Codes: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes Ant Patterns: http://ant.apache.org/manual/dirtasks.html#patterns Spring Framework AntPathMatcher: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/util/AntPathMatcher.html Mourne Mountains: https://en.wikipedia.org/wiki/Mourne_Mountains Slieve Donard: https://en.wikipedia.org/wiki/Slieve_Donard
Views: 35305 Philip Starritt
Java Heap Dump Analysis - VisualVM Tutorial
 
04:43
In this tutorial I show you how to use VisualVM to perform a Java Heap Dump snapshot in a live executing Java application in eclipse IDE. Ahem… Let me ask…First….What is Java VisualVM? Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java applications while they are running on a Java Virtual Machine (JVM), and for troubleshooting and profiling these applications. This includes objects allocated on the Heap, Thread state, Execution environment information, Stack etc. Great for debugging dog slow applications!! Ok cool, now what is a Heap Dump? A heap dump is a snapshot of the memory of a Java Process at a single point in time. This contains data about Java objects, classes in the heap, class, fields, references, class loader names, static content, Thread Stacks etc. And... Why would I create a Heap Dump? There are many, but here are my two favourites. When performing performance analysis on an application, performing a heap dump during certain execution phases will provide you will critical information on the state of the Java Process, such as object allocation on the heap and thread states. Second, when an application crashes due to a Java java.lang.OutOfMemoryError, you can enforce the JVM to perform a snapshot and capture the application’s state via a heap dump. This heap dump will typically be placed into a java_pid*[id].hprof file. You can then load the heap dump file into a visualizer to understand the java applications state – this provides a good insight and clue into why the program crashed. Although if your application is running on a cloud based ephemeral file system this may be tricky. But the majority of applications that require a heap dump for analysis are most likely not in the cloud and rather dedicated high performance data centers. Last one… You mentioned compressed Oops, whats that? Ill create another video but read this for now chum. http://docs.oracle.com/javase/8/docs/technotes/guides/vm/performance-enhancements-7.html Don’t forget to subscribe for more tech content! Cheers! Philip Links Eclipse VisualVM Launcher Integration Set-up Guide https://www.youtube.com/watch?v=W60wvJ885iE VisualVM https://visualvm.github.io/ Eclipse Visual VM Integration https://visualvm.github.io/idesupport.html Java Profiling http://docs.oracle.com/javase/7/docs/technotes/guides/visualvm/profiler.html
Views: 5610 Philip Starritt
Spring Boot Integration Test Example REST API Controller | Java MockMvc
 
14:19
In this tutorial i show you how to create Spring Boot Integration Tests in order to test REST API Controllers. Java spring testing tutorial for beginners. I first create a simple RESTFul Service. We then implement Spring's WebIntegrationTest and MockMvc Builder to discover and host our web services (spring controllers) during the junit integration test. Once the web services are created, we can invoke them locally using MockMvc. We can then assert on the expected HTTP request with Spring and hamcrest matchers. Return HTTP response if required. If you enjoyed the video, please share, comment & subscribe for more great content! Enjoy! Philip Spring MockMvc: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/web/servlet/MockMvc.html Spring ResultActions: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/web/servlet/ResultActions.html Spring Security MockMvc Test: http://docs.spring.io/spring-security/site/docs/current/reference/html/test-mockmvc.html Spring Boot Testing Features: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html Spring Boot, MockMvcBuilders, RESTController, WebApplicationContext, SpringApplicationConfiguration, SpringJUnit4ClassRunner, MockMvcRequestBuilders, MockMvcResultHandlers, MockMvcResultMatchers, Embedded Tomcat, Java, JUnit
Views: 10963 Philip Starritt
Project Lombok Constructors Example (Part 7)
 
01:38
In this tutorial I show you how to use Project Lombok @NoArgsConstructor, @RequiredArgsConstructor and @AllArgsConstructor annotations in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide: https://projectlombok.org/setup/eclipse Java Project Lombok: https://projectlombok.org/ Eclipse IDE Download: http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all Project Lombok EqualsAndHashCode annotation Example https://projectlombok.org/features/constructor
Views: 1250 Philip Starritt
VisualVM Eclipse Launcher - Java Profiling Tutorial
 
06:00
Introductory step-by-step guide how to use & set-up the Eclipse Java VisualVM plugin IDE integration. This also works for Spring Tool Suite (STS) and other eclipse IDE based distributions. Java Profiling Tools. What is VisualVM? Java VisualVM is a tool that provides a visual interface for viewing detailed information about Java applications while they are running on a Java Virtual Machine (JVM), and for troubleshooting and profiling these applications. This includes monitoring objects allocated on the Heap, Memory, Thread state, Execution environment Information, HeapDumps, Stack etc. Great for debugging dog slow applications!! Who would use a Java Profiler like VisualVM? Everyone! But especially anyone wanting to optimise their applications performance! This will identify heavily used methods, objects, Perform Heap Dumps, GC info and much more! Again, great for debugging dog slow applications! Guide: a) Download Eclipse Plugin. (Link below). b) Extract ZIP archive into any directory (D) c) Add local update site as directory (D) and select & install VisualVM Launcher. d) Ensure Launcher global preferences point to VisualVM and your JDK. e) Launch the java application with the new VisualVM Launcher. f) View your live java execution in VisualVM. Don’t forget to subscribe for more tech content! Cheers! Philip Links VisualVM https://visualvm.github.io/ Eclipse Visual VM Plugin Integration Guide https://visualvm.github.io/idesupport.html Visual VM Java Profiling Guide http://docs.oracle.com/javase/7/docs/technotes/guides/visualvm/profiler.html
Views: 4699 Philip Starritt
Spring Boot with Camel ActiveMQ JMS Example - Java AutoConfiguration
 
19:54
Step by step tutorial on how to implement a Spring Boot, ActiveMQ, JMS & Apache Camel Application using spring boot's auto configuration as of 2016-07-07. 00:00 - 00:46 - Tutorial introduction 00:46 - 01:53 - Java Project Maven Dependencies / Spring Starter Project via SPRING INITIALIZR 02:05 - 04:47 - Spring Boot ActiveMQ Connection Factory Auto Configuration Analysis & Configuration 04:47 - 09:30 - Configuring Spring JMS Transaction Manger and Camel JMS Component 09:30 - 14:06 - Create Camel Routes autoconfigured into the CamelContext. 14:06 - 15:13 - Running ActiveMQ Service & ActiveMQ Console 15:13 - 18:08 - Fixing common errors 18:08 - 19:25 - Running the application & Demo 19:35 - 19:54 - I hope you enjoyed the content & Subscribe In this example I used Spring Boot Parent 1.4.0.BUILD-SNAPSHOT to access NEW spring-boot-starter-activemq classes. I also used Camel-spring-boot-starter version 2.17.1. If you enjoyed this video, subscribe for more great content every week! Enjoy, Philip Links: Spring Boot Initializer: https://start.spring.io/ Spring Boot JMS ActiveMQ Support: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html Apache Camel JMS: http://camel.apache.org/jms.html Apache Camel ActiveMQ: http://camel.apache.org/activemq.html Apache Camel Transactional client: http://camel.apache.org/transactional-client.html Apache ActiveMQ: http://activemq.apache.org/
Views: 16411 Philip Starritt
Java Clean Code Tutorial #1 - Eclipse Compiler Build Errors & Warnings Preferences
 
05:16
Episode 1 of the free Java Clean Code Training Series. Many new and experienced Java developers often overlook the importance of having high severity levels on their Eclipse IDE Java Compiler Errors & Warnings. This simple IDE feature can and will identify many bugs early on and stop them from progressing into source control. Eclipse, Spring Tool Suite and many other IDEs have customisable compiler build / warning preference levels. To access go to Preferences, Java, Compiler, Errors/Warnings. I suggest you review your current severity levels and adjust the majority to ERROR. This will flag up many unseen bugs, potential programming problems, unnecessary code and improvements at compile time. E.g. Unreachable code, null pointer access and redundant code. Once you are happy with your settings, you can export the preferences to a .pref file via File, Export, Preferences. To import the file, File, Import, Preferences. You can share this file with your team and also import it to any new workspaces you may have. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 2, Philip
Views: 6321 Philip Starritt
Spring Boot Properties File and Profiles Tutorial | Externalised Environment Configuration
 
10:08
Hi, Use Spring Boot to externalise your environment specific runtime configuration. Environment specific configuration is usually stored in properties files, YAML files and command line arguments. In this tutorial i will show you how to specifically configure your application for the environment it is deployed into. Having externalised configuration will allow you to propagate your single generated software artefact through your different environments (E.g. Dev, Test, Production). I first created an application.properties and placed it on the application's CLASSPATH. This is one of four locations Spring Boot will look for the default properties file. Properties configured here will be common for all environments unless explicitly overridden. See Spring Boot Features, 24. Externalized Configuration for properties order. I then created an application-{environment}.properties file for each environment. The {environment} is substituted for the spring profile. This can be set using -Dspring.profiles.active virutal machine argument. This is passed into the application on bootup, so from your deployment YAML file / bash shell script etc. E.g. Set your spring profile per environment: -Dspring.profiles.active=local -Dspring.profiles.active=dev -Dspring.profiles.active=test -Dspring.profiles.active=production This will then loads the common application.properites THEN the environment specific properties file. One of: application-local.properties application-dev.properties application-test.properties application-production.properties Spring will then substitute the properties throughout its configuration of the spring container. Enjoy! Philip Spring Boot Externalized Configuration - http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html Spring Boot Reference Guide - http://docs.spring.io/spring-boot/docs/current/reference/html/ Java Environment Variables - https://docs.oracle.com/javase/tutorial/essential/environment/env.html Java Properties Files - https://docs.oracle.com/javase/tutorial/essential/environment/properties.html
Views: 10184 Philip Starritt
Spring Boot REST Integration Test with Mockito Java JUnit Tutorial
 
14:54
In this tutorial I show you how to Mock your Spring controller service classes with the new Spring Boot 1.4+ Mockito annotations. I start by taking a test driven development approach. I create a Spring Boot RESTful webservice controller and test it with a @WebMvcTest and MockMvc class. I then expanded the controller to contain a service class. In the junit test, I defined the service class and annotated it with @MockBean. This annotation is used to define a Mockito mock for a bean inside your ApplicationContext. I was then able to use the Mockito BDD behaviour driven development static imports to define what should be returned from the mockito mock object method calls. After The MockMvc test, I verified via mockito static imports that the mock was called once. Don't forget to subscribe for more great tech content! Enjoy! Philip Links: Testing improvements in Spring Boot 1.4: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4 Spring Boot Testing: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html Junit: http://junit.org/junit4/ Mockito: http://site.mockito.org/ Building REST services with Spring Boot: https://spring.io/guides/tutorials/bookmarks/ Spring Boot: https://projects.spring.io/spring-boot/ Mockito BDD / BDDMockito / Behaviour driven development: http://site.mockito.org/mockito/docs/current/org/mockito/BDDMockito.html
Views: 9804 Philip Starritt
Java Clean Code Tutorial #2 - Static Analysis FindBugs Eclipse Plugin Setup
 
05:09
Episode 2 of the free Java Clean Code Training Series. In this tutorial I show you how to download and install the static analysis tool FindBugs and run it against your Java Programs in Eclipse or Spring Tool Suite. Findbugs looks for and identifies bugs in Java Programs. It is based on the concept of bug patterns. A bug pattern is a code idiom that is often an error. Findbugs will search for over 200 bug patterns in your code. Bug patterns arise for a variety of reasons: - Difficult language features - Misunderstood API methods - Misunderstood invariants when code is modified during maintenance - Garden variety mistakes: typos, use of the wrong boolean operator, dead code etc FindBugs uses static analysis to inspect Java bytecode for occurrences of bug patterns. Static analysis means that FindBugs can find bugs by simply inspecting a program's code: executing the program is not necessary. This makes FindBugs very easy to use: in general, you should be able to use it to look for bugs in your code within a few minutes of downloading it. Running findbugs will certainly help you write cleaner code by helping to identify bugs, typos, dead code or simple generic coding mistakes. I treat static analysis tools as first class citizens and always execute on my code, regardless if its fun home code or serious production code. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. See you in episode 3, Philip http://findbugs.sourceforge.net/factSheet.html
Views: 5978 Philip Starritt
Project Lombok Data Example (Part 5)
 
01:54
In this tutorial I show you how to use Project Lombok @Data annotation in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide: https://projectlombok.org/setup/eclipse Java Project Lombok: https://projectlombok.org/ Eclipse IDE Download: http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all Project Lombok EqualsAndHashCode annotation Example https://projectlombok.org/features/Data
Views: 1344 Philip Starritt
Project Lombok Java Logging Example (Part 10)
 
02:31
In this tutorial I show you how to use Project Lombok various logging @Log annotations in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide: https://projectlombok.org/setup/eclipse Java Project Lombok: https://projectlombok.org/ Eclipse IDE Download: http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all Project Lombok Log annotations Example https://projectlombok.org/features/log @CommonsLog Creates private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(LogExample.class); @JBossLog Creates private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(LogExample.class); @Log Creates private static final java.util.logging.Logger log = java.util.logging.Logger.getLogger(LogExample.class.getName()); @Log4j Creates private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(LogExample.class); @Log4j2 Creates private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager.getLogger(LogExample.class); @Slf4j Creates private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogExample.class); @XSlf4j Creates private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);
Views: 2147 Philip Starritt
Java Clean Code Tutorial #6 - Exception Handling - Prefer Runtime Exceptions
 
05:19
Exception handling is a critical part of software and java developers often are unaware of the choice of base exceptions, RuntimeException and Exception. It is NOT bad practise to use extend RuntimeException, just have a look at SpringFramework or most open source projects. Everything has its place. When your method throws checked exceptions, you force the client to handle the exception even when they don’t know how to. This can result in human error bugs such as: LOG/SWALLOW – Resulting in Errors / unpredictable behaviour. LOG/SWALLOW/THROW New Exception without a cause – Resulting in lost ‘cause’ stack traces which are hard to find in logs. Especially if they have a different correlation ID. LOG/Throw new exception. Resulting in lost ‘cause’. This cause can never be found as it was never logged, this makes it extremely hard for developers to reason on what actually caused the failure. If you do not perform a try/catch then you need to couple the client API methods with the exception that was thrown from the method. Just think if you need to propagate it 3 layers up the stack? This can get messy! I believe that developers should utilise and extend RuntimeException to allow flexibility in their API and also reduce clutter. With RuntimeExceptions you now have the ability to catch your exception where you can handle it and not couple the stack with ‘throws X declarations or try/catch/rethrow’. When dealing with RuntimeExceptions I also recommend a ‘catch all’ at the base of the application to stop any exceptions propagating to the client/UI or out of the JVM. This is also good security practise as some exceptions may leak sensitive data. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 7, Philip Episode 6 of the free Java Clean Code Training Series.
Views: 4589 Philip Starritt
OutOfMemoryError Java Heap Space Fix - Heap Dump Analysis VisualVM Tutorial
 
04:51
In this tutorial I show you how and why a java.lang.OutOfMemoryError can occur when running a Java application. I also show you how to configure your application to perform a Java Heap Dump if an out of memory errors. Additionally; I perform heap dump analysis by importing it into a Java profiling tool such as VisualVM. This will help find the root cause. First I set the Java Heap size to 64m by changing the –Xms and –Xmx virtual machine arguments. What does –Xms stand for? This java virtual machine argument allows you to specify the initial size (bytes) of the java heap. What does –Xmx stand for? This java virtual machine argument allows you to specify the maximum size, in bytes, of the memory allocation pool. We set the java heap memory to such a small size that it can’t handle and save the amount of java objects being created. Once there is not enough memory left to allocate objects, the application will fail with an out of memory error. I then configure the application to perform a Heap Dump on java.lang.OutOfMemoryError by specifying the flag: XX:+HeapDumpOnOutOfMemoryError This heap dump will be present in your applications working directory. If you would like to change the output path of the heap dump you can specify it by passing the: -XX:HeapDumpPath I then proceed to execute the java application which has an infinite loop that will create and place objects on an Array list. The application eventually fell over and threw an OutOfMemoryError when we allocated a Brick Object and tried to place it in the list. The list was at its maximum capacity and tried to resize. An arraylist is backed by an array, which has a finite number of elements. Each time the list’s backing array has reached maximum capacity it defines a new array typically double the size and copies the old array’s contents over into the new array. Then the GC clears the old array. Unfortunately there was not enough room for the new backing array in the Java Heap which caused the application to crash. When the java failure occurred it left the java heap with file name pattern java_pid{process-id}.hprof, this file can then be imported into VisualVM Java profiler for analysis of the applications state when the out of memory error occurred. After importing the hprof file into VisualVM profiler we can analyse the java thread’s status and the memory allocation. We can see the last stack trace before the failure and the huge amount of Brick allocations. If your application ever crashes, it’s good to inspect the heap dump to find out what was going on. This will hopefully identify causes and will prevent future failures if you can put a fix in. If you work with a cloud based ephemeral file system, then you might not be able to create / access a heap dump, as the application’s file system is scrapped and a new application is started on failure. There are ways to work around this such as attaching a hard drive to the instance. It depends on the nature of the system. I hope you enjoyed the tutorial! Don’t forget to subscribe for more great tech videos! Thanks, Philip Eclipse VisualVM Launcher Integration Set-up Guide https://www.youtube.com/watch?v=W60wvJ885iE&t Java Heap Dump Analysis – VisualVM Tutorial https://www.youtube.com/watch?v=Uubqc76h-jo VisualVM https://visualvm.github.io/ Eclipse Visual VM Integration https://visualvm.github.io/idesupport.html Java Profiling http://docs.oracle.com/javase/7/docs/technotes/guides/visualvm/profiler.html What are the -xms and -xmx parameters when starting JVMs? https://stackoverflow.com/questions/14763079/what-are-the-xms-and-xmx-parameters-when-starting-jvms
Views: 5528 Philip Starritt
Project Lombok Java NonNull Example (Part 9)
 
01:47
In this tutorial I show you how to use Project Lombok @NonNull annotation in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide: https://projectlombok.org/setup/eclipse Java Project Lombok: https://projectlombok.org/ Eclipse IDE Download: http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all Project Lombok NonNull annotation Example https://projectlombok.org/features/NonNull
Views: 1292 Philip Starritt
Java Clean Code Tutorial #10 – AVOID Static Methods
 
01:57
Java Static vs Non Static? When developing functionality, I always give my code and design extra thought before declaring a Java Static Method. Why? I feel that Static Methods are Ok and great for: - Utility classes that contain static methods that you would not need to mock out in tests. These can include functions that don’t do any networking & only use their parameters to compute the return value. E.g. Apache Commons StringUtils. - For use as a static factory method instead of a public constructor. These are great for using a descriptive name to construct classes. This can improve code readability. Static methods are easy to test themselves. The real challenge arises when another class & method calls that static method and that static method performs functionality that you would typically need to mock out in an automated test. Such functionality can include Networking, IO, Calling external services etc. Mocking out that static method can cause a good a headache as you would need to use frameworks or utilities to assist, e.g. PowerMock. This is unnecessary work and the code smell should be flagged by your initial unit tests. An alternative to calling static methods would be to remove static and use dependency injection to inject an instance of that class as a dependency. This would provide you with flexibility in your tests to easy replace the dependency with a mock or stub. This is easy with the likes of Spring Framework. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 11, Philip Recorded in the Mourne Mountains, Slieve Donard. Newcastle, County Down, Northern Ireland. A great post on static methods by Christian Posta http://blog.christianposta.com/testing/java-static-methods-can-be-a-code-smell/ Spring IO https://spring.io/ Spring Framework https://projects.spring.io/spring-framework/ Dependency Injection https://en.wikipedia.org/wiki/Dependency_injection
Views: 1562 Philip Starritt
Spring Boot JDBCTemplate Optimistic Locking Example with MySQL and Java Multithreading
 
18:36
I show you how to perform optimistic locking with Java, SpringBoot and MySQL. Pessimistic Locking VS Optimistic Locking JDBCTemplate Optimistic Locking NamedParameterJdbcTemplate Optimistic Locking DataSourceTransactionManager @Transactional annotation Java Transaction Propagation Levels Database connection Transaction Isolation Levels Concurrency Control Java SpringBoot SpringFramework RESTful Webservice Tomcat HTTP Request Thread breakpoint analysis HTTP concurrency example properties file MySQL Datasource JDBCTemplate autoconfiguration Subscribe for more great tech content! Enjoy! Philip Video Location: Slieve League Cliffs - Ireland, Co Donegal. https://en.wikipedia.org/wiki/Slieve_League Microsoft Concurrency Effects: https://technet.microsoft.com/en-us/library/ms190805(v=sql.105).aspx Optimistic concurrency control: https://en.wikipedia.org/wiki/Optimistic_concurrency_control Transaction Isolation Levels: https://en.wikipedia.org/wiki/Isolation_(database_systems) Spring Framework JDBC: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html JdbcTemplate: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html Spring Transaction Management: http://docs.spring.io/autorepo/docs/spring/current/spring-framework-reference/html/transaction.html Spring Boot Working with SQL Databases: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html Spring Boot Configure a Datasource: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html
Views: 3150 Philip Starritt
Project Lombok Getter and Setter Example (Part 2)
 
02:51
In this Java tutorial I show you how to use Project Lombok'S Getter and Setter annotation in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide https://projectlombok.org/setup/eclipse Java Project Lombok https://projectlombok.org/ Eclipse IDE Download http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all
Views: 3718 Philip Starritt
Java Clean Code Tutorial #4 - Avoid Boolean Parameters (Flag Arguments)
 
06:38
Episode 4 of the free Java Clean Code Training Series. Why should developers avoid Boolean method parameters? (Also known as Flag Arguments) When you use Boolean parameter you are openly saying that the method does more than one thing. Good methods should only perform one thing, and perform it well. It is also unclear from the API what the Boolean flag represents and the majority of the time developers will need to open up the java class to inspect its behaviour and meaning. Boolean flags make the methods intention unclear to the developer. How to mediate the problem? a) Split the method with the Boolean parameter into two methods and give them descriptive names. This will make the code easier to read and work with. b) If you cannot split the method due to existing complexity and technical debt, then you should create the two new methods and call the existing method with the hardcoded Boolean parameter. c) Refactoring the method into smaller methods is also a third option. Ultimately this simple design pattern Increases the use-ability, maintainability and readability of code when calling methods. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 5, Philip
Views: 3777 Philip Starritt
Secure Development #3 - OWASP Dependency Check Maven
 
06:47
I explain and show you how to scan your external dependencies for known exploits and vulnerabilities using OWASP dependency checker. The majority of software applications include a large number of external dependencies, it is critical that these dependencies are scanned for known exploits and vulnerabilities. OWASP Dependency Checker provides us with exactly this functionality, the maven plugin (many other scanning options available, gradle, command line etc) will scan all the dependencies in your application and flag up any that have active vulnerabilities. This functionality can easily be executed as a Java maven task/goal during your continuous integration pipeline. This task will highlight any issues with your Java JAR files that you can then analyse and make an informed decision promptly. I.e. Update the Jar file? Exclude the dependency? Fix it? Big shout-out to Open Web Application Security Project OWASP and Jeremy Long for this great tool. Don’t forget to subscribe if you enjoyed the content! Cheers! Philip OWASP https://www.owasp.org/index.php/Main_Page OWASP Dependency Check https://www.owasp.org/index.php/OWASP_Dependency_Check OWASP Dependency Check Maven Plugin Example http://search.maven.org/#artifactdetails%7Corg.owasp%7Cdependency-check-maven%7C1.4.5%7Cmaven-plugin OWASP Dependency Check Maven Plugin Usage http://jeremylong.github.io/DependencyCheck/dependency-check-maven/ OWASP Dependency Check GitHub https://github.com/jeremylong/DependencyCheck National Vulnerability Database https://nvd.nist.gov/ OWASP Dependency Check Intro https://www.youtube.com/watch?v=5hFf5uGQ-bA How to use OWASP dependency check?
Views: 1402 Philip Starritt
Docker PostgreSQL Tutorial - Running In 3 Minutes Quick Start
 
07:55
I show you how to quickly create a Docker PostgreSQL local database instance. Additionally, perform a database migration and execute your SQL scripts on the postgreSQL service start up. In order to perform a database migration to create your schema, tables, objects and SQL statements we will extend the image by placing the local .sql files into the containers directory: /docker-entrypoint-initdb.d This can be done by using mapping a docker volume from the host directory to the container directory above. We map our host port 5432 to the containers port 5432 so other applications running on the host can access the postgreSQL instance. (such as dbvisualizer, java applications, other systems etc) Control C will gracefully terminate the container instance, but the image will still live on your machine until you remote it. All of the above is execute with docker compose UP command. Don’t forget to subscribe! Next video on Jooq persistance framework! Philip Docker Postgres Official Repository: https://hub.docker.com/_/postgres/ Docker-compose UP https://docs.docker.com/compose/reference/up/ Ubuntu https://www.ubuntu.com/ Dock Compose Tutorial https://docs.docker.com/compose/
Views: 9021 Philip Starritt
Spring Boot Consume RESTful Web Service with RESTTemplateBuilder
 
17:45
How to easily consume a RESTful API Web Service with Java, Spring Boot and the new RestTemplateBuilder. I start off by creating a RESTful web service with Spring’s RestTemplateBuilder. With Spring Boot 1.4.0+, this class will be automatically instantiated and will be available for dependency injection. With this builder, we can set the REST client’s basic authentication, connect timeout, read timeout, http request factory, converters, error handlers and many more settings. This is a great convenience as we no longer need to manually do it ourselves. We then create a class to hold our Rest Client Properties, this bean is annotated with Spring’s @ConfigurationProperties with a prefix specified. As we have spring-boot-configuration-processor on the classpath, we now have intellisense and code completion in our property files and are now type safe when defining properties. No more mistakes! These properties are then used to set the values inside the RestTemplateBuilder. We aim to externalise all configuration, especially if it can change per environment. I then go ahead and use the Spring CommandLineRunner to execute the run method and call the REST service. The rest template will use the default Simple Spring HTTP Request factory as we do not have any of the predefined REQUEST_FACTORY_CANDIDATES on our classpath. I then add Http Components HttpClient and show that the request factory is now the springframework httpComponentsClientHttpRequestFactory. I hope you enjoyed this tutorial and start using RestTemplateBuilder :) Don’t forget to subscribe for more great videos! Till next time! Philip Spring RestTemplate: http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html Spring RestTemplateBuilder: http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/client/RestTemplateBuilder.html Spring CommandLineRunner: http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/CommandLineRunner.html Spring Boot: https://projects.spring.io/spring-boot/ Spring Boot Externalized Configuration: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html Spring Boot Configuration Properties: http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/context/properties/ConfigurationProperties.html spring-boot-configuration-processor http://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html
Views: 5956 Philip Starritt
Idempotency - The Importance of Integration Idempotence with Microservices & APIs
 
13:51
Step by step Idempotency tutorial highlighting why your Enterprise Integrations should be Idempotent consumers. The term idempotent is used in mathematics to describe a function that produces the same result if it is applied to itself. f(x) = f(f(x)) What is Idempotency in relation to messaging? A consumed message will have the same effect on the system if it is received once or X times. Why do we need to be idempotent? Consuming applications may receive the same message more than once. This may place the system / data in an invalid or stale state; a situation we need to prevent. Popular publishing design pattern. Publisher bug. etc. Design your consumer so it can safely consume the same message multiple times. I.e. Idempotent Consumer. If you enjoyed the video, please share, comment & subscribe for more great content! Enjoy! Philip Tech Links: Enterprise Integration Patterns: http://www.enterpriseintegrationpatterns.com Idempotent Receiver: http://www.enterpriseintegrationpatterns.com/patterns/messaging/IdempotentReceiver.html Apache Camel Framework - Java Enterprise Integration Patterns: http://camel.apache.org/enterprise-integration-patterns.html Apache Camel Idempotent Consumer: http://camel.apache.org/idempotent-consumer.html Microsoft Concurrency Problems: https://technet.microsoft.com/en-us/library/aa213029(v=sql.80).aspx Idempotent Consumer, REST API, Microservices, Duplicate Messages, Filter, Apache Camel, Enterprise Integration Patterns, Transactions, Compensating Transactions, Saga Failure, Legacy System Integration.
Views: 3626 Philip Starritt
Canonical Data Model Example – Enterprise Integration Patterns
 
11:01
Many organizations have multiple Software Applications that are based on different data models & formats. When these systems need to integrate, how can we minimize dependencies and coupling between domain models? One solution is to design and implement a Canonical Data Model. The model should be independent and not reflect any individual application. Each Integrating application should only know how to convert their domain model into the canonical model and vice versa. Applications are no longer exposed and coupled to each other’s domain objects and terminology. Designing a canonical model can enclose different levels of complexity and challenges. E.g. A small company vs an existing large organisation’s eco-system may be very different. - Size of existing data models? - People need to understand the existing data models, systems and business process. - Good tooling required for schemas. - Good software developers up for the challenge. - How to avoid translation & code spaghetti? - Manage canonical model versioning. Don’t break existing consumers with old versioning. - Publishers implement Consumer Driven Contract Tests. - Benefit Cost Ratio? Is it worth the investment? - Is it a good idea? Do we want and need it? Let’s be pragmatic. - Analyse lessons learned from existing adoptions & attempts. If you enjoyed the video, don’t forget to subscribe for regular software tech videos! :) Enjoy! Philip Spring Boot JMS Tutorial - JAXB JmsTemplate JmsListener with ActiveMQ: https://www.youtube.com/watch?v=3GNiepg3704 Generate JAXB Java classes from XSD with maven-jaxb2-plugin AND Spring OXM JAXB Example: https://www.youtube.com/watch?v=0D-P2LzLJYQ Enterprise Integration Pattern Canonical Data Model: http://www.enterpriseintegrationpatterns.com/patterns/messaging/CanonicalDataModel.html Enterprise Integration Patterns: http://www.enterpriseintegrationpatterns.com/ Consumer Driven Contract testing: https://www.thoughtworks.com/radar/techniques/consumer-driven-contract-testing Consumer Driven Contracts: http://martinfowler.com/articles/consumerDrivenContracts.html
Views: 2346 Philip Starritt
Create & Deploy Spring Boot WAR to Apache Tomcat 8
 
06:41
In this tutorial I show you how to convert a Spring Boot JAR application into a traditional WAR file. I then proceed to deploy the WAR into Tomcat 8 servlet container. 00:00 - 00:49 Introduction, Spring Boot JAR & WARs 00:49 - 01:45 Spring Initializr to create Spring Boot WAR file 01:45 - 01:55 Steps to convert WAR file 01:55 - 02:12 Spring Boot Main Class 02:12 - 02:51 Override SpringBootServletInitializer configure method, add SpringBoot main class 02:51 - 03:13 Maven POM, Spring Boot Parent & Packaging Tag 03:13 - 03:48 Mark POM spring-boot-starter-tomcat dependency as maven provided scope 03:48 - 04:04 Create RESTful service for demo 04:04 - 04:55 Run WAR file on Tomcat 8 servlet container 04:55 - 05:10 Convert WAR into Spring Boot JAR 05:10 - 05:15 Remove provided scope for tomcat dependency 05:15 - 05:20 Set POM packaging as Jar 05:20 - 05:30 Delete ServletInitializer java class 05:30 - 05:50 Run main method as Spring Boot App 05:50 - 06:20 Common error, change in URL when converting from WAR to Jar 06:20 - 06:30 Resources and support for older servlet containers 06:30 - 06:40 Thank you for watching I don't really recommend WAR and would rather prefer an executable JAR with an embedded server. I find the later reduces development time, especially when creating prototypes and minimum viable products. Make JAR, not WAR. If you enjoyed the content, Subscribe for more great technology / software videos! Enjoy! Philip Spring Boot Traditional Deployment: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html Understanding WAR Files: https://spring.io/understanding/WAR Spring Initializr: https://start.spring.io/ Advice deploying war files vs executable jar with embedded container: http://stackoverflow.com/questions/23478013/advice-deploying-war-files-vs-executable-jar-with-embedded-container
Views: 7688 Philip Starritt
AJAX Tutorial HD - JSP call to Java Servlet using jQuery & JSON response
 
20:51
AJAX tutorial on how to call a Java Servlet from JSP using Javascript / jQuery. I advise that you use a robust framework like Spring REST, SpringBoot, JAX-RS etc instead of the raw servlet example. JSON response access example. Google Gson Java Example. Sorry about the mic! Don't forget to check out all my new 2016 Java, Spring Boot and Camel Videos. They are recorded with a professional microphone ! 🙂 Don't forget to Subscribe for more great tech videos Philip
Views: 71411 Philip Starritt
Java Servlets and JSP Tutorial For Beginners
 
06:01
It’s 2018, yet Java Servlets and JSPs are still a must know for Java developers. Let me explain why having an understanding this core library and framework can benefit you, and why I decided to read Murach’s Java Servlets and JSP. Many of today’s modern Java web frameworks are built on-top of the core Java Servlets API. Having a good understanding of the under lying technology gives you a great advantage knowing what is actually going on behind the scenes and ensuring you use the high level technology as required. This can help bring out optimisations and provide insight into why to use a framework, not to mention the ability to read its source code to see whats actually going on. Also, tens of thousands of existing production applications are built using standard Java Servlets API, and many of these applications have legacy Java contractors supporting them. Having the ability to get productive fast by understanding the technology can be a great advantage if you want such a career. Many modern developers don’t want to learn older technologies, so having the ability to work on all platforms provides you with a great advantage for employment. Subscribe for more tech videos like this! Till next time, Philip Links Java Servlets: https://en.wikipedia.org/wiki/Java_servlet . Java Server Pages https://en.wikipedia.org/wiki/JavaServer_Pages
Views: 939 Philip Starritt
Twitter API Java Tutorial - Spring Social Twitter Example
 
11:49
In this Twitter API Tutorial, I show you how to easily integrate with the Twitter API using Spring Social Twitter & Spring Boot auto-configuration. 00:00 – 00:40 Twitter API Tutorial Introduction. 00:40 – 02:00 Create a Spring Boot application with Spring Social Twitter & Web maven dependencies. Created project using new spring starter project, spring STS initializr. 02:00 – 03:45 Analyse Spring Boot & Spring Social Twitter auto-configuration. How Spring Boot will automatically create a TwitterTemplate with request scope. 03:45 – 05:15 Navigate to dev.twitter.com and create a new app. Read and agree to twitter terms and conditions. 05:15 – 05:55 Obtain Twitter Consumer Key (API Key) and Consumer Secret (API Secret). The secret should be encrypted at REST and not be in plaintext properties files! Store key and secret in your application’s properties files, this will let spring boot know it needs to configure a twittertemplate. 05:55 – 06:20 Analyse TwitterTemplate invoking Spring’s OAuth2Template with the consumer key and consumer secret. 06:20 – 09:35 Create RESTful service that will act as an API gateway / Proxy to Twitter API service calls. Use TwitterTemplate searchOperations to retrieve the latest 20 tweets with the specified hashtag. 09:35 – 10:30 Run application and search for #manutd on twitter. Return results in HTTP response from our RESTful web service. 10:30 – 11:30 Use TwitterTemplate timelineOperations getUserTimeline to search for a twitter timeline. 10:30 – 11:48 Summary of tutorial. Don't forget to subscribe for regular tech & software videos! Enjoy, Philip Spring Social Twitter: http://projects.spring.io/spring-social-twitter/ Spring Social: http://projects.spring.io/spring-social/ Twitter: https://twitter.com/ Twitter Dev: https://dev.twitter.com/ Twitter REST APIs: https://dev.twitter.com/rest/public
Views: 10636 Philip Starritt
Java Clean Code Tutorial #5 - Comparing String Constants
 
02:17
Java String constant comparison is one of the most popular and heavily used java statements. I feel it’s very important that all developers are aware of this one simple tip when performing comparisons to avoid unexpected Null Pointer Exceptions. In order to avoid null pointer exceptions, always place the constant first during the comparison. For example, the graceful validation below will not throw a null pointer is the variable is null. The risk prone code will throw a null pointer exception if the variable is null. Graceful validation - CONSTANT.equals(variable) Risk Prone - variable.equals(CONSTANT) I feel it is important developers know about this idiom and when to apply it. It can drastically improves codebases with such small changes, unless you want the code to blow up! But usually i don't. Share this quick tip with your team & fiends. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 6, Philip Episode 5 of the free Java Clean Code Training Series.
Views: 1644 Philip Starritt
Spring Boot Cache Example with Caffeine
 
25:00
In this Spring Boot Cache tutorial I show you how to setup and Cache methods, Expire data and expose the cache actuator metrics endpoint. In this example I use Caffeine Cache, a high performance java caching library. I cover the following topics in the video: Spring Cache Annotations @Cacheable and @CacheEvict Setting up your Cache Manager Caffeine High Performance Caching Library By Ben Manes Spring Boot’s Cache Auto Configuration Spring Boot Actuator Cache Metrics Endpoint Spring Stopwatch tutorial for timing method execution to the milliseconds precision Don’t forget to subscribe if you enjoyed the video! Cheers! Philip My Free Java Clean Code Course https://www.youtube.com/playlist?list=PLiwhu8iLxKwL-VOcGAPzaflFIRFXwUxDD My Free Cyber Security Course https://www.youtube.com/playlist?list=PLiwhu8iLxKwIHBkXp5eY9k-0OWBz5gK7R The video was recorded in Tenerife, Mourne Mountains and a local lake with a swan & duck. https://en.wikipedia.org/wiki/Tenerife https://en.wikipedia.org/wiki/Mourne_Mountains https://en.wikipedia.org/wiki/Swan Tech Links Spring Boot Caching https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html Spring Caching Abstraction Layer https://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html Ben Manes Caffeine Cache, A high performance caching library for Java 8 https://github.com/ben-manes/caffeine Spring Boot Actuator, Metrics Endpoint, Cache Metrics https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html
Views: 3646 Philip Starritt
Java Clean Code Tutorial #7 - Exception Handling - Throw Exceptions Instead of returning Error Lists
 
04:10
Validation is present in virtually all java applications. I feel that using an error flag / error list should be avoided and replaced with an exception being thrown up the stack when an illegal validation is identified. When you use error flags or error lists, you introduce the scope to introduce bugs regarding the current return status of the validation. This can also clutter your code with validation logic outside the ‘validate’ object. If you use a validation object with an error list, try to avoid using a list as an output argument. I.e. The method will change the state of an list parameter passed in. Rather return a Immutable List/Set of validation errors. When you throw exceptions this is not possible as it will be propagated up the stack and dealt with in your try/catch block. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 8, Philip Episode 7 of the free Java Clean Code Training Series.
Views: 2404 Philip Starritt
Junit Categories Example | Maven SureFire Plugin Configuration
 
08:02
In this Java Junit tutorial, I show you how you can use JUnit Categories to classify your tests into slow, medium and fast tests. This can beneficial when you want to execute a certain subset of your tests in a certain order. For example, you might want to run all the tests that take a short time to execute first, then the medium followed by the long running tests. This can provide you with quicker build / test feedback cycles in your continuous integration / delivery build tool such as Bamboo / Jenkins. I typically classify quick tests as simple junit tests with no frameworks. Medium tests would be if a framework was required with some level of processing and large tests for long running tests such as integration tests. In the tutorial I use the maven’s maven-surefire-plugin to execute certain groups. These groups are specified by the maven profile SlowTests, MediumTests or FastTests – added by the profile xml elements. Each profile adds the groups property that points to an package & interface. The junit methods or classes annotated by @Category(pagkage.interface) will then be executed as part of that cycle. Maven Surefire Plugin also supports running tests in parallel from junit 4.7 onwards. I hope you enjoyed the tutorial, if you did – don’t forget to subscribe :) Until next time, Philip Links: Maven Surefire Plugin http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html Java Junit 4 http://junit.org/junit4/ Spring https://spring.io/ org.junit.experimental.categories. Category http://junit.org/junit4/javadoc/4.12/org/junit/experimental/categories/Category.html
Views: 1794 Philip Starritt
Spring Boot JMS Tutorial - JmsTemplate JmsListener  with ActiveMQ Example & JAXB
 
21:18
In this Java Spring JMS Example I show you how to use Spring Boot JMS Autoconfiguration in order to create a JMS producer and JMS consumer. We first create a JMS publisher application by injecting the Spring Boot JmsTemplate autoconfiguration with a MarshallingMessageConverter and ActiveMQ connection factory (also autoconfigured). The MarshallingMessageConverter contains a Jaxb2Marshaller with its context path, schema and pretty print values set. The context path is equal to the package that contains the JAXB generated objects. I then create a JMS consumer application by configuring a MarshallingMessageConverter backed by a Jaxb2Marshaller. The ActiveMQ connection factory will also be autoconfigured in the consumer. Once these are configured, Spring Boot will automatically create a JmsListenerContainerFactory and associate our defined beans (Above). We can then use the @JmsListener annotation to read of a target message queue. See spring documentation 13.1.6 for more information. The publisher will automatically convert & marshall the JAXB object into XML before sending it to the ActiveMQ message queue. The consumer will additionally automatically unmarshal the XML into the JAXB object. 0:00 – 01:15 Tutorial overview 00:15 – 01:42 Create maven dependency for shared JAXB Objects. 01:42 – 02:55 Maven JAXB plugin – Generate JAXB objects from XSD 02:55 – 03:45 Create Jms Publisher Spring Starter Project 03:45 – 04:40 Analyse Spring Boot JmsAutoConfiguration JmsTemplate 04:40 – 06:30 Set Spring Boot ActiveMQ autoconfiguration & application properties 06:30 – 10:00 Configure MarshallingMessageConverter and Jaxb2Marshaller. Set the context path, enable schema validation and XML pretty print 10:00 – 12:35 Send Message to ActiveMQ queue via JmsTemplate. Start ActiveMQ Message Broker via Windows Command Prompt 12:35 – 14:30 Debug and analyse objects to show spring boot autowiring 14:40 – 15:40 Create Jms Consumer Spring Starter Project & configure maven dependencies 15:40 – 16:36 Configure Jms consumer MarshallingMessageConverter and Jaxb2Marshaller. Set the context path, enable schema validation and XML pretty print 16:36 – 16:45 Remove AMQP dependency from Publisher (brought in my accident) 16:55 – 17:15 Add @EnableJms to the spring configuration 17:15 – 18:50 Add @JmsListener annotation to read and process messages of the ActiveMQ 18:50 – 19:40 Turn on JMS consumer and consume XML message. Automatically convert XML into JAXB object. 19:40 – 20:10 Turn on publisher and send another message to consumer 20:10 – 20:17 Tutorial summary If you enjoyed the tutorial please subscribe for regular Software Tutorials! :) Enjoy! Philip Spring Framework JMS Example Apache Camel Alternative Tutorial: https://www.youtube.com/watch?v=B-Q_InvRvn0 Jaxb2Marshaller Tutorial: https://www.youtube.com/watch?v=0D-P2LzLJYQ Spring Boot Messaging Features: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-messaging.html Spring Framework JMS Integration: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jms.html JmsTemplate: http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jms/core/JmsTemplate.html ActiveMQ: http://activemq.apache.org/ ActiveMQ Spring Support: http://activemq.apache.org/spring-support.html Spring JMS ActiveMQ Example
Views: 11175 Philip Starritt
Java Clean Code Tutorial #8 - How long should a method be??
 
01:25
A very common question when writing software is, how long should a method be? My initial response to this question is the single responsibility principle, a method should do one thing and do one thing very well. That being said, I feel effort and care should be taken to try and keep methods to around 20 lines maximum. This is just my opinion and not a stone rule! Where did i get this magic number? I found this was a sweet spot from my own personal experience and while working with many programmers at all levels. In general, we felt that methods that had over 20 lines of code had the potential to be broken down and certain logic extracted into other methods with cool descriptive names. Effectively making the code more like poetry. Whats your opinion? Please share in the comments for other developers searching for this question! Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 9! Philip Various other good opinions on StackOverFlow http://softwareengineering.stackexchange.com/questions/133404/what-is-the-ideal-length-of-a-method-for-you
Views: 950 Philip Starritt
Java Design Patterns Essentials - GoF Review
 
07:24
Being aware of the Gang of Four Java design patterns will significantly improve your coding skills and ability to quickly understand codebases and get productive. How?? Many different domains and software applications solve their problems and business logic with the same design patterns. Understanding these patterns is a great skill that significantly enables you to jump between code bases, software companies and simply makes you more employable. Yes, modern architectures such as serverless promote smaller codebases and artifacts, but this does not remove the last 20 years of production applications. These applications still need updated, upgraded, retired etc – and in order to do so a solid understanding of the gang of four can be great ammunition. It also doesn’t mean that a small codebase can’t use a proven and neat pattern to solve a problem, but only use it if it fits!! Review of Java Design Pattern Essentials Second Edition Tony Bevis. Don’t forget to subscribe! Cheers, Philip Gang of Four Design Patterns https://en.wikipedia.org/wiki/Design_Patterns
Views: 660 Philip Starritt
SpringBoot RetryTemplate Example  | Java Web Service Retry Design
 
12:35
Step by step guide how you can easily implement an automated Retry and Back-off policy within your Spring Java application. Enable your application to handle temporary failures when attempting to connect to a service or network resource. This can be done by enabling an automated retry policy that will perform the same operation that previously failed. The retry policy should have a maximum number of retries and either a dynamic back-off or incremental delay period. I recommend each service that you retry is idempotent. By designing for failure, you improve the stability of the application. If you enjoyed the video, please share, comment & subscribe for more great content! RetryTemplate: http://docs.spring.io/spring-batch/reference/html/retry.html Spring Retry Github: https://github.com/spring-projects/spring-retry Retry Design Pattern: https://msdn.microsoft.com/en-gb/library/dn589788.aspx Enjoy! Philip
Views: 1993 Philip Starritt
Martin Thompson gives IMPORTANT Software Engineering Advice
 
02:34
Martin Thompson, High-Performance & Low-Latency computing specialist gave very important and pragmatic Software Engineering advice during the Belfast BASH conference. I created a video on this comment, as I believe this simple technique is often overlooked and ignored by some engineers. "You will see things you did not see!" Read back core flows in your system and you will spot many improvements :) Martin's Talk: Engineering You! Martin Thompson talks about the characteristics of a good software engineer and explores the individual practices and techniques that can help bring out the engineer in everybody. Subscribe for more great tech content! Enjoy! Philip About Martin: Martin is a consultant, trainer, and coach specializing in designing high-performance and low-latency systems. In the performance space, he has changed expectations about what is possible with Java by showing that Java can compete with and even outperform native applications. His passions include concurrent programming (the Disruptor being one of his creations) and teaching people how to write algorithms that best utilize modern hardware. Martin's Blog Mechanical Sympathy: http://mechanical-sympathy.blogspot.co.uk/ InfoQ: https://www.infoq.com/author/Martin-Thompson Twitter: https://twitter.com/mjpt777 Full Engineering You Video: https://www.infoq.com/presentations/engineer-practices-techniques Belfast BASH: https://twitter.com/devbash INSTIL Software (guys who run bash): https://twitter.com/instil
Views: 277 Philip Starritt
Project Lombok Immutable Value Example (Part 6)
 
01:17
In this tutorial I show you how to use Project Lombok immutable @Value annotation in Eclipse IDE. What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links: Eclipse, Spring Tool Suite setup guide: https://projectlombok.org/setup/eclipse Java Project Lombok: https://projectlombok.org/ Eclipse IDE Download: http://www.eclipse.org/ Project Lombok Features https://projectlombok.org/features/all Project Lombok EqualsAndHashCode annotation Example https://projectlombok.org/features/Value
Views: 1016 Philip Starritt
Generate JAXB Java classes from XSD with maven-jaxb2-plugin AND Spring OXM JAXB Example
 
15:53
Generating Java JAXB classes from an XSD schema is a common task. In this tutorial I show you how to use the maven-jaxb2-plugin to generate the JAXB java classes. (From group org.jvnet.jaxb2.maven2). By the way - have you tried MOXy? I actually find it more maintainable than handing JAXB objects; but thats another video topic!. I additionally show you how to use Spring Framework OXM Jaxb2Marshaller to marshal JAXB java objects into XML and unmarshal XML into JAXB java objects. 00:00 - 01:23 Tutorial Introduction from a beach in Andalusia; Spain. During my morning walk. 01:23 - 01:46 Create Spring Starter Project 01:46 - 02:40 Created XML XSD Schema 02:40 - 03:50 Added maven-jaxb2-plugin to the applications POM 03:50 - 04:40 Generated the JAXB Java Objects representing the schema 04:40 - 04:52 Added Spring Framework OXM dependency to the POM 04:52 - 08:55 Created Spring Jaxb2Marshaller with context path, schema resource validation and pretty print property. 08:55 - 10:33 Created JAXB Java Objects to perform marshalling on 10:33 - 12:30 Marshalled JAXB Java Object into XML with Jaxb2Marshaller StreamResult and StringWriter. Could also use StringResult. 12:30 - 13:00 Fixed the exception thrown by adding the missing context path and schema properties. 13:00 - 14:45 Unmarshalled XML into JAXB java objects using Jaxb2Marshaller StreamSource and StringReader. 14:45 - 15:50 Maven & Spring JAXB Integration example summary I hope you learned something new and enjoyed the video; subscribe for more regular tech videos! Enjoy! :) Philip JAXB2 Maven Plugin: https://github.com/highsource/maven-jaxb2-plugin JAXB2 Maven Plugin Configuration Cheat Sheet: https://github.com/highsource/maven-jaxb2-plugin/wiki/Configuration-Cheat-Sheet Alexey Valikov Highsource: https://github.com/highsource Spring Framework Marshalling XML using O/X Mappers: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/oxm.html Jaxb2Marshaller: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/oxm/jaxb/Jaxb2Marshaller.html Spring Initializr: https://start.spring.io/ MOXy EclipseLink for the interested: https://wiki.eclipse.org/EclipseLink/Examples/MOXy
Views: 8211 Philip Starritt
Project Lombok Eclipse Plugin Installation Guide (Part 1)
 
03:57
In this tutorial I show you how to install Project Lombok in Eclipse and Spring Tool Suite (STS). What is project Lombok and why would I want it? “Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java.” What this essentially means, it will automatically generate common java boilerplate code (such as getters, setters, constructors, tostring etc) with a couple of annotations. This is done at compile time and weaved into your bytecode, this means project Lombok does not need be on the executables classpath during production. Don’t forget to subscribe for more great tech vids! Have a good one! Philip Links Eclipse, Spring Tool Suite setup guide https://projectlombok.org/setup/eclipse Java Project Lombok https://projectlombok.org/ Eclipse IDE Download http://www.eclipse.org/
Views: 7426 Philip Starritt
Java Clean Code Tutorial #9 - STOP Writing Code!!
 
01:50
I always feel its good practice for a developer to take some time to understand and familiarise themselves with some reputable common and heavily used libraries. These libraries most likely contain utility classes and methods that will make your life easier. For example, I like apache commons. There are hundreds of official open source java libraries that are available via build tools; maven, gradle etc. I also understand that sometimes one might not want to bring down a dependency just for a few lines of code. This is totally fine if you are restricted to certain vetted dependencies or are required to keep the final JAR to a the absolute minimum size. Before you write a utility method, just have a check if the function has already been written and contained in one of the shared libraries :) Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 10, Philip For example have a look at Apache Commons Lang3 https://commons.apache.org/proper/commons-lang/
Views: 1044 Philip Starritt
Java Daemon Thread vs User Thread Example
 
05:51
What is a Java Daemon Thread? A daemon thread is a type of java thread that does not prevent the JVM from exiting when the program finishes. The Java Virtual Machine exits only when all threads running are all daemon threads (I.e. No Java User Threads exist). The initial java main method is a user thread and a thread will automatically inherit the daemon status of its parent (Creator) thread. Any threads created from the main thread will also be user threads unless you specifically call the thread#setDaemon(true) method. For example: T1 is a daemon thread, when T1 creates and starts T2, T2 will also be a daemon thread. Also, worth mentioning When the JVM terminates, daemon threads: - Finally blocks are not executed - Stacks are not unwound – JVM exists. To make a daemon thread, the setDaemon(true) must be invoked BEFORE the thread is started. Garbage collector is an example of a daemon thread. I.e. As you are aware, the garbage collector thread will not prevent the JVM from exiting when all your user threads die. I hope you enjoyed this quick Java tip!! Sub & See you next time!! Philip https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html
Views: 875 Philip Starritt
Mock Java REST Web Service Tutorial with Spring Boot RestTemplate Test Example Client
 
19:38
In this tutorial i show you how to unit test Java REST web service HTTP requests via a mock Spring RestTemplate utilising Spring MockRestServiceServer. Tutorial on how to mock your Java REST Client with Spring. Creating automated unit tests for your RestTemplate requests will add value by asserting the HTTP requests contain all expected values (HTTP Headers, payload, etc). If you enjoyed the video, please share, comment & subscribe for more great content! Enjoy! Philip How to consume a RESTFul API with Spring RestTemplate: https://www.youtube.com/watch?v=DyNXkznUYaU Spring MockRestServiceServer: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/test/web/client/MockRestServiceServer.html Spring RestTemplate: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html Java Hamcrest: http://hamcrest.org/JavaHamcrest/
Views: 6676 Philip Starritt
Java Clean Code Tutorial #11 – DRY Principle - Don't Repeat Yourself
 
02:10
I believe DRY Don't Repeat Yourself is one of the most important fundamental design principles in software development. Why? It reduces duplication of code, duplicated code is hard to maintain and promotes WET - Don't do this! I.e. Waste everyone's time, we enjoy typing.. It promotes code reuse, need to make a change? Well if you reuse common functionality you will only need to make the change once. DRY can promote the single responsibility pattern by encouraging developers to extract common functionality into their own class or method. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 12, Philip Recorded in the Mourne Mountains, Slieve Donard. Newcastle, County Down, Northern Ireland. Spring IO https://spring.io/ Spring Framework https://projects.spring.io/spring-framework/ Don't Repeat Yourself https://en.wikipedia.org/wiki/Don%27t_repeat_yourself 3 Key Software Principles https://code.tutsplus.com/tutorials/3-key-software-principles-you-must-understand--net-25161
Views: 1171 Philip Starritt
Flyway Database Migration Tutorial - Java API
 
11:14
Let me explain and show you how to code Flyway for Database Migrations in Java. First, why do we need automated database migrations? This is pretty simple, database migrations will ensure developers know what the current schema’s state is in each environment. They just need to look at flyways history table and see the version, or look at the application version and what schema files are on the classpath. Migrations also provide other great benefits like Ensuring your persistence tests can be run against a database with the same schema. This can be done by spinning up a docker database instance, running flyway then running your junit tests against the database. Recreating a database from scratch. This can save a lot of time when spinning up a new environment. Don’t forget to subscribe for more tech videos like this, Cheers! Philip Links: Flyway https://flywaydb.org/ Why database migrations? https://flywaydb.org/getstarted/why How Flyway Works https://flywaydb.org/getstarted/how Flyway Github https://github.com/flyway/flyway
Views: 1313 Philip Starritt
Java Clean Code Tutorial #12 – Please Write Unit Tests, lets go FAST!
 
02:34
Having a unit test suite for your code is the secret to shipping software really fast. Why? Having a full unit test suite for each class and public method (not including getters / setters etc) enables developers to make changes to the codebase with high confidence that they have not broken existing functionality. Developers simply need to run the existing tests after they have made their changes to verify functionality still works. If something is broke, the unit test will identify exactly the class and method in the code. Unit tests help you better understand the design of your code. This stops sloppy code from being produced that just works, and will be a nightmare to maintain in the future. Having tests allows you to specify and test the conditions that are subject to that piece of code. Tests also should have descriptive names of what they are doing, this can help with visibility into what works and what is broken after a change. Unit tests play and fit in nicely to continuous delivery and continuous integration tools such as Bamboo and Jenkins. These can also give you visual feedback and provide metrics. Software is written once and read hundreds of times. So let’s make our fellow developers life easier. Why clean code? Simple. Clean code allows us to confidently make changes and deliver more features quickly to our customers. Don’t forget to subscribe for your regular dose of Java Tutorials! STOP THE ROT. Till episode 13, Philip Recorded in the Mourne Mountains, Slieve Donard. Newcastle, County Down, Northern Ireland. Test Driven Development https://en.wikipedia.org/wiki/Test-driven_development Unit testing https://en.wikipedia.org/wiki/Unit_testing Is Unit Testing worth the effort? http://stackoverflow.com/questions/67299/is-unit-testing-worth-the-effort Spring IO https://spring.io/ Spring Framework https://projects.spring.io/spring-framework/ Dependency Injection https://en.wikipedia.org/wiki/Dependency_injection
Views: 1120 Philip Starritt
Consume a RESTful Web Service in Java Spring Boot | REST API Client
 
19:37
How to easily consume a RESTful API Web Service with Java, Spring Boot & RestTemplate. NEW... must watch - My new tutorial on how to use the cool new Spring Boot 1.4 RESTTemplateBuilder to automatically create your RESTTemplate objects. https://youtu.be/MnhCW0uKDCU How to create a RESTFul java web service with spring boot. Create a REST API java client (RESTful web service client) using spring boot & RESTTemplate. Watch your Spring REST Client consume the JSON returned from the web service. If you enjoyed the video, please share, comment & subscribe for more great content! Enjoy! Philip Spring RestTemplate: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html How to test your RestTemplate with mock classes via MockRestServiceServer: https://www.youtube.com/watch?v=uZ-oEeOUMQc Spring Initializr: https://start.spring.io/ Spring Framework: https://projects.spring.io/spring-framework/ Spring IO: https://spring.io/ SpringBoot, Spring, RestTemplate, RestController, JSON, Maven, Java8, Tomcat.
Views: 53737 Philip Starritt

Which will writing service review
Program specialist cover letter examples
Writing community service
Business writing service
Personal loan application cover letter