JDK 9 and JShell

Intro

I recently got to know about this official Java REPL (Read-Eval-Print-Loop) or JShell project. It is named as Kulla and you can visit here to see the project’s home. This is pretty much same like the Python’s IDLE (If you have used it before) and a great way to exercise your code in real time. Also the good thing is that this project will be available as a part of JDK9 among with some other cool features.

Anyhow I managed to get it run on own and have tried few exercises too. Here, take a look

How do I get it to run

I haven’t tried this on Windows, only on POSIX based systems (Linux).  But I believe the precompiled jar will work on Windows. You can give it a go and see.

Easy way

If you want to try out REPL right away there’s this precompiled Jar that you can use . What you’ll need is

Once these are in place you just need to set the JAVA_HOME to your / path / to / JDK 9. Then execute the following -jar command:-

$ java -jar kulla.jar

You will be entered in to the JShell.

Hard way

NOTE: The whole build process can take up to 20-30 minutes or more, so brace yourself.

  • Make sure you have set the JAVA_HOME
  • You also need Mercurial. If you are on Ubuntu just give sudo apt-get install mercurial
  • The the follow these commands to get kulla-dev branch built
    • hg clone http://hg.openjdk.java.net/kulla/dev kulla-dev
    • cd kulla-dev
    • sh get_sources.sh
    • bash configure –with-boot-jdk=/path/to/jdk1.9
    • make clean images
    • make install  (optional)

OK, kulla-dev branch is now built, hopefully without any errors. Now lets see how we can build and run the REPL. I’m extracting these information from official README under Kulla dev branch.

Download JLINE2 from Maven, and set the environment variable JLINE2LIB to point to the downloaded jar file.

Building REPL:-

  • cd langtools/repl
  • bash ./scripts/compile.sh

Running:-

  • bash ./scripts/run.sh

If everything goes fine you’ll be entered to the JShell without any issues.

Features

I will add a summary of features that you’ll find useful when using the REPL.

  1.  REPL has networking support. Yes you can work with java.net
  2.  Semicolone is optional giving you a flexibility like most of REPL’s out there
  3.  It has some useful help commands that you can use to improve your productivity. /help list those commands
  4. Checked exceptions are not valid here. Like in normal Java environment you will not be forced to handle the checked exceptions. REPL will be handling it in the background
  5. Expressions will also work out of the box here. Arithmetic, String manipulations, method calls .etc

Here I found a good tutorial that might be useful. It has some basic to intermediate exercises that you can follow go get familiar with the JShell/REPL

Linux | Fancy little “dialog” utility

Using Linux’s sophisticated “dialog” utility to display CPU core temperature

installation

sudo apt-get install dialog

sudo apt-get install lm-sensors

