Java – Pass by Value or Pass by Reference?

Plain and simple…

… Java is always pass by value.

However, it’s also true to say that a reference is actually a value – a memory address.  So more accurately Java is pass by value for primitives and pass by an object’s reference, which is a value.

It’s quite interesting that even in Oracle’s Java Programmer certification course it’s written that a primitive is passed by value and an object is passed by reference.  In the case of an object that ‘reference’ is actually a primitive that contains the memory address of where the object structure is held.  From a logical point of view the phrase ‘objects are pass by reference’ actually makes sense, but how would you describe what happens to primitives on a logical level?  Oracle’s wording is actually cause of the confusion.  There is an attempt at distinguishing how primitives are handled i.e primitives are passed by value, compared to objects, but it would much clearer to describe it as is.

From another point of view, this is a fantastic interview question – albeit a very simple one. It does prove if a candidate just remembered some text, or actually thought about it and is able to go into a little bit more detail.

Is Test cricket on it’s way out?

With Brendon McCullum’s retirement came news of his signing a $1.6m IPL deal. At the age of 34 – considered to be an age where batman are at their peak – he has chosen the mad dash of 20/20 over the longer form of cricket.  Good for him.  This is by no means a whinge or a moan against one of the best players NZ has ever produced both in captaincy and batting skills.  He has lifted NZ to higher levels which would probably not happen without him.  But what is the message being sent to world cricket?  Get in young, play for your national team, do well, get noticed, sign a big IPL deal, play a bit and retire. There is just too much International cricket.  Players cannot rest and are away from their homes for most of the year, which has to be a terrible thing for some.  A split of specific teams is already happening where most countries already have a one captain for the Tests team and another captain for the ODI and 20/20 teams.  Only a handful of players will play all formats.  Those are usually the ones that end up getting the big contracts.

I find it painful to hear that players are choosing IPL over Test cricket.  From a financial and career perspective I totally understand and I’m glad that cricket players can make big bucks, but where does that leave Test cricket?  National cricket boards cannot fork out the kind of money privately sponsred teams can.  Often, Test cricket is played in front of empty stands.  On the other hand every IPL game seems to be played at a stadium that is filled to the brim with fans.  I question the validity of these fans because they seem to be very excited all the time – it seems choreographed.

Lets face it – Test Cricket is dying. ODI cricket is still hanging on, where I thought that it would have died a few years after 20/20 came into the fold.  Test cricket is under attack from all fronts – empty stadiums, players not making themselves available for Tests over 20/20 and pointless 2-match series.  So can anything be done to fix this?

 Test match world cup

Martin Crowe has been vocal about having a two year Test cricket championship.  The idea presented was to have 8 teams competing against each other over the duration of the championship.  Each match up would in fact be a series of 3 Test Matches.  At the end of the second year a winner would be announced.  The interesting aspect of this approach would be that the wooden spoon team would be replaced by the winner of the ‘second decision’ championship. This would give countries like Ireland, Holland, Zimbabwe, Afghanistan, Hong Kong, Malaysia or Canada a chance to play against the top team for two years.  While the team that dropped out of the top tier would have to play the minnows and win the second tier championship to reenter the top tier.  Could that help to generate more interest in Test Cricket?

1 or 3 match Test series

Although the Test Match World Cup does look like an interesting proposal, it does comes across as a rather radical approach to increasing interest in Test Cricket.  Another solution, which would be far less radical would be to have a either a 1 or a 3 Test match on every tour.  Apart from the Ashes, which should stay as a 5 match series because of its long history. All other tours should consist of either 1 match or a 3 match series.  The one Test Match series would help emerging countries get expose to top-level cricket, while the top teams could battle it out over a series that has a much large chance of producing a result.  After all what is the point of a 2 or 4 match series?

This approach might only just increase interest a little bit.  It would be difficult to quantify how much interested has been gained by implementing a 1 or 3 match Test series through out all the Test series in the world.

Three separate business entities

