JShell - Java 9 finally gets a REPL environment

I did a short presetation on JShell - Java9's new REPL environment.

Here's the video (in Bulgarian)

Here's the code for nashorn:

import java.net.http.*;
import java.util.stream.*
import javax.script.*
 
// URL to fetch JSON for weather data for Pravets, Bulgaria
String url = "http://api.openweathermap.org/data/2.5//forecast/daily?q=Pravets,BG&appid=27fc9aa7cc0af902105a9c4c2d97845c&mode=json&units=metric&cnt=7";
 
//java 9 http api
String json = HttpRequest.create(new URI(url)).GET().response().body(HttpResponse.asString()) 
 
// create nashorn engine
ScriptEngine e = new ScriptEngineManager().getEngineByName("js")
 
// expose weather data JSON as global variable to nashorn engine
e.put("str", json)
 
// massage JSON using nashorn and get the max. temp values
double[] values = (double[]) e.eval("Java.to(JSON.parse(str).list.map(function(val) val.temp.max), Java.type('double[]'))")
 
printf(Arrays.toString(values)+"\n")
 
// stat on max. temp values
printf(DoubleStream.of(values).summaryStatistics().toString())

[jug.bg] jProfessionals 3.0 Venkat Subramaniam

Usually I do the review of what we do in our JUG, but Dmitry did quite a good job and he has the best pictures.

Some minor additions from me:

Venkat Subramaniam also known simply as Venkat was here. Venkat is a rockstar (JavaOne Rockstar is someone who did an amazing session at JavaOne. Venkat is 16 (sixteen!!!) times J1 Rockstar in just 4 years).

14590108_10209666223585737_642560942851602417_o-1

Venkat did two sessions and a workshop. The two sessions (one on lambdas and one soft-code session on bad code) were highly popular, probably 150-200 people came.

Then there was a workshop that turned into a discussion on lambdas and quality code in general. Which was awesome.

More info on the event page in facebook and on our jProfessionals social page. Photo album.

Some highlights:

14572767_10211127009798939_2903683900575372082_n

14590067_10209666230545911_2854270441218995292_o-1

14525157_10154174348204811_3398045179896873701_o

14691280_1715325688789631_4489935881640852493_o

14692160_1715325678789632_7790867019126340358_o

 

Java, JDK, JRE locations on OSX

JRE for browsers (mine was 1.8.0_101, 160mb, was up to date):
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java

JDK, JRE installed with installer:
/Library/Java/JavaVirtualMachines/

I had only:
$ du -d1 -h
312M ./jdk1.8.0_25.jdk

Was not up to date.

After installing U101, I had:
$ du -d1 -h
338M ./jdk1.8.0_101.jdk
312M ./jdk1.8.0_25.jdk

I removed the old one.

Cleaning up a linux machine (arch)

TLDR

journalctl --vacuum-size=100M #remove all logs, only retain 100mb
pacman -Scc #remove all package installation files (obsolete and current)
pacman -S bleachbit
bleachbit -c system.*

First, what's big on the system

du -d1 -h / 2>/dev/null | sort -h

This shows a sorted list of the largest dirs in `/`
You can do two levels down:

du -d2 -h / 2>/dev/null | sort -h

My result is:

0 /proc
0 /sys
0 /tmp
12K /dev
12K /srv
16K /lost+found
632K /run
4.3M /boot
13M /opt
15M /etc
75M /root
93M /home
2.4G /var
3.2G /usr
221G /mnt
227G /

I ignore /mnt (because that's an external drive)
Two dirs stand to mind: var and usr.
Let's see what's inside:

du -d1 -h /var /usr 2>/dev/null | sort -h

Then, a little bit deeper:

du -d1 -h /var/log /usr/share /usr/lib /var/cache 2>/dev/null | sort -h

Let's start with the logs

I have 717mb in /var/log.

I'm not a fan of deleting directories randomly, so let's do it the clean way:

$ journalctl --disk-usage
Archived and active journals take up 728.7M on disk.

Let's leave only 100mb of logs:

journalctl --vacuum-size=100M
...
Deleted archived journal /var/log/journal/ba5391...b.journal (8.0M).
...
Vacuuming done, freed 616.6M of archived journals on disk.

More info here on how to configure journalctl here.

Packages

I have 660M /var/cache/pacman. It was 1.8gb, but I ran pacman -Sc to remove unused packages. Let's remove the rest:

pacman -Scc

/usr/share/locale

A lot of users do remove it, or at least clean it up. But I might be a problem. But checkout bleachbit (next paragraph).

Bleachbit

Automatic cleaner. Will delete a lot of stuff, but for it was mostly locales.

$ pacman -S bleachbit
$ bleachbit -p system.*
Disk space to be recovered: 488.8MB
$ bleachbit -c system.*

You can look for more stuff to delete:

bleachbit --list
bleachbit -p thunderbird.*

Buying a new openwrt-compatible router. Howto

I need a new router, because the time machine I have been using for so long is finally giving up. It was a pretty strong machine. God bless her soul. Now I'd like to have something like this as a router:
solid run
https://www.solid-run.com/product/clearfog-pro/ But that's pricey and needlessly powerful, it costs extra to add wifi, box, power and so on.

OpenWRT

Since I found out OpenWRT exists I have continuously rooted my routers. OpenWrt is minimalistic linux made especially for routers. I don't like the fact that it's not a full-fledged linux - they had to minimize the footprint and some packages are incomplete/different. But it does its jobs perfectly.

There is a hardware compatibility list which now features devices with 1gb ram and 4gb flash. Unfortunately they either have no wifi, or not enough lan ports. Even the Bulgarian producer Olimex is featured close to the top.

Starting from top to bottom, here's how I chose my router:
(I skip all that have no wifi)

  • FLASH MB/RAM MB/NAME/Reasons
  • 256/1024/Gateworks Ventana GW5xxx/only two GbE ports;hard to buy
  • 16/128/EnGenius ECB1750/no GbE
  • 16/128/Belkin F9K1115/hard to buy
  • 32/128/WZR-HP-AG300H/no ac
  • 32/128/Meraki Z1/no ac
  • 16/128/EnGenius ECB1750/no GbE

Possibilities (all of them are available in local shops):
(all of them support some type of ac on 5Ghz)

  • FLASH MB/RAM MB/NAME/PRICE
  • 128/512/Linksys WRT1900AC/€235
  • 128/128/Cisco-Linksys EA6300/€106
  • 128/256/Buffalo WZR-600DHP2-EU/€100
  • 128/128/Netgear R6100/€100
  • 16/128/ZyXEL NBG6616/€85
  • 16/128/TP-LINK Archer C7/€98
  • 16/128/TP-LINK Archer C5/€75
  • 16/128/D-Link DIR-860L/€53

In the table I didn't put CPU type and whether they have USB 2/3 ports.

Poor guy's monitor emulator

Some mainboards won't boot without an active graphics chip which in turn won't start without a monitor connected.

This hack works with 3 resistors (75 ohm (50-150 is fine), 0.25 watt (0.125-0.500 watt is fine)).


Putt them like this

vga_dummy_electronic_schema

Resources:

https://www.techpowerup.com/forums/threads/how-to-make-a-dummy-vga-dongle.86507/
http://www.geeks3d.com/20091230/vga-hack-how-to-make-a-vga-dummy-plug/
http://www.electronics-lab.com/how-to-make-a-vga-dummy-plug/

Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)

