Sunday, July 30, 2017

Angular 4 resources

https://cli.angular.io/reference.pdf Angular CLI reference

https://angular.io/guide/cheatsheet Angular cheatsheet

Install bootstrap: https://github.com/angular/angular-cli/wiki/stories-include-bootstrap

Bootstrap recipes https://getbootstrap.com/

Incredibly verbose course on Angular 4, with extremely confusing and complicated examples:
https://www.udemy.com/the-complete-guide-to-angular-2

Much clearer and essential course https://www.youtube.com/playlist?list=PLYxzS__5yYQmi8f94KAGx1ofwFIn-FLNt

Rangle.io training book https://www.gitbook.com/book/rangle-io/ngcourse2/details



Java Flight Recorder JFR: enable recording of exceptions

how to specify custom settings for JFR

http://isuru-perera.blogspot.it/2016/03/specifying-custom-event-settings-file.html

The default settings are in C:\Program Files\Java\jre1.8.0_121\lib\jfr\default.jfc (in Windows... otherwise in JAVA_HOME/jre/lib/jfr/default.jfc in Linux.

so you can enable also the "Exceptions" event, just copy the default.jfc to /tmp/default.jfc, hack it

    <event path="java/exception_throw">
      <setting name="enabled" control="http://www.oracle.com/hotspot/jvm/enable-exceptions">false</setting>
      <setting name="stackTrace">true</setting>
    </event>


set it to true

and start the jfr with

jcmd JFR.start settings=/tmp/default.jfc

and you will smile and be happy



Thursday, July 27, 2017

weblogic.transaction.internal.AppSetRollbackOnlyException: setRollbackOnly called on transaction

If you get "weblogic.transaction.internal.AppSetRollbackOnlyException: setRollbackOnly called on transaction " in your application, and have no clue what is going on, in Oracle Support you find this article:
"When setRollbackOnly() is Called in beforeCompletion() Synchronization Method , Thrown Exception Cannot be Obtained (Doc ID 1547327.1)"
you should apply a patch 16509700 AND specify -Dweblogic.transaction.allowOverrideSetRollbackReason=true , or upgrade to WLS 12.1.3

Tuesday, July 25, 2017

Sunday, July 2, 2017

Venkat Subramanian, Lazy evaluation in Streams




import java.util.Arrays;
import java.util.List;

public class Lazy {
 public static void main(String[] args) {
  List values = Arrays.asList(1, 2, 3, 5, 4, 6, 7, 8, 9);
  System.out.println(values.stream().filter(Lazy::isGT3).filter(Lazy::isEven).map(Lazy::doubleIt).findFirst().orElse(0));

 }

 public static boolean isGT3(int number) {
  System.out.println("isGT3 " + number);
  return number > 3;
 }
 

 public static boolean isEven(int number) {
  System.out.println("isEven " + number);
  return number % 2 == 0;
 }
 
 public static int doubleIt(int number) {
  System.out.println("doubleIt " + number);
  return number * 2;
 }


}




import java.util.stream.Stream;

public class SumEvenNumbers {
 public static int compute(int start, int count) {
  return Stream.iterate(start, e -> e + 1).filter(e -> e % 2 == 0).mapToInt(e -> e * 2).limit(count).sum();
 }
 
 public static void main(String[] args) {
  System.out.println(compute(51, 101));
 }

}




AWS tutorial

Entertaining non-technical presentation:





This one is extensive and sort-of-technical but boring and not hands-on (only slides):





Disappointed by the available free training, I have eventually purchased from https://www.udemy.com/ the aws-certified-solutions-architect-associate course by A Cloud Guru, and created a free AWS account https://eu-west-2.console.aws.amazon.com/console/home?region=eu-west-2#



Venkat Subramanian, Java 8 hidden treasures



Lot of examples on Collectors here https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class CSV {
 public static void main(String[] args) {

  List<String> names = Arrays.asList("a", "b", "c");
  System.out.println(names.stream().map(String::toUpperCase).collect(Collectors.toList()));
  System.out.println(names.stream().map(String::toUpperCase).collect(Collectors.joining(",")));

 }
}




interface Util {
 public static int numberOfCores() {
  return Runtime.getRuntime().availableProcessors();
 }
}

public class IFWithStaticMethod {
 public static void main(String[] args) {
  System.out.println(Util.numberOfCores());

 }
}


interface Fly {
 default void takeoff() {
  System.out.println("Fly:takeoff");
  getState();
 }

 void getState();
}

public class IFDefault implements Fly {
 public static void main(String[] args) {
  IFDefault default1 = new IFDefault();
  default1.takeoff();
 }

 @Override
 public void getState() {
  System.out.println("IFDefault:getState");

 }

}





import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.Comparator;

enum GENDER {
 MALE, FEMALE
}

class Person {
 @Override
 public String toString() {
  return "Person [name=" + name + ", gender=" + gender + ", age=" + age + "]";
 }

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public GENDER getGender() {
  return gender;
 }

 public void setGender(GENDER gender) {
  this.gender = gender;
 }

 public int getAge() {
  return age;
 }

 public void setAge(int age) {
  this.age = age;
 }

 String name;
 GENDER gender;
 int age;

 public Person(String name, GENDER gender, int age) {
  super();
  this.name = name;
  this.gender = gender;
  this.age = age;
 }

}

public class Sorting {
 public static List<Person> getPersons() {
  return Arrays.asList(new Person("Sara", GENDER.FEMALE, 20), new Person("Sara", GENDER.FEMALE, 22),
    new Person("Bob", GENDER.MALE, 20), new Person("Paula", GENDER.FEMALE, 32),
    new Person("Paul", GENDER.MALE, 32), new Person("Jack", GENDER.MALE, 2),
    new Person("Jack", GENDER.MALE, 72), new Person("Jill", GENDER.FEMALE, 12));
 }
 
 public static void main(String[] args) {
  System.out.println(getPersons().stream().sorted(Comparator.comparing(Person::getName)).collect(Collectors.toList()));
 }

}





import java.util.function.Predicate;

public class TestPredicate {
 public static void main(String[] args) {
  Predicate<Integer> isOdd = (param) -> param % 2 == 0;
  Predicate<Integer> isOddAndGreaterThan5 = isOdd.and((param) -> param.intValue() > 5);
  
  System.out.println(isOdd.test(2));
  System.out.println(isOdd.test(3));
  System.out.println(isOddAndGreaterThan5.test(3));
  System.out.println(isOdd.test(6));
 }
}





Saturday, July 1, 2017

OverOps "The Complete Guide to Solving Java Application Errors in Production"

http://land.overops.com/java-application-errors/

I have downloaded the interesting free PDF. In a nutshell:

NullPointerException are the most common type of exception - followed by NumberFormatException (IMHO both can be avoided by better checks of input data/parameters and configuration: the external world is your enemy, never trust it)

Pareto Law: 97% of error logs are caused by just 3% unique errors

Read Joshua Bloch "Effective Java 2nd Edition" on how to handle exceptions

Logging errors is expensive in term of disk space... it's cheaper to fix them than to ignore them!

Operational noise is a killer: make sure your logs are clean, and your exception contain all the context information necessary to troubleshoot them