Installing Java-1.8 in Ubuntu 14.04

Here is the procedure on how to install java-1.8 version in ubuntu 14.04.

Initially check the java version that is available in your computer

  • java -version

Create an empty folder so that we can install java 1.8

  • sudo mkdir /opt/java && cd /opt/java

Now lets download java-1.8 version

 

  • wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz"

Extract the tar file

  • tar -zxvf jdk-8u45-linux-x64.tar.gz

Now lets update the alternatives so that system will point to the location where java-1.8 is installed

  • cd jdk1.8.0_45/
  • sudo update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.0_45/bin/java 100

Note: The 100 in above command represents the priority no.  which can set manually

  • sudo update-alternatives --config java

    Please enter the selection no. which is having the path as  “/opt/java/jdk1.8.0_45/bin/java” and press enter.

  • sudo update-alternatives –install /usr/bin/javac javac /opt/java/jdk1.8.0_45/bin/javac 100
  • sudo update-alternatives –config javac
  • sudo update-alternatives –install /usr/bin/jar jar /opt/java/jdk1.8.0_45/bin/jar 100
  • sudo update-alternatives –config jar

Now lets try to set up the environment variables

  • sudo nano /etc/environment
  • In this file change the Java home path
    JAVA_HOME=/opt/java/jdk1.8.0_45/

     

  • Add this line as new line in the file
    JRE_HOME=/opt/java/jdk1.8.0._45/jre
  • update the path variable .In the path variable paste the following value instead of /usr/bin/java-7.....
     /opt/java/jdk1.8.0_45/bin:/opt/java/jdk1.8.0_45/jre/bin
  • So now your path variable will look like this
    PATH=”/opt/java/jdk1.8.0_45/bin:/opt/java/jdk1.8.0_45/jre/bin
    :/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games”
  • Restart the ennvironment file

source /etc/environment

 

Now let’s check whether the java is updated or not

  • java -version

java version “1.8.0_71”
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)

Python selenium tool to crawl any website.

Requirements :

Ubuntu (any latest version will be fine)

FIrst we will try to install selenium tool :-

  • sudo apt-get install python-pip
  • sudo pip install selenium
  • sudo pip install django==”1.6″

 

 Sample Program

# coding=utf-8
import time
from selenium import webdriver
import os

driver = webdriver.Firefox()

driver.get(‘https://translate.google.co.in/?hl=en&tab=TT’)

hText=”सुधीर Bhayya”
driver.find_element_by_id(“source”).send_keys(hText.decode(“utf-8”))
time.sleep(5)
driver.find_element_by_id(“gt-submit”).click()
time.sleep(5) #waits till the translation gets done

translatedText = driver.find_element_by_id(“result_box”).text

print translatedText

driver.close()

Explanation:

 driver = webdriver.Firefox()
This statement will open a firefox  browser in your machine

driver.get(‘https://translate.google.co.in/?hl=en&tab=TT’)

opens translate.google.com in your browser.

driver.find_element_by_id(“source”).send_keys(hText.decode(“utf-8”))

enter some hindi language text in the box to convert it to english

driver.find_element_by_id(“gt-submit”).click()

clicks translate button to get the translate to english

 

 

 

 

 

Mysql Basics

MySQL Tutorial
Here are some instructions for mysql beginners:-

Installation of Mysql :-

1) sudo apt-get install mysql-server

Connecting to Mysql:-

Open a terminal and type

1) mysql -u root -p (for localhost i.e in same machine)

2) mysql -u root -p -h ##your-IP## (to coonnect mysql in different machines)

Some Basic Commands:-

1) create database Sample {for creating a database named ‘Sample’}

2) use Sample {for using the database ‘Sample’}

3) create table Employee (id integer,name varchar(50),location varchar(50)) ;
{creating a table ‘Employee’ with 3 columns ‘id’ –> integer type,’name’ –> String,’location’ –> String}

4) insert into Employee values(101,’john’,’Delhi’); {Inserts data in to Employee table }

5) select * from Employee; {Displays all the rows from Employee}

6) update Employee set id=’102′ where id =’101′; {Updates data in Employee from 101 to 102}

7) delete from Employee where id =’102′; {deletes a row in Employee where id is 102}

8) drop table Employee {deletes table Employee}

9) drop database Sample {deletes database Sample}