I did a talk on Jigsaw at BGOUG.

The talk is for a very important new feature in Java SE 9. Code named Jigsaw, this feature modularizes the Java SE platform.
The coolest thing I do at the talk is to create a custom JRE.

Of course the jug and jPrime were mentioned.

Code: https://bitbucket.org/stybz/jigsaw.sty/src/

Video:

Presentation:

[jug.bg] Speaking at Riga Dev Day

So I'll do a talk about Http/2.0 at Riga Dev Day Conference. I'll be there representing the jug.bg. I'm pretty psyched to check out Latvia.

My session is on the first day

speaking-at-rdd16-2

 

Update: my talk didn't go too well, because the technicians couldn't manage to connect my laptop to the projector - even though they asked about what kind of laptop I had. It took us 15 min, the it was flickering the whole time and that made me nervous and I overshot my time, because of wrong time on screen.

And to top it all of they recorded it and said it will go to youtube in a couple of months. 🙁

Not that it matters, but all my demos worked, kind of a Pyrrhic victory.

Update2: Riga is awesome and very beautiful.

IMG_6612 IMG_6616 IMG_6641

[jug.bg] "Everything you need to know about Java Classloaders" by Oleg Shelajev

IMG_6594

Today Oleg presented a very interesting session about how class loaders work. He even remotely loaded classes from images (I imagine steganography).

Oleg works for Zero Turnaround, the company behind jRebel. Code examples here. The presentation is here.

One of the most interesting sessions so far IMHO.

[jug.bg] Adopt OpenJDK is not for mere mortals

forbidden.duke

A bit of introduction - we as a jug (java user group) got more active at the end of 2013 in no small part thanks to Ivan. We managed to build openjdk, import it in 3 major IDEs (eclipse, intellij and netbeans) and contributed a Virtual Machine with buildable openjdk 9 (both in fedora and ubuntu) and organized a couple of events, we decided we were ready for the next part.