Why not separate the three levels of cricket into totally separate ‘businesses’? International cricket is a business – ignoring this is quite similar to denying that the sky is blue on a cloudless day.  So why not have every cricket board spin of a 20/20, ODI and Test Match ‘decisions’ and let them organize the game starting from school level through to International level.  There would be bitter competition between the entities, but it would allow players to choose the type of cricket that suited them. Also it would cater more specifically to different fan bases.

The grounds

Bring back the grass bank, barbecues and allow people to bring their own food.  The last game I watched live was the final game for Stephen Fleming vs England in Napier. The only beer we could drink was Tui at 5 bucks for a small plastic cup.  The food at the venue was completely disgusting and expensive.   So you have to pay an entry fee, a parking fee (if you come by car), be only allowed to buy over priced and poor quality food and drinks.  I think I will stay home, stream the cricket for free and order a decent pizza.

Allowing people to bring in their own food and drinks does cause problems in cases where they bring in glass bottles etc.  Ever heard of vodka water melons?  let people bring their own beer, a BBQ, sausages, onions etc.  Spend a bit more cash on security (rather then spending lots of cash of crap quality catering) and ensure people know and understand that they are given a freedom, but if they cross the line they will get kicked out.

Remove ODIs

Yet another radical approach to generating more interest in Test cricket.  Removing ODIs would reduce the amount of cricket played thus making it simpler for fans to choose which format to follow and more importantly to attend. Players would also choose which format they want to specialize in as we have seen players do really well in one format while perfmoring poorly in another.

Reduce the length of Test cricket and introduce Night Tests

A Night test under lights has already taken place in Australia.  This is an interesting concept because it obviously allows people to come and watch the late afternoon and evening sessions.  Is this a potential answer? It does sounds like a decent solution.  Taking it a bit further why not adjust the minimum overs to be bowled in a day to say 60 or 70 and get the days play underway at 4pm?  Perhaps a combination of both is the best answer.  If a match starts on the weekend than it’s a day Test Match, while if the match is due to take place during the week then it would be a night Test Match.  The players might argue (and I think I’ve already read an article on this topic somewhere) that the conditions during the day vary so much so during the night that night Tests should have their own statistics.  Potentially some players will specialize in night games over day game. Presumably those that feast on carrots might be better candidates for the night games with their better eyes.

Re-organize the cricket calendar

It might be enough to simply organize the world cricket calendar in a such a way that series do not overlap giving the players a chance to play in high-income 20/20 tournaments between playing for the national team.  As soon as you have one successful competition others spring up. Now almost every country has it’s variant of the IPL.  If all these tournaments would be placed in the calendar then there would be little time left for other forms of cricket.

Privatize Test cricket

This post is getting outta control.  How about throwing a bit of privatization at Test cricket so that in can compete with 20/20?  If you could get all the top players to play Test cricket then would the fans turn out in force to watch them play?  Potentially.  Privatizing Test cricket would most probably inject more money into it along with a stronger drive by owners/investors to increase the amount of eye balls glued to the screen for advertising purposes.

WordPress on t2.nano

The t2.nano instance type does not come as well configured at the t2.micro, so if you want to run WordPress on one of these instances you will need to a bit more leg work.  Assuming you have chosen Amazon Linux you should be able to get everything up and running with the commands below.

Install PHP, MySql and httpd

sudo yum groupinstall -y "PHP Support" (be careful, this will only install php 5.3, which is a tad old)
sudo yum install php-mysql
sudo yum install httpd
sudo yum install php55-mysqlnd (this is needed with newer versions of php)

Delete the welcome page as it will give you trouble

sudo rm /etc/httpd/conf.d/welcome

Install WordPress

Follow the WordPress installation guide to install WordPress. If re-using a DB create a new schema in MySQL or create a new server.  The WordPress installation guide will tell you where to stick the credentials.

Install SSL:

sudo yum install mod_ssl

Run a SSL test to see what rating your server will get.  You will probably get a B because Apache by default allows SSL v3, which is dead and RC4, which is weak.  Run the test anyhow to see where your configration is at before hardening it.

https://www.ssllabs.com/ssltest/

Update ssl.config

sudo vi /etc/httpd/conf.d/ssl.conf