Here the lm-sensors for detecting temperature (see here for configuration details: http://lm-sensors.org/wiki/iwizard/Detection)

Finally the script goes as

#!/bin/bash

temp1=$(sensors | grep “Core 0:” | cut -c1-24)
temp2=$(sensors | grep “Core 1:” | cut -c1-24)

dialog –title “System temp info” –msgbox “$temp1 $temp2” 10 22

dialog –clear
exit 0

Using minimal advantage of lm-sensors, it’s just displaying main core temperatures.

Screenshot - 11232013 - 10:52:34 PM

openSUSE 13.1 – almost here [updated]

It’s been a while since the openSUSE 13.1 beta is released. And now it’s just a matter of time until the official release. [RC1 is coming on Thursday]

So as a SUSE user I’m putting my blog’s background picture to a nice art work made by the community. You can see the gecko face in between the posts, well it didn’t work as I expected but still it look pretty sleek.

You can check out other promotion fun sparks from here:-
https://news.opensuse.org/2013/10/07/help-promote-opensuse-13-1/

Check out the suggested goals for openSUSE 13.1
https://en.opensuse.org/openSUSE:Goals_13.1

Have fun..!

Update: It’s out..! But I didn’t have much time on checking it out. Hoping to do a run through, let’s see how it goes this time.

Amazon WS EC2 – connect via SSH RSA

So you own an up and running Amazon EC2 instance. And you want it to access via hassle free way. This guided post will describe on how you can do it with few steps.

Note: Just for the convenience I’m referring some steps from this blog here – http://thekeesh.com/2011/05/setting-up-user-accounts-password-authentication-and-ssh-keys-on-a-new-ec2-instance/

OK before I start assume you have an up and running EC2 instance. If so grab the public DNS from your AWS management console

EC2 Management Console 2013-09-15 15-54-28
It will be probably something like

ec2-#############.compute-1.amazonaws.com

Once that is acquired I again assume you have already made your Key-pair and saved it while you are in the process of creating a new instance

EC2 Management Console 2013-09-15 16-01-07

Once that is also in place go to your terminal and CD to the location you saved your Key [your-key-pair.pem] and try to do SSH

$ ssh -i your-key-pair.pem ubuntu@ec2-#############.compute-1.amazonaws.com

[the default user will be ubuntu for Amazon Machine Images (AMIs).]

Now you should be inside the AMS terminal

aws-terminal

Ok now you have to do is add your self up as a new user and give the root privileges (sudoers). Simply follow execute the following commands on to the AWS terminal

Adding yourself as a user:

$ adduser yourself

granting privileges

$ sudo visudo

find the line root  ALL=(ALL:ALL) ALL and the line yourself ALL=(ALL) ALL under it.

Then enable password authentication via (I used the nano editor)

$ sudo nano /etc/ssh/sshd_config
PasswordAuthentication no to PasswordAuthentication yes

Afterward reload the ssh configuration

$ sudo /etc/init.d/ssh reload

Ok now logout from the current session and log back as yourself

$ ssh yourself@ec2-#############.compute-1.amazonaws.com

And to make sure everything is working just fine, execute following

$ sudo -v

You will be promted to enter the password you have provided while creating the user(yourself). Enter that and if everything went well you will get no output on terminal.

Now lets remove this troublesome password authentication replacing SSH RSA public key authentication

To do that first you need to create a SSH RSA public key

So logout from the AWS terminal and from your local terminal execute the following command (Just press return for all the steps)

local-host$ ssh-keygen -t rsa

And you will get a similar output as below

Enter file in which to save the key (/home/yourself/.ssh/id_rsa):
Created directory ‘/home/yourself/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yourself/.ssh/id_rsa.
Your public key has been saved in /home/yourself/.ssh/id_rsa.pub.
The key fingerprint is:
58:3a:80:a5:df:17:b0:af:4f:90:07:c5:3c:01:50:c2 yourself@inux-cc6a

Your public key will be stored in /home/yourself/.ssh/

Now what you have to do is add that key to AWS in order to identify yourself as authorize user.

local-host$ scp ~/.ssh/id_rsa.pub yourself@ec2-#############..compute-1.amazonaws.com:/home/yourself

Then again login to the AWS

local-host$ ssh yourself@ec2-#############..compute-1.amazonaws.com:/home/yourself

And place the key file in right place

$ mkdir .ssh
$ mv id_rsa.pub .ssh/authorized_keys
$ chmod 700 .ssh
$ chmod 600 .ssh/authorized_keys

Now you should be able to login without using a password

local-host$ ssh yourself@ec2-#############.compute-1.amazonaws.com

Finally remove the password authentication and root user access

$ sudo vim /etc/ssh/sshd_config

Find the line PasswordAuthentication yes and change it to PasswordAuthentication no.

Also PermitRootLogin yes to PermitRootLogin no

Finally reload the SSH configurations again

$ sudo /etc/init.d/ssh reload

That’s all you need for crating a new user account and allowing authentication via SSH RSA.

If you are still lazy enough to type that long public DNS you can simply assign it to an alias and place it in the ~/.bash_proflle  or ~/.bashrc to make it permanent.

#amazon cloud ssh
alias connect-amazon=’ssh yourself@ec2-#############..compute-1.amazonaws.com’

$ connect-amazon

 

Introduction to Python

Overview

python logo

After a long time I haven’t post any blog entries,Ahhh I was too lazy and kind of busy with my studies,recently I got a chance to look in to a technically enhanced language,which is Python.It’s adoption is now drastically expanding among most of the corporate IT sectors, for example Google.Google’s new innovation,Google wave,it’s server (Pygowave) is entirely developed using Python + the Python web framework called Django.So at this point I’m going to step in to Python and briefly describe how to setup python in various platforms and will perform a small hello world example.

Special qualities of Python language
Platform independent.
Can be use as a scripting language.
Open source.
Easy to use.
Can be easily manipulated with various web freamworks.
Special interaction with the Java platform (Jython).
Moreover it’s really fun.

Lets do this (Installing Python)

So if you want Python installed on your platform and need to play with it you need a special software called Python interceptor which is bundled with the Python installer.You can get the most recent Python installation from http://www.python.org/download.
Visit there and download it.

Windows:
OK, when you visit http://www.python.org/download,you’ll see several different links in there such as Python 2.6.x and Python 3.1.x, click on a windows installer link and you’ll start the downloading process
Note:If you’re running on an AMD machine you need to select appropriate link.After downloading the installation bundle run the file by double-clicking.Follow the installation steps on the Python installation wizard don’t be afraid just select the default settings.OK now you’re done.I will continue with some code examples after explaining how to setup Python on Linux and Unix.

Linux and Unix:
Most Linux and Unix distributors included the Python interceptor.You can give it a try straight away,start the terminal/command prompt and use the command $python,by running this command will start the python interceptor and will out put the following information on to your terminal.
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

if it not you’ll get a command error
python: command not found
(Which means python is not already percent)
I’m not go in to details about how you can install Python on Linux or Unix platforms,you can get the complete guid from here

OK, assume that you have successfully installed Python on your system.Now it’s time to do some coding.Here I’m using Python interceptor on windows because currently I’m on windows,and my Python version is 2.6.

Starting the interceptor(Windows)
Programs ➤ Python 2.6 ➤ IDLE (Python GUI), you should see a window
like above, this is the Python shell inside that the Python interceptor is running.

Lets try a small code “Hello World”,
>>> print "Hello, world!"
Press enter,and the python interceptor will out puts the following.
Hello, world!
>>>

Note:You see on the screen cast I have used a semicolon “;”, but don’t worry it’s not needed it’s optional if you’re a so called Java enthusiastic person you’ll probably use a semicolon,but the Python interceptor simply doesn’t care about the semicolon.

OK,that’s it for now I’m tired.I know this is so little and you want more,Well you’ll find out more exiting things that Python can do in the near future. Keep in touch.