At the end of 2014 we started timidly to try to contribute in the Adopt OpenJDK program. Adopt OpenJDK allows everyone* to participate in building and writing the java platform itself (or at least that's how we understood it *back then*).

We knew that LJC (London Java Community - their most popular jug) heavily participated in the new Date/Time API and soujava (Brasil's most popular jug) also managed to include code in the OpenJDK. Elated by these guys' successes we decided we had enough free time and sheer energy to contribute to the OpenJDK and thus put ourselves on the OpenJDK map.

In December 2014 we asked for something to work on. Nobody answered.

We decided to work on a simple Throwable convenience method (JDK-5050783). We had a hackaton. We submitted our fix. We were given some feedback and we submitted another. And we were told not to play with grown up stuff. That was a bit discouraging. But we didn't give up.

In February 2015 we started working on jaxp warnings. We fixed 43 easy warnings and submitted a patch. Then we fixed more harder warnings and submitted another patch. The great Joe Darcy answered but unfortunately we got nowhere again. That sucks.

A bit before that (Dec 2014) jug.bg member Doychin Bonzhev found a bug in the NetworkInterface and submitted a solution. He even submitted to another mail-list. He got a response (saying it is reasonable solution) and answered, but that was it. Nothing AFAIK followed.

So that was it for us. We gave up. Probably we didn't know the right people, but I argue that shouldn't matter. From time to time we get mentioned as collaborators in the Adopt OpenJDK by our dear friend Mani. We don't feel like that at all.

* Now you understand why the asterisk, right?

[jug.bg] jProfessionals 2.0

Today was the second edition of the jProfessionals format we started 5 months ago.

IMG_6574

jProfessionals is a one-day free conf. Smaller than jPrime (our star yearly event).

In the first version we invited Koshuke Kawaguchi. (the creator of Jenkins CI).

 

Today the first presenter was Richard Warburton.

IMG_6573

The session was about java 8 lambdas and even though it started as a very introductory session it turned out to be quite interesting. We discussed currying, Optional and the elvis operator.

What I learned is that Optional with value types is going to be fast (all in stack, no heap). Elvis is going in another direction - just a simple !=null check. Optional is kind of an explicit contract (preferred despite the verbosity and the extra object).

 

The second speaker was Vlado Tsanev aka tsachev.

IMG_6575

He talked about Spring REST Docs. The talk was one big live demo. REST Docs is a way to document a rest api automatically by extracting the info from the tests - it creates cURL commands, headers, params as so called snippets, and it allows the use of a adoc files with links to the REST Docs snippets.

 

After a tasty lunch it was time for "The Seven Deadly Sins of Microservices" by Daniel Bryant.

IMG_6576

It was a soft session with a lot of links and cool ideas of what microservices are good for and what they are not. There was a discussion on where people fail mostly using them. Very interesting and engaging - I bookmarked a lot of books that I'm never going to read.

 

Doychin Bondzev talked about Firebird (an alternative to postgres) - free, has triggers and is embeddable with nice tools and binary backup that is fast enough on windows.

 

Richard Warburton was next with another session for the future of Generics which was really fun.

IMG_6577

I finally understood why enums are defined recursively (Enum<E extends Enum<E>>).

 

Next was a talk about Jenkins Builds with Docker Containers by Petar Velikov from e-card.bg.

IMG_6578

It was quite interesting especially the docker part (he even used dockviz).

 

Finally there were two lightning talks. Martin Toshev talked about RxJava and RxJS.

Another guy - Teodor Tunev talked about Activiti - a java BPM platform far better than jBPM in his words.

IMG_6578

 

Finally some beer was due.

IMG_6580

(has not arrived yet)

Fosdem 2016

My first fosdem this year. I found a lot of interesting things mostly on the opensource tracks. The "free java" track IMHO was a bit unpopular even though Stephen Chin and Mark Reinhold were there.

I guess I'm used to a better treatment on a conference (I go mostly as a speaker). Here it was rainy and cold and even though the french fries were awesome, I'm used to better food.

IMG_6498 IMG_6499 IMG_6500

[jug.bg] Dockerize Spring Boot Application

Antoan presented a session about Spring Boot running on Docker and how to use the docker maven plugin inside a Spring Boot application.

Actually we talked mostly about running Docker and application from the ecosystem. There was a statement that uninstalling Kitematic requires payment, which started a discussion about this model.

IMG_6532

[jug.bg] The Jenkins' creator in Sofia thanks to @bgjug #jprofessionals

The first edition of jProfessionals is happening right now.

koshuke.presentation

We managed to bring over Koshuke Kawaguchi. He's the creator of Hudson and after leaving Oracle, creator of the open source Jenkins. The topic was Jenkins 2.0.

The next speaker is Vladimir Tsanev. He'll talk about JMH with examples. Very interesting topic. He actually showed how to create a simple benchmark and to how to execute it.

Update: After the plentiful lunch Svetlin Nakov was awesome presenting HTTP/2. He was great at explaining the inner workings of the new protocol. Emil Doychev presented Groovy. There was a little bashing on JPA.

Some time for coffee and Doychin Bondzhev presented JavaFX in a very accessible way.

jpros.audience

Trayan Iliev talked about high performance reactive programming with java 8. It was very interesting. Especially the demo at the end.

[jug.bg] Devoxx 2015

IMG_6052

Wow.

Writing this I'm listening to Alan Bateman and Mark Reinhold deliver a session on the new Jigsaw (their third attempt?). This time it might work.

There's a lot of beer, more than I can handle (it turns out that a teenage girl handles her liquor better than I can) . A lot of awesome sessions - even one on the history of the universe.

The JUG is represented by Ivan, Krasi, Vladi and a bunch more awesome folks that make my trip here awesome.

Explaining to young female students that an IT career doesn't suck (that much)

IMG_2305

It was a surprise to me, but I got invited to a forum organized by HP to explain to young women that a career in IT is not scary, doesn't suck at all and why it might be something that they may enjoy.

There were around 50 guests.

I was invited as an example of a "young" "successful" person. It was an honor sitting next to the Iravan Hira (CEO of HP Bulgaria), Preslav Pavlov (Global Deliveries Director for HP), Rumyana Trencheva (CEO of SAP Bulgaria), Zornica Iankova (HP's HR Director), Kristina Stoitsova (R&D at VMware).

Modrator was webcafe.bg's owner Sibina Grigorova.

IMG_2321

The event was highly entertaining for me. The public initially wasn't keen on asking too many questions. But the discussion afterwards proved interesting. I was happy to hear that female CEOs didn't feel male colleagues treated them differently. Still there are far more males than females in IT.

IMG_2348

Of course I wore a @bgjug t-shirt.

[jug.bg] pi4j on RaspberryPi

IMG_5872

Jug.mk's leader Pance Cavkovski is talking today about how to put java on a raspberry pi and then automate your home.

There is also a slide about NodeMCU that helps you distribute GPIO around your home and control different devices. NodeMCU is a wifi-to-GPIO for $5 basically, which is awesome:

nodemcu

Today was a busy day, the beer was over in seconds and that sucks because Ivan and I only had a beer.

IMG_5873

I brought a Odroid C1. But pi4j doesn't work, so I used jOdro.

We have a new banner that we didn't forget to bring today, so there it is:

fb232f01376e5b1d7ac122e88a72766e3830a5576fe8c0b28a2866eaa10dbe13

[jug.bg] A hackaton showcasing JSR 371 (MVC) 2015.09.30

 

On 30.09.2015 we did a workshop that showcased the very beta of MVC 1.0 implemented in ozark.

We had to use glassfish, which I somehow dislike, because I don't understand it and it didn't run very smooth, but in glassfish's defense I have to say that reloading the application without restarting worked like a charm. That is awesome.

MVC is promising and I like how simple it is.

The code is here: https://github.com/bgjug/mvc10-workshop.

spring.mvc

HTTPS faster than HTTP ?!

It’s possible that some users may even find that the HTTPS version of a web site is faster than HTTP. This can happen if they sit behind a coporate HTTP proxy that normal intercepts, examines and records web traffic. An HTTPS connection will often just be forwarded as a simple TCP connection through the proxy because HTTPS traffic cannot be intercepted. It’s this bypassing that can lead to improved performance.

Source: http://blog.httpwatch.com/2011/01/28/top-7-myths-about-https/

I can actually confirm this to be true in some cases. Even worse is that people might think that HTTPS prevents corporate from sniffing - that is not always the case 🙂

In Memoriam - Lorkis (8 yrs)

Wow, 8 whole years have passed since Lora left us. I feel old.

Looking forward is my thing, looking back - I've always had a difficulty doing it. It makes me reminisce but in a melancholic way. I have very large white spots in regards to my past. I guess my brains likes forgetting.

The weird part is that two very close friends have birthdays today. Mixed feelings.

Checking the old pictures makes me smile - there isn't a single boring picture with Lora. Rest in peace.

A bunch of pics I gathered: http://picasaweb.google.com/mihail.stoynov/InMemoriamLorkis
More pics from friends: http://picasaweb.google.com/renkata/ByPUWK

My personal Lora song: Eva Cassidy - Autumn Leaves

[jug.bg] Hackaton to create a JBoss Forge plugin to create Spring Boot applications

So this weekend the Bulgarian Java User Group (jug.bg) organized a hackaton to try to create a JBoss Forge plugin to create Spring Boot applications.

JBoss Forge is a tool to ease development. Main traits are it can create JPA entities, It can create an example REST interface to those entities, a web interface to those entities and it integrates with Eclipse and IntelliJ IDEA:

Screen Shot 2015-08-12 at 11.51.02
Cmd+Option+4 in IDEA on OSX, Ctrl+4 in Eclipse on Windows

The code is here. Here are a couple of pictures from the event:

IMG_5514 IMG_5515IMG_5513

 

Remote-controlled lego with LeJOS using EV3 controller

The last day of jCrete was with two hacking sessions - one on optimizing a NES emulator (if I got it correctly) and one on building a Lego and writing some software on LeJOS and EV3 controller (ARM processor inside).

This is what we did (@claudiotagliola did more than I have):

lego IMG_5263 IMG_5266

We used LeJOS, with LeJOS plugin for eclipse, initial code we got from Steven's presentation on the subject,  but we decided not to build the thing shown on the presentation.

We built a pretty bulky two-motor lego using snow-chains. We installed a server app that listened on a port and we sent it commands using a awt/swing app.

Videos:

Here's the code:

The app installed on the device:

package jcrete.hacking;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

import lejos.hardware.Button;
import lejos.hardware.Key;
import lejos.hardware.KeyListener;
import lejos.hardware.motor.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.utility.Delay;

/**
 * This was written on jCrete 2015 on a LeJOS session by Steven Chin.
 * 
 * We were given the task to build a lego and do something cool with it.
 * We built a pretty large tank and remote-controlled it via wi-fi with
 * simple socket commands.
 * 
 * For more info, go to https://mihail.stoynov.com/?p=2909
 * 
 * This is a mock server for testing if you don't have a lego at hand.
 * 
 * @author Nayden Gochev, jug.bg
 * @author Mihail Stoynov, jug.bg
 *
 */
public class E3vRemoteControlCarApp {

	static boolean isRunning = true;

	public static void main(String[] args) throws IOException {

		try (
				final EV3LargeRegulatedMotor leftMottor = new EV3LargeRegulatedMotor(MotorPort.B);
				final EV3LargeRegulatedMotor rightMottor = new EV3LargeRegulatedMotor(MotorPort.C);
				ServerSocket serv = new ServerSocket(19231);
				) {

			Socket socket = serv.accept();
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					socket.getInputStream()));

			// if we use the buttons on the device directly
			Button.UP.addKeyListener(new KeyListener() {

				@Override
				public void keyReleased(Key k) {
					leftMottor.stop(true);
					rightMottor.stop(true);
				}

				@Override
				public void keyPressed(Key k) {
					leftMottor.setSpeed(1500);
					leftMottor.setAcceleration(150);
					leftMottor.forward();
					rightMottor.setSpeed(1500);
					rightMottor.setAcceleration(150);
					rightMottor.forward();

				}
			});

			Button.DOWN.addKeyListener(new KeyListener() {

				@Override
				public void keyReleased(Key k) {
					leftMottor.stop(true);
					rightMottor.stop(true);
				}

				@Override
				public void keyPressed(Key k) {
					leftMottor.setSpeed(1500);
					leftMottor.setAcceleration(150);
					leftMottor.backward();
					rightMottor.setSpeed(1500);
					rightMottor.setAcceleration(150);
					rightMottor.backward();

				}
			});

			Button.RIGHT.addKeyListener(new KeyListener() {

				@Override
				public void keyReleased(Key k) {
					rightMottor.stop(true);
					leftMottor.stop(true);
				}

				@Override
				public void keyPressed(Key k) {
					rightMottor.setSpeed(1500);
					rightMottor.setAcceleration(150);
					rightMottor.forward();
					leftMottor.setSpeed(1500);
					leftMottor.setAcceleration(150);
					leftMottor.backward();
				}
			});

			Button.LEFT.addKeyListener(new KeyListener() {

				@Override
				public void keyReleased(Key k) {
					rightMottor.stop(true);
					leftMottor.stop(true);
				}

				@Override
				public void keyPressed(Key k) {
					rightMottor.setSpeed(1500);
					rightMottor.setAcceleration(150);
					rightMottor.backward();
					leftMottor.setSpeed(1500);
					leftMottor.setAcceleration(150);
					leftMottor.forward();
				}
			});

			Button.ESCAPE.addKeyListener(new KeyListener() {

				@Override
				public void keyReleased(Key k) {
				}

				@Override
				public void keyPressed(Key k) {
					E3vRemoteControlCarApp.isRunning = false;
				}
			});


			// we copied it from somewhere, not necessary
			Delay.msDelay(3000);


			// the listener with the while readline
			String line;
			while ((line = reader.readLine()) != "STOP" && isRunning) {
				System.out.println("RECIEVED " + line);
				switch (line) {
				case "UP-PRESS":
					leftMottor.setSpeed(1500);
					// leftMottor.setAcceleration(150);
					leftMottor.forward();
					rightMottor.setSpeed(1500);
					// rightMottor.setAcceleration(150);
					rightMottor.forward();
					break;
				case "UP-RELEASE":
					leftMottor.stop(true);
					rightMottor.stop(true);
					break;
				case "DOWN-PRESS":
					leftMottor.setSpeed(1500);
					// leftMottor.setAcceleration(150);
					leftMottor.backward();
					rightMottor.setSpeed(1500);
					// rightMottor.setAcceleration(150);
					rightMottor.backward();
					break;
				case "DOWN-RELEASE":
					leftMottor.stop(true);
					rightMottor.stop(true);
					break;
				case "LEFT-PRESS":
					rightMottor.setSpeed(1500);
					// rightMottor.setAcceleration(150);
					rightMottor.backward();
					leftMottor.setSpeed(1500);
					// leftMottor.setAcceleration(150);
					leftMottor.forward();
					break;
				case "LEFT-RELEASE":
					rightMottor.stop(true);
					leftMottor.stop(true);
					break;
				case "RIGHT-PRESS":
					rightMottor.setSpeed(1500);
					// rightMottor.setAcceleration(150);
					rightMottor.forward();
					leftMottor.setSpeed(1500);
					// leftMottor.setAcceleration(150);
					leftMottor.backward();
					break;
				case "RIGHT-RELEASE":
					rightMottor.stop(true);
					leftMottor.stop(true);
					break;
				case "STOP":
					E3vRemoteControlCarApp.isRunning = false;
					break;
				}
			}
		}
	}
}

 

The controller:

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;
 
import javax.swing.JButton;
import javax.swing.JFrame;
 
/**
/**
 * This was written on jCrete 2015 on a LeJOS session by Steven Chin.
 * 
 * We were given the task to build a lego and do something cool with it.
 * We built a pretty large tank and remote-controlled it via wi-fi with
 * simple socket commands.
 * 
 * For more info, go to https://mihail.stoynov.com/?p=2909
 * 
 * This is a mock server for testing if you don't have a lego at hand.
 * 
 * @author Nayden Gochev, jug.bg
 * @author Mihail Stoynov, jug.bg
 *
 */
public class Remote extends JFrame {
 
	private static final long serialVersionUID = -8402983606638099877L;
 
	private final JButton left;
	private final JButton right;
	private final JButton up;
	private final JButton down;
	private final JButton stop;
 
	private BufferedWriter pw;
 
	public static void main(String[] args) {
		Remote remote = new Remote();
		remote.setSize(500, 500);
		remote.setVisible(true);
	}
 
	public Remote() {
		try {
			Socket socket = new Socket("192.168.0.107", 19231);
//			Socket socket = new Socket("127.0.0.1", 19231);//for mocking
			pw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
		setLayout(new BorderLayout());
 
 
 
		left = new JButton("LEFT");
		this.getContentPane().add(left, BorderLayout.WEST);
		left.addMouseListener(new MouseAdapter() {
 
			@Override
			public void mouseReleased(MouseEvent e) {
				leftRelease();
//				System.out.println("LEFT-RELEASE\n");pw.flush();
			}
 
 
			@Override
			public void mousePressed(MouseEvent e) {
				leftPress();
//				System.out.println("LEFT-PRESS\n");pw.flush();
			}
 
 
		});
		right = new JButton("RIGHT");
		this.getContentPane().add(right, BorderLayout.EAST);
		right.addMouseListener(new MouseAdapter() {
 
			@Override
			public void mouseReleased(MouseEvent e) {
				rightRelease();
//				System.out.println("RIGHT-RELEASE\n");pw.flush();
			}
 
 
 
			@Override
			public void mousePressed(MouseEvent e) {
				rightPress();
//				System.out.println("RIGHT-PRESS\n");pw.flush();
			}
 
 
		});
		up = new JButton("UP");
		this.getContentPane().add(up, BorderLayout.NORTH);
		up.addMouseListener(new MouseAdapter() {
 
			@Override
			public void mouseReleased(MouseEvent e) {
				upRelease();
//				System.out.println("UP-RELEASE\n");pw.flush();
			}
 
 
 
			@Override
			public void mousePressed(MouseEvent e) {
				upPress();
//				System.out.println("UP-PRESS\n");pw.flush();
			}
 
 
		});
		down = new JButton("DOWN");
		this.getContentPane().add(down, BorderLayout.SOUTH);
		down.addMouseListener(new MouseAdapter() {
 
			@Override
			public void mouseReleased(MouseEvent e) {
				downRelease();
//				System.out.println("DOWN-RELEASE\n");
			}
 
 
 
			@Override
			public void mousePressed(MouseEvent e) {
				downPress();
//				System.out.println("DOWN-PRESS\n");
			}
 
 
		});
		stop = new JButton("STOP\n");
		this.getContentPane().add(stop, BorderLayout.CENTER);
		stop.addMouseListener(new MouseAdapter() {
 
			@Override
			public void mousePressed(MouseEvent e) {
				sendCommand("STOP");
			}
		});
 
		//keypad arrows work only if the focus is on the stop button
		//lame but that's life
		stop.addKeyListener(new KeyListener() {
			@Override
			public void keyTyped(KeyEvent event) {
				// TODO Auto-generated method stub
 
			}
 
			@Override
			public void keyReleased(KeyEvent event) {
				if(KeyEvent.VK_UP == event.getKeyCode()){
					upRelease();
				} else if(KeyEvent.VK_DOWN == event.getKeyCode()){
					downRelease();
				} else if(KeyEvent.VK_LEFT == event.getKeyCode()){
					leftRelease();
				} else if(KeyEvent.VK_RIGHT == event.getKeyCode()){
					rightRelease();
				}
			}
 
			@Override
			public void keyPressed(KeyEvent event) {
				if(KeyEvent.VK_UP == event.getKeyCode()){
					upPress();
				} else if(KeyEvent.VK_DOWN == event.getKeyCode()){
					downPress();
				} else if(KeyEvent.VK_LEFT == event.getKeyCode()){
					leftPress();
				} else if(KeyEvent.VK_RIGHT == event.getKeyCode()){
					rightPress();
				}
			}
		});
 
 
		pack();
	}
 
	private void downPress() {
		sendCommand("DOWN-PRESS");
	}
 
	private void sendCommand(String command) {
		try {
			pw.write(command+"\n");pw.flush();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
 
	private void downRelease() {
		sendCommand("DOWN-RELEASE");
	}
 
	private void leftPress() {
		sendCommand("LEFT-PRESS");
	}
 
	private void upRelease() {
		sendCommand("UP-RELEASE");
	}
 
	private void leftRelease() {
		sendCommand("LEFT-RELEASE");
	}
	private void rightRelease() {
		sendCommand("RIGHT-RELEASE");
	}
 
	private void upPress() {
		sendCommand("UP-PRESS");
	}
 
	private void rightPress() {
		sendCommand("RIGHT-PRESS");
	}
}

 

Mock app to test the remote:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * This was written on jCrete 2015 on a LeJOS session by Steven Chin.
 * 
 * We were given the task to build a lego and do something cool with it.
 * We built a pretty large tank and remote-controlled it via wi-fi with
 * simple socket commands.
 * 
 * For more info, go to https://mihail.stoynov.com/?p=2909
 * 
 * This is a mock server for testing if you don't have a lego at hand.
 * 
 * @author Nayden Gochev, jug.bg
 * @author Mihail Stoynov, jug.bg
 *
 */
public class ServerMock {
	public static void main(String[] args) throws IOException {
		try (ServerSocket server = new ServerSocket(19231);) {
			Socket socket = server.accept();
			System.out.println("ACCEPTING");
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(
							socket.getInputStream()));
	
			System.out.println(reader.readLine());
			String line;
			while ((line = reader.readLine()) != null) {
				System.out.println("RECIEVED " + line);
			}
		}
	}
}

Powering an external hdd on a raspberry pi or odroid

IMG_5449

I've had issues powering an external hdd on a raspberry pi or odroid. I had to buy Y-cable (Y-cable = branched USB cord for dual power).

I found out, that powering the raspberry pi or odroid on the normal USB supplies more power than on the mini/micro-USB they use. The micro/mini USB used for power has a fuse that cannot supply more than 1A, but powering via one of the USB typeA works fine. Of course you would need a Y-cable, because even the most powerful USB chargers cannot produce enough power on one port.

That's another point - most USB chargers say they produce 2A or 2.1A and the crappy ones produce .3A, the good ones go up to .9A. So everybody lies. But .9A is good enough with a Y-cable.

The PI/Odroid use like .5A, the drive uses .3A, but they spike to more than 1Amp.

jCrete

jCrete is an unconference organized by Heinz Kabutz (author of the Java Specialist newsletter).

*unconference - top people, informal talks, discussions instead of sessions (most in a restaurant or at the beach).

What I learned:

Unsafe is going to be available in jdk9 with a jre switch on startup. Oracle is working on isolating (boundary checks) the unmanaged heap so that

  • mistakes will not mess up the managed heap
  • mistakes will not cause a segmentation fault (crash the whole jvm, because someone is trying to read memory from another process)

Oracle might introduce a commercial GC with deterministic stop-the-world pauses.

G1 will become the default GC in jdk9.

I will update this accordingly with more info.

jdk1.8.0_25 internal compiler error

Screen Shot 2015-07-14 at 11.35.31

A bug report here: https://bugs.openjdk.java.net/browse/JDK-8065424

Information:Using javac 1.8.0_25 to compile java sources
Information:java: An exception has occurred in the compiler (1.8.0_25). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
Information:java: java.lang.NullPointerException
Information:java: at com.sun.tools.javac.code.Types.isConvertible(Types.java:290)
Information:java: at com.sun.tools.javac.comp.Check.assertConvertible(Check.java:922)
Information:java: at com.sun.tools.javac.comp.Check.checkMethod(Check.java:876)
Information:java: at com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:3838)
Information:java: at com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3615)
Information:java: at com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3522)
Information:java: at com.sun.tools.javac.comp.Attr.checkMethodId(Attr.java:3501)
Information:java: at com.sun.tools.javac.comp.Attr.checkId(Attr.java:3488)
Information:java: at com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:3237)
Information:java: at com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2011)
Information:java: at com.sun.tools.javac.comp.Attr.attribTree(Attr.java:607)
Information:java: at com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1843)
Information:java: at com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1465)
Information:java: at com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1704)
Information:java: at com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1384)
Information:java: at com.sun.tools.javac.comp.Attr.attribStat(Attr.java:676)
Information:java: at com.sun.tools.javac.comp.Attr.attribStats(Attr.java:692)
Information:java: at com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1142)
Information:java: at com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:909)
Information:java: at com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1035)
Information:java: at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:778)
Information:java: at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4342)
Information:java: at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4252)
Information:java: at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4181)
Information:java: at com.sun.tools.javac.comp.Attr.visitClassDef(Attr.java:892)
Information:java: at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:693)
Information:java: at com.sun.tools.javac.comp.Attr.attrib(Attr.java:4156)
Information:java: at com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1248)
Information:java: at com.sun.tools.javac.main.JavaCompiler.compile2(JavaCompiler.java:901)
Information:java: at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:860)
Information:java: at com.sun.tools.javac.main.Main.compile(Main.java:523)
Information:java: at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
Information:java: at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
Information:java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:168)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:382)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:296)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:204)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:176)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1196)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:877)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:945)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:840)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:663)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:370)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:191)
Information:java: at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:137)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:293)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:124)
Information:java: at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:242)
Information:java: at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:41)
Information:java: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
Information:java: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Information:java: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
Information:java: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
Information:java: at java.lang.Thread.run(Thread.java:745)
Information:java: Errors occurred while compiling module 'xj-conc-j8'
Information:7/14/15, 11:22 - Compilation completed with 1 error and 0 warnings in 2s 319ms
Error:java: Compilation failed: internal java compiler error

