Posts

Showing posts with the label jvm

Java Agents

Image
 Java Agents are an interesting capability of the JVM. Agents can either be Static(Load when the java app starts with a special flag) or they can be Dynamic(using the dynamic API from java we can dynamically bind to a specific JVM PID. Agents can be used to run any code before the app starts or even to change the bytecode. The cool thing about agents is the fact that is a runtime thing and we do not need to change the source code of the target app. Agents are similar to Aspects but IMHO much better. Mockito uses mocks in order to test difficult scenarios, pretty much all observability solutions for logs and metrics also have agents. Today I want to share 2 pocs, one using a vanilla java app and doing bytecode manipulation, The second using Spring Boot 2.x and running code forever in a background thread as the app also runs. So Let's get started!

Fat Jar with Scala 2.13 and Sbt 1.5

Image
Fat Jar is a very useful technique. Having one jar and one jar only makes the distribution of software much easier and also mantaince much more sense as you need to roll out bug fixes and changes. Scala allows us to create self-package, self-executing one single fat jat by using the Assembly plugin. Today I want to share a simple POC and video I made showing how we can create a Fat Jar using Scala, Assembly, and Sbt. The code will be using a java dependency, a project called Apache Commons Lang .  So let's get started! The Video The Code https://github.com/diegopacheco/scala-playground/tree/master/fatjar-assembly-sbt-1.5.0 Cheers, Diego Pacheco

Scala 3.0

Image
Scala 3.0 is not out yet but has some interesting new features. I'm still digesting some features some I have some mixed feelings about it. One of the main big changes is the support for Python-like syntax. Scala 3.0 has lots of shortcuts, types of convenience, and different ways to do generics. Scala always had the philosophy to be flexible on the language level and let the tools and companies restrict functionality, so this still pretty much very true. I made a series of 3 videos going over some of the changes in Scala 3. This material is highly inspired by the scala 3 boo/docs. Some code and features on the videos will not be limited by scala 3 but also cool things about scala 2 or even scala in general but mostly I will be talking about scala 3.0. Keep in mind scala 3 is not final so things could change but I believe you gonna be able to have a good sense of what to expect and what's going on. So Let's get started. 

Functional Programming in Kotlin

Image
Kotlin is an interesting JVM language. Today I want to show some capabilities Kotlin has around Functional Programing. FP is a very interesting way to think and create safe programs. Today we will cover High Orde Functions, Lambdas, and also Class extensions. So today I made a simple video and code POC. Let's get started! The Video The Code https://github.com/diegopacheco/kotlin-playground/tree/master/kotlin-fp-fun Cheers, Diego Pacheco

Generics in Kotlin

Image
Kotlin is an interesting JVM language. Today I want to show some capabilities Kotlin has around Generics. Generics are super important for any language. However, some languages abuse generics and have gaps. Generics are important for code reuse and also to enforce type constraints for safety. Kotlin has some interesting ways to express type constraints. So today I made a simple video and code POC. Let's get started!

Reflection in Kotlin

Image
Kotlin is an interesting JVM language. Today I want to show some capabilities Kotlin has around Reflection. Reflection is needed to perform some generic computations often to reuse code around some metadata processing. Kotlin separates Java and Kotlin classes(KClass) and has utility methods around them. So I made a simple POC and Video. Let's get started!

Strings in Kotlin

Image
Kotlin is an interesting JVM language. Today I want to show some capabilities Kotlin has around Strings. Strings are bread and butter or everyday work of any programing language. Strings are a basic type that can either be simple and pleasure or a nightmare i.e go look at Strings in Erlang.  Strings are pretty easy and cool in Kotlin. So I made a short video and some simple POC going over some String features in Kotlin. Let's get started!

Insert Koin: Fast DI in Kotlin

Image
Dependency Management is the oldest tricky of the book. DI is useful not only to make it easier to configure a system but also to make it more extensible and testable. Koin is a very lightweight DI framework for Kotlin. Koin is fast, minimalistic, simple, and yet powerful. Today I want to show we can use Koin is a kotlin simple code I build and also how we can do Unit Tests using JUnit 5 and Koin. So Let's get started.

Kotlin: With, TakeIf and Let

Image
Kotlin has interesting standard APIs and an eco-system. Today I want to cover 3 interesting features in the kotling language: With, TakeIF, and Let. In order to cover that language features on the std SDK, we will end up touching other concepts such as Sring Interpolation / EL and also one of the biggest and interesting language Design choices in Kotlin: The Elvis Operator. I see lots of influence from Scala and Groovy on Kotlin. 

Kotlin with Maven

Image
Kotlin is a modern language on the JVM. Created by JetBrains . Kotlin got popular with Android and Gradle however I would say it's an interesting solution also well for backend services. Kotlin has some interesting design choices and handy APIs and a good eco-system, which I will be covering in the next posts. Today I want to show how we can get Kotlin working on IntelliJ IDEA using maven as a build system. Most of the examples you will set out there on the web will be Gradle-based. Don't get me wrong Gradle rocks but maven still the dominant build system in Java land.  So we will see how to configure the build plugins and all dependencies needed in order to make no only Kotlin builds but also integration with Junit and unit tests. So Let's get started. The Video The Code https://github.com/diegopacheco/kotlin-playground/tree/master/kotlin-1.4-fun Cheers, Diego Pacheco

Kotlin 101

Image
Kotlin is a JVM language created by JetBrains in 2011. Google declared the official preferred language for Android in 2019. Kotkin is heavily inspired in Scala . Kotlin claims to have the good parts of scala without having the bad parts. It's also possible to see some Python and Groovy influence as well. Kotlin makes java much less verbose and has awesome support in sense of IDE thanks to IntelliJ. I'm a Scala guy and prefer scala, however, kotling is an interesting choice especially if you are making android native apps. So today I want to share a video I made with a good walkthrough through several features of the language in a Maven project. So Let's get started!

Polyglot and Native runtime with GraalVM

Image
GraalVM is a universal VM mainly for Java and JVM supported languages. With GraalVM you can run native programs written in Python, Ruy, R and all JVM languages like Scala, Clojure, Groovy and Kotlin also LLVM based like C and C++. Graal VM removes isolation between languages and enables interoperability with natively shared runtime. You might be wondering why botter use other VM? Well, there are a couple of good reasons. Java is a pretty old language and does not have the best startup time. Today we are all running services in containers on top of kubernetes and we are always looking for ways to improve the customer experience. Startup time is not only a matter of better customer experience but also availability. For the developers, this means better development experience and idiomatic experience with the best solution for each specific problem. GrralVM Supported Runtimes GraalVM can be used standalone runtime or embedded in the context of OpenJDK, Node.JS, Oracle...

Setting up a full JVM Env with Vagrant: Java 8, Scala 2.11, Groovy 2.4, Clojure 1.6, Maven 3.3, Gradle 2.4, Sbt 0.13 and Lein

Image
On the previous posts i show how to use docker , docker-compose and nodejs with vagrant now let`s do a full jvm env :-) This setup is pretty easy and straightforward for you however it could take some time depending of your internet bandwidth because we gonna download several components. Remember you need to have Vagrant installed already, this time we gonna need more than just the Vagrant file because java, scala, clojure for instance require we setup environment variables so we gonna need change some files for clojure and sbt  in order to make everything work smoothly.