Remove SSL3 because it’s broken

#remove SSL v3
SSLProtocol all -SSLv2 -SSLv3

Turn on Cipher order

#turn on cipher order
SSLHonorCipherOrder on

Adjust the available ciphers (note, when copying and pasting into vi you need to get rid of the invalid space and new line chars)

#remove RC4 from cipher list 
SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+ SHA256 EECDH+aRSA EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4 RC4+RSA"

And finally provide the location of the keys to be used during SSL

#location to certificate file
SSLCertificateFile /etc/pki/tls/certs/<certificate file name>.crt
SSLCertificateKeyFile /etc/pki/tls/private/<prive key file name>.key
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crti

At this point it would pay to move the localhost.key and .cert files to a backup folder or delete them all together. Update Apache Config to redirect all traffic to HTTPS

sudo vi /etc/httpd/conf/httpd.conf

Modify the Virtual Host to redirect everything to https:

<VirtualHost *:80>
    Redirect permanent / https://<your domain>
</VirtualHost>

Add the following to the SSL Virtual Host

sudo vi /etc/httpd/conf.d/ssl.conf

Modify the HTTPS Virtual host so that it always forces SSL

<VirtualHost _default_:443>
   #force HTTPS usage.
   Header always set Strict-Transport-Security "max-age=31536000; includeSubdomains"

Restart Apache

sudo service httpd restart

Re-run the test

https://www.ssllabs.com/ssltest/

Some useful configurations

If you are missing the .htaccess file then you have to tell WordPress to download the updates explicitly, otherwise it will try to get you to update via FTP.

#to force direct update, over ftp
 define( 'FS_METHOD', 'direct' );
#increase memory for php
 define( 'WP_MEMORY_LIMIT', '64M' );

If you want image cropping (if you are seeing something like this: “There has been an error cropping your image”) then you will need something like this:

sudo yum install php<php version>-gd
#eg yum install php55-gd
sudo amazon-linux-extras install php7.2

SSH to EC2 killing consoles

sudo vi /etc/ssh/ssh_config #under Host * ServerAliveInterval 240

Make sure HTTPD starts in reboot

sudo chkconfig httpd on

Change the host name

vi /etc/sysconfig/network

https://gist.github.com/sl-digital/9838411#file-amazon-linux-ami-php55-L23

add to .htaccess Options All -Indexes    this is to prevent the display of WP directories

https://www.danielmorell.com/guides/htaccess-seo/redirects/https-www-and-trailing-slash

// disable WordPress’s Canonical URL Redirect feature
remove_filter(‘template_redirect’,’redirect_canonical’);

Overclocking, processor lifespan and CPU trends

Yay! Love the smell of that new piece of hardware you just bought? That feeling when peeling off the tight plastic.  Plugging it in. Seeing lights, fans what ever else do something. Why not let loose on the voltage controls and see what the new device can really do.   CPU over clocking has become a breeze these days and so has cooling, which you will need a lot of when overclocking.  Many people are concerned about performance degradation over time when the CPU is juiced up on extra voltage.  Fair point, but looking at the trend of  CPU performance over say the last 15 years it’s crystal clear that a 7-8 year CPU cannot keep up with heavy computing such as games, rendering and anything else that needs CPU cycles.  So what will, say, an i7- 5820K have to say for it self by the time the year 2022 ticks over?

The general trend in  processor evolution is that we have given up on trying to go mega quick and instead are concentrating on go wide by way of cores and efficient by way of the manufacturing processes used.  This trend has and will continue for the foreseeable future because it is driven by  demand of ever more powerful and efficient mobile devices.

Software is getting better at utilizing cores more effectively (and Microsoft has jumped on board by announcing pricing plans per core rather then per socket).   Not all software needs multi-core performance, instead it relies on single core performance to get its work done.  Most games work like this as do lots of desktop programs.  In the server world software such as databases, web or application servers are much more optimized to utilize multi-core  processors.  Visualization is where I think multi-core processor really come into their own by even supporting multiple virtual machines.

Pocket processor

Soon the time will come where we will carry our processors in our pockets.