[jug.bg] RabbitMQ session

Today we had a BGJUG event.

Martin presented RabbitMQ - Spring Framework's default message broker.
IMG_4964 IMG_4966

 

I followed the presentation and using Docker's GUI for OSX called Kitematic, easily created a rabbitmq server and a client in a maven project:

Screen Shot 2015-06-29 at 20.51.51Screen Shot 2015-06-29 at 21.07.04

Again there was a lot of beer, but since we have been accused of advertising beer brands, there will be no pics.

 

[jprime.io] Feedback

So, jprime.io is over, let's see how well we did:

Screen Shot 2015-05-28 at 17.15.33

Screen Shot 2015-05-28 at 17.18.33
Translation: A huge BRAVO. The organization was well done.
Screen Shot 2015-05-28 at 17.19.08
Translation: the event is exceptionally interesting. I learned a lot and I was inspired.
Screen Shot 2015-05-28 at 17.19.25
Translation: I liked it a lot. Please inform me if you plan to do anything again soon. The day was not wasted. Learned a lot.

---

Screen Shot 2015-05-28 at 17.23.25 Screen Shot 2015-05-28 at 17.25.20 Screen Shot 2015-05-28 at 17.25.33 Screen Shot 2015-05-28 at 17.25.48 Screen Shot 2015-05-28 at 17.26.02 Screen Shot 2015-05-28 at 17.29.57

