Posts

Showing posts with the label Code example / Sample / Tutorial

Using the Same Language for Microservices, iOS Apps, and Browser / Web Apps

Image
You're looking for the appropriate language?  Kotlin  might be the language you're looking for! Here you can find some sample projects that show how it can actually be done: Sample iOS app, written in Kotlin, using Maven or Gradle for building   —  this is how it looks Browser app that shows how Kotlin can access HTML's DOM  — this is  how it looks Browser app written in Kotlin that uses HTML5' Canvas  — this is  how it looks Another Browser app that shows how Kotlin can be used to build HTML5 apps   — this is  how it looks …all projects should work out-of-the-box.

Kotlin/JavaScript HTML5 Canvas Example

Image
This is the  source for a simple Kotlin (JavaScript) HTML5 Canvas app  that lets one type a random series of letters. And this is  how it looks like .

Kotlin/JavaScript HTML5 Example for DOM Manipulation

Image
I just published a simple  Kotlin/JavaScript "getting started app"  that  shows the Unicode characters for a specific decimal range. And  this is how it looks like .

Kotlin JavaScript “Hello, World!” Project

Image
 This  GitHub repository  provides you with detailed instructions and an out-of-the-box working sample project to get started with Kotlin and its JavaScript transpilation  capability.

Kotlin / Java / GWT / JavaScript Interoperability HTML5 Web CRUD Showcase

Image
Check out the  code  and check out the actually  deployed and working showcase app  :)

String Concatenation vs StringBuilder Performance Benchmark

Image
This single Java class benchmark, shows impressively that the penalty for using StringBuilder instead of regular String concatenation can be around 5x ! Many static code analyzers like PMD / SonarQube deceptively claim the opposite. This assumption might be a vestige from the pre Java 5 era. Indeed some developers even concatenate compile time constants ( static final ) using StringBuilder. Although be warned , when it comes to using effectively non-final variables inside the concatenation, StringBuilder will drastically outperform the regular String concatenation by several orders of magnitude. Effectively non-final variables are references that are not fixed. On the other hand effectively final values do not necessarily need be prefixed with the " final " keyword but they could be , which differentiates them from effectively non-final variables, that cannot be prefixed with the " final " keyword without causing a compilation error. To state it clear ...

In-Depth Understanding JUnit Tests

Source code on GitHub public class ExampleTest {     private static final Logger LOG = LoggerFactory.getLogger(ExampleTest.class);     /**      * This method won't be executed if the unit test will be (externally) terminated (e.g. from within the IDE).      * You have to act **really** fast in this case.      */     @BeforeClass     public static void beforeClass() throws Exception {         LOG.info("@BeforeClass"); // will be always executed, even if a test fails throwing any Exception     }     /**      * This method won't be executed if the unit test will be (externally) terminated (e.g. from within the IDE).      */     @AfterClass     public static void afterClass() throws Exception {         LOG.info("@AfterClass"); // will be always executed, even if a test fails throwin...

Builder Pattern in Java

The builder pattern can be used to provide a kind of virtual dynamically extendable constructor to build e.g. a model class for RESTful requests where not all fields are required but many fields are optional. public class ClientRequestModel {     private String url;     private String headers;     private String parameters;     private String body;     public ClientRequestModel(Builder builder) {         url = builder.url;     }     public String getUrl() {         return url;     }     public String getHeaders() {         return headers;     }     public String getParameters() {         return parameters;     }     public String getBody() {         return body;     }     @Override     public String toS...

Best practice logging implementation for Java — Logback

pom.xml:         <dependency>             <groupId>ch.qos.logback</groupId>             <artifactId>logback-classic</artifactId>             <version>1.1.1</version>             <scope>compile</scope>         </dependency> src/main/java/resources/logback.xml: <?xml version="1.0" encoding="UTF-8"?> <configuration>     <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">         <encoder>             <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>         </encoder>     </appender>     <root level=" info ">         <appender-ref ref="ST...