---

Also in my inbox:

Tова което вчера казвах на Найден, че още от първата конференция бяхте много добри.

Поздрави,
—Филип

Translation: Basically Phillip is saying we are the best java conf here.

---

Another one:

Здрасти,
Браво за конфа. Получи се доста добре.
Готиното беше, че хората наистина се събираха и си говореха.
Аз трябваше да тръгна по-рано, че имах малко лични ангажименти,
и изпуснах всичко след предпоследната лекция, но това на което бях,
наистина беше готино и се усещаше приятелската атмосфера 🙂
Браво,

Стеф


From: "Stefan Vartolomeev"

Translation: Stef is saying it was nice that people communicated and that the atmosphere was friendly and the feeling altogether was cool.

---

Screen Shot 2015-05-28 at 17.48.27Screen Shot 2015-05-28 at 18.02.35 Screen Shot 2015-05-28 at 18.03.31 Screen Shot 2015-05-28 at 18.03.43 Screen Shot 2015-05-28 at 18.04.03 Screen Shot 2015-05-28 at 18.04.22 Screen Shot 2015-05-28 at 18.05.49 Screen Shot 2015-05-28 at 18.06.09

 Update:

 ...

I think we did well.

jprime: Why would someone organize a conference?

Every morning I wake up to this: Screen Shot 2015-05-20 at 23.09.29and this: Screen Shot 2015-05-20 at 22.21.30. Every day I wage a fruitless war to go down to zero on both fronts and I fail miserably. But I'm getting better.

Recently we managed to "inject" a company as a gold sponsor after all the deadlines have passed. We did it in 20 minutes after 6 phone calls.

The server firewall failed. Someone fixed it on a Saturday morning.

Our invoicing architecture after so many patches fails to follow all the complex branches of the process of issuing an invoice. We somehow manage to still use it fruitfully. And I have big plans for rewriting most of it.

ePay integration was a pain it the ass. Very bad documentation, different undocumented services, support could be better. But it was fun encrypting and decrypting a ton of messages until we stabilized it. We even "support" credit cards (in a way).

Our Turkish speaker delayed his visa application. I called the Bulgarian embassy in Ankara. They were nice, didn't forget to call me back. Actually they kept me updated the whole time. And they issued the visa in less than a day. So kudos to them.

We fight less, work more, plan better, became team players and learned a lot. Organizing a conference is fun.

Go buy a ticket at jprime.io.

An amateur's guide to organizing a conference

I remember when 8 months ago Ivan came up with the idea to organize a conference, we were all - why the hell not. How hard can it be? I want to go back in time and give my cocky past self a slap in the face. A very hard slap.

We had already done many hackatons, pushed a couple of openjdk patches (which are as of now still not accepted) and drank many beers planning the bright future.

I remember feeling a bit in a rut. And this was a really good excuse to write some java code, meet new java people and work with some new java technologies.

I remember when we just talked about the conference for four months. It all got very real 4 months ago and we had a choice - organize the whole thing in 4 months (which then I had no idea was a really short time for a conference) or give up for next year.

We were very eager back then. We all decided to do it. I remember some of our organizers looking at us, probably thinking "let's sit and watch go down in flames".

4 months later I know a lot about accounting and VAT. I wrote a lot of code, most of the times after midnight. The funniest story is when we were deploying the electornic ticket system (epay integration) - proudly written mostly by me (but I'm ashamed of the code).

4 months later I can sign a contract in a couple of hours. A procedure previously taking me almost a week. I have optimized so many of the bureaucracy procedures I do. As a business owner I had the same issues, but after we started the conference I couldn't keep up and had to optimize again and again. Here's the place to send a special thank you for our lawyer and accountant - two of the people I would fail without.

4 months later I sleep less, and I do more. I hope the sleeping part will fix itself after the 27th. I now can read 30 emails in an hour (unfortunately after another hour I have 30 more). Half of my inbox has "Ivan" in the sender's field - he has the nasty habit of putting every little detail in an email, requires the same from me, and is pissed off if I fail to read something 2 hours after he sent it.

One of the funniest stories from the past week is me sitting in an office, signing a contract. The contract has to be signed, and I have to pay that contract in 10 minutes. So I'm sitting on my laptop sending the money, the other side sitting on theirs checking if the money is going to arrive. And at some point it feels as a movie scene where the good guy is going to appear any minute and break the drug deal.

So organizing a conference is tough, but it's a lot of fun. Next time (yes, if I have the opportunity, I'd do it again) it's going to be even better. My conference cherry is about to be popped in 27 days. Hope to see you there.

--Mihail S (and, yes, I know it says "by Admin", but we have more important things to fix first)

[jug.bg] Simon Scholz presented Eclipse E4 in a bgjug event

Simon Scholz from Vogella presented Eclipse RCP development, the new Eclipse Mars (to be published in a month) and tips and tricks on migrating from eclipse 3 to eclipse 4.

IMG_4413

 

There were also examples on Maven Tycho, SWTBot UI testing. Simon bragged about fixing issues on the dark theme of Eclipse, which I adore, so now it's even better.

IMG_4414

Pretty funny, I had to pick Simon from the airport, so I had to have a sign:

Photo on 5-12-15 at 00.28

 

Adding another email to a primary gmail address

I use one central email address: stephen@gmail.com (email anonymized). I want to add my work address stephen@fake.company.com to my primary address so I can control it from there.

Receiving

option1: gmail's pop3 importer

Gmail cannot use IMAP to download messages (or I haven't found out how) from other mail servers. It can use POP3:

 

option2: forwarding

What i prefer is to make the mail server at fake.company.com to forward all the messages to stephen@gmail.com. This depends from server to server.

Sending

If you want to pose as stephen@fake.company.com from stephen@gmail.com, you have to use fake.company's email servers, here's how it's done:

On stephen@gmail.com's settings, do:

Gmail -> settings -> accounts -> Add another email address you own

Screen Shot 2015-03-10 at 5.56.12 PM

Then add the info of stephen@fake.company.com:

NOTE: Uncheck "Treat as an alias"

Then add the server info:

Then an email with a code will be sent to stephen@fake.company.com

Give the code to gmail:

Now we're ready, compose a new email and put a different FROM address:

Now when you receive an email to stephen@gmail.com designated for stephen@fake.company.com and you click reply, gmail will automatically put stephen@fake.company.com as the FROM address.

NOTE: People on the other side will never know you use stephen@gmail.com.

[jug.bg] hackaton to fix warnings in openjdk

Today, 17.02.2015, the Bulgarian Java User Group (BGJUG) organized another hackaton. This time we wanted to fix warnings inside the jdk.

Screen Shot 2015-02-17 at 8.33.57 PM

First we did

make clean JAVAC_WARNINGS="-Xlint:all,deprecation,rawtypes,\
unchecked,cast,serial,dep-ann,static,fallthrough,try,varargs,\
empty,finally -Xmaxwarns 10000" DISABLE_WARNINGS="-Xlint:all"\
 LOG=info images

to generate a build.log to find out all the warnings. Then with any text editor one could open jdk9/build/linux-x86_64-normal-server-release/build.log and use these searches (using regular expressions) to find all the warnings:

openjdk/jdk9/corba(.)* warning
openjdk/jdk9/jaxp(.)* warning
openjdk/jdk9/jaxws(.)* warning
openjdk/jdk9/nashorn(.)* warning
(Substitute with your username)
The result was:
359 corba
100 jaxp
500 jaxws
0 nashorn
Initially Mitya proposed nashorn, but all of them were already fixed. Then Ivan and Nayden settled on jaxp. Because we all dislike corba.
Joe Darcy has a blog post on different warning types and how to fix them. We split the warnings into different types:
rawtypes 43
unchecked 14
serial 32
cast 10
dep-ann 1

Note: Dep-ann is to add the @Deprecated annotation.

We fixed the last three types and created a patch: http://bgjug.sty.bz/bgjug/~bgjug/fix-warnings-jaxp-part1/webrev.00/, because the unchecked and the rawtypes are a bit tricky as they involve changing public APIs.

We then tried to solve as much of the latter as possible and then created a second patch: http://bgjug.sty.bz/bgjug/~bgjug/fix-warnings-jaxp-full/webrev.00/

 

barbadan.hit.bg

barbadan.hit.bg беше сайт с няколко книги за мотоциклетна езда преведени на български. Когато стана ясно, че ще затварят hit.bg и безплатно хостнатнатите там страници, реших да спася цялото творчество и копирах сайта, за да се запази като знание.

Теми:
>Ефективни приоми на уличната езда.
>Кейт Код.
>Снимки.
>Спирачни_накладки_и_дискове_за_мотоциклети.
>ПТП.
>Техника на спортната езда.

Адрес: https://mihail.stoynov.com/barbadan.hit.bg/

Не знам какви са правата на съответните книги/статии. Ако все пак нарушавам нечии, моля да пише.

Sublime Text 3 with Javatar

So we in the Bulgarian Java User Group wanted to build Valhalla, and no IDE (Eclipse, Intellij Idea) supports it. We needed some simple text editor with some java support. And Sublime Text 3 (with Javatar) is the one we chose.

Sublime is a fancy editor written in C and Python. Javatar is a plugin that adds some Java support.

Installing Sublime Text 3 beta is straight forward. Installing Javatar is:

[openjdk@localhost valhalla]$ cd ~/.config/sublime-text-3/Packages/
[openjdk@localhost Packages]$ git clone git://github.com/spywhere/Javatar.git

Setting up the correct java is: Ctrl+Shift+P --> "javatar" --> Javatar Settings - Default

Then change the javac and java locations:

Creating projects is a bit uneasy - create new project is actually called "Project -> Save as".

And then we can run some code (fist compile, then run):

[jug.bg] Valhalla hackaton (29.01.2015)

Today we had a second bgjug hackaton for the month. Its topic was Valhalla.

Project Valhalla will probably be part of Java 10 (expected 2018). Among other things it allows using primitives as generic arguments.

Here's how you can build Valhalla yourself.

Here's a virtual machine with valhalla if you're lazy (virtual box).

This is the valhalla presentation by Ivan. And this is the video of the talk (in Bulgarian).

IMG_3676

Here are some of the code we ran:

Ivan created a simple ArrayList

public class SpecialArrayList {
	private static int INITIAL_SIZE = 10;
 
	private T[] elements = null;
	private int length = 0;
 
	public SpecialArrayList() {
		elements = new T[INITIAL_SIZE];
	}
 
	public T get(int position) {
		if(position &gt;= length) {
			throw new ArrayIndexOutOfBoundsException();
		}
 
		return elements[position];
	}
 
	public void add(T element) {
		// Check whether array is full
		elements[length] = element;
		length++;
	}
}
public class Main {
	public static void main(String[] args) {
		SpecialArrayList intList = new SpecialArrayList&lt;&gt;();
		intList.add(1);intList.add(2);intList.add(3);intList.add(4);
		System.out.println(intList.get(2));
 
		SpecialArrayList stringList = new SpecialArrayList&lt;&gt;();
		stringList.add("1");stringList.add("2");stringList.add("3");stringList.add("4");
		System.out.println(stringList.get(3));
	}
}

Nayden tested a bit of crazy code - which is supposed to fail (IA impl = new IAImpl();):

public class B  {
   protected T t;
   protected T[] ts;
   public B(){}
 
   public B(T t){
     this.t = t;
     this.ts = new T[100];
   //  System.out.println(this.t.getClass());
   }
 
   public T[] getTs(){
     return this.ts;
   }
 
   public T getT(){
     return this.t;
   }
 
   public static void main(String[] args){
       B b = new B&lt;&gt;(100);
       System.out.println(b.getT());
 
       System.out.println(b.getClass());
       System.out.println((new B("dada")).getClass());
       System.out.println(c.getClass());
 
       IAImpl ludnica = new IAImpl();
       ludnica.setT(100);
       System.out.println(ludnica.getT() instanceof Object);
 
       IABase base = new IAChild();
       base.setT("dada");
       System.out.println(base.getT());
       System.out.println(base.getClass());
 
       IA impl = new IAImpl();
 
       impl.setT("dada");
       System.out.println(impl.getT());
       System.out.println(impl.getClass());
   }
}
 
 
interface IA{
 public T getT();
 public void setT(T t);
}
 
 
class IABase{
 private T t;
 public T getT(){
   return this.t;
 }
 public void setT(T t){
   this.t = t;
 }
}
 
class IAChild extends IABase {
 
}
 
class IAImpl implements IA {
 private Object t;
 public Object getT(){
   return this.t;
 }
 public void setT(Object t){
   this.t = t;
 }
}

Building OpenJDK 9 on a OSX (or any linux)

This is a tiny tutorial on how to build your own copy of OpenJDK 9 from the current sources.

Contents

Preparation
├─Install a package system
├─Install ccache
└─Command Line Tools
Download OpenJDK 9
Build OpenJDK 9
JTREG
├─JTREG: The variables
└─Running tests
webrev

Preparation

Install a package system

Install brew or macports. I prefer brew. Both are package systems for OS X.

Install ccache

ccache is a compiler cache - speeds up the build.

$ brew install ccache

Command Line Tools

We need them so we have a C compiler and other tools.

Install Xcode Command Line tools ( you don't need the whole Xcode, only the command line tools)

Download OpenJDK 9

Get the sources, in the console type:

$ mkdir jkd9
$ cd jdk9
$ hg clone http://hg.openjdk.java.net/jdk9/dev jdk9.hg

Takes 10-20 secs. This downloads basically a couple of scripts that we will execute to get the actual sources.

Now we execute the script we downloaded:

$ cd jdk9.hg
$ chmod u+x get_source.sh
$ ./get_source.sh

The last command can can take 10-20 minutes depending on the connection speed.

Build OpenJDK 9

$ chmod u+x configure
$ ./configure
$ make clean images

The second command took a bit less than 20 minutes. The first command is fast.

The result: we have this created:  build/macosx-x86_64-normal-server-release/images/jdk/ - this is the built OpenJDK 9 - SUCCESS.

JTREG

jtreg is a "testing harness" (whatever that means) made specially for OpenJDK. We need it to run the tests written for the OpenJDK

Download from https://adopt-openjdk.ci.cloudbees.com/view/OpenJDK/job/jtreg/ (not the Snapshot version, the other one).

unzip in jdk9, so we have jdk9/jtreg.

JTREG: The variables

The official instructions suggest we edit ~/.bashrc. I don't like changing global (for your user) settings, so we can put these settings in jdk9/.bashrc

$ nano .bashrc

Add the following lines:

export SOURCE_CODE=/Users/steve/jdk9/
export JTREG_INSTALL=$SOURCE_CODE/jtreg/
export JT_HOME=$JTREG_INSTALL
export JTREG_HOME=$JTREG_INSTALL
export JPRT_JTREG_HOME=${JT_HOME}
export JPRT_JAVA_HOME=${PRODUCT_HOME}
export JTREG_TIMEOUT_FACTOR=5
export PRODUCT_HOME=$SOURCE_CODE/jdk9.hg/build/macosx-x86_64-normal-server-release/images/jdk
export PATH=$PATH:$PRODUCT_HOME/bin:$JT_HOME/linux/bin/

NOTE: Change /Users/steve/jdk9/ with your folder on the top line.
NOTE: Check the correctness of PRODUCT_HOME too.

To execute this file, do:

$ source .bashrc

Running tests

$ cd jdk9.hg/test
$ make jdk_util

Webrev

Webrev crawls over your changes to generate a set of web-based views of the differences in your code. The different views allow reviewers to easily look at your proposed changes, selecting the appropriate difference format based on the type of file, the type of change, and their own preferences.

webrev.ksh is a 70kb kshell script. Pretty weird.

Go to jdk9.hg and:

jdk9.hg# wget http://hg.openjdk.java.net/code-tools/webrev/raw-file/tip/webrev.ksh
jdk9.hg# chmod u+x webrev.ksh

To prepare a webrev, make some changes. For example in the jaxp folder. Then we commit locally in the mercurial repo.

jdk9.hg# cd jaxp
jaxp# hg commit -m "BGJUG: Fix compiler warnings in jaxp repository"
jaxp# ../webrev.ksh

It will prepare a webrev/ dir and webrev.zip. The folder is then uploaded somewhere and sent to the appropriate mail list inside openjdk. Example:
http://bgjug.sty.bz/bgjug/~bgjug/fix-warnings-jaxp-part1/webrev.00/

Note: execution times come are measured on a pretty recent Macbook Air.

Source: https://java.net/projects/adoptopenjdk/pages/AdoptOpenJDKBuildInstructions