Tuesday, August 25, 2015

Execute java Code in Ubuntu

One thing about Java is cross platform where it able to run at any machine with Java environment installed wile for VB and C# that mainly run in window environment. So now I here to record how to execute java code in Ubuntu.

Open up your terminal in Ubuntu.

Make sure your machine is install with Java. To check the version of Java you may use below command.

java -version

If there is no respond of Java version from the show version command, you may need to install Java.
Below is the command install Java version 1.8. Execute below command line by line, It take few minutes to download the Java and it based on your network connection.

sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
Once finish install, verify it by using java -version. So you may get to know the version of Java installed in the machine.

Create a java code in any directory that is accessible with read write access. Below is Hello world sample code for testing purpose and save the file name as myFileName.java while the Class name is TestJavaProgram.

//First Java Program class TestJavaProgram
{ 
    public static void main (String[] args)  
   {  
       System.out.println ("Hello, world."); 
   } 
}  
So after save the java file in a directory, using terminal dir command navigate to the particular folder/directory. After in the level of the directory, using below code to compile the java.

javac myFileName.java
After the compilation, you need to run the java code by using below command and make sure the class name is correct.

java TestJavaProgram
Alternative way some people may make the java code as a jar file. You may execute the jar file by using below command.

java -jar yourjarfilename.jar


Wednesday, August 12, 2015

SQL Query by Date and Get 4 Nearest Record

Today here to play around with the SQL script and I try to revise my SQL script.

When come to date calculation, there is a build in function to calculate the date different. The function name is datediff(). How to use this function as it simple and you have to pass 2 value into this function and it will return the difference of day between the 2 value.

Example:
Value A: 2015-08-20; Value B: 2015-08-12 and the different of these2 day are 8

SELECT datediff('2015-08-20 00:00:00','2015-08-12') as 'dayto'

For today date there is a build in function too which is CURDATE()

In SQL if you want to get specific numbers of result return by SQL server you may using LIMITthen follow by the number of record.

Example to return 10 record.
Limit 10

Well the complete SQL script to get the top 4 nearest evetStartDate date from today as follow.

SELECT datediff(`evetStartDate`,CURDATE()) as 'dayto', `eventguid`,`eventName`,`evetStartDate`
FROM event
WHERE `evetStartDate` > NOW()
ORDER BY `evetStartDate` ASC
LIMIT 4"



Friday, August 7, 2015

Using Nano Editor to set static IP

Previously i have use to using GUI to change the IP address on Ubuntu, but now come to server and there is no GUI, so I have force to learn using command to change the IP address.

Here is the guide to set static IP address on  Linux Ubuntu  by using the Nano text editor.

sudo nano /etc/network/interfaces

so do not miss out the s in interface word, else the Linux unable to recognize your command. Due to changing system setting, it may prompt you the password for root. Once you entered the password and you may see the something as below.

auto lo eth0
iface lo inet loopback
iface eth0 inet dynamic
eth0 is the network card name, as you have more than 1 network card, it may have few name. So make sure the name of the interface. you may verify your interface card by using the ifconfig to show the list of interface and interface details.

so you may manually to change the file by using the nano editor. Below is my example and please take note that the iface eth0 inet dynamic  change to static.

auto lo eth0
iface lo inet loopback
iface eth0 inet static
 address 192.168.1.101
 netmask 255.255.255.0
 gateway 192.168.1.1

after you complete change, press Ctrl + x to save the change. The editor will promt you

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?

Type Y to accept the change then press enter to save the file.

After you save the config file, you may restart the interface to make change. Type below command to down the interface

sudo ifdown eth0

and

sudo ifup eth0

to up the interface.

LAMP Installation guide.

Finally finsh the development for the project. Now is the time to host the application on server. Due to cost saving concern, the application will host on a Linux node in VM. So LAMP is the choice we have decide to deploy and host the application. LAMP basically is the acronym of Linux, Apache, MySQL and PHP.

As previously I am using the XAMPP to start the PHP project development on Window. So now I have to deploy all the file into this new Linux node.

It is quite difficult to me as I have little knowledge on Linux Ubuntu and all have to use command to perform the installation. After go through the installation, I found that it quite simple but 1 thing is you have to know the command and mind your typed text else the command unable to execute.

Before begin the installation, make sure that you have connect to internet.

So start with install Apache. Below is the command to install the Apache. You may just copy paste the command.

sudo apt-get install apache2

after install Apache, no need to rush to start the service. Let continue with install Mysql with command below.

sudo apt-get install mysql-server

And now install the PHP.

sudo apt-get install php5 libapache2-mod-php5

Well, we have finish the installation for Apache, MySQL and PHP. So now we going to start the service.

sudo /etc/init.d/apache2 restart

after start the Apache service, you may use a browser to test the service. You may just type http://ipaddressofthehost/ on web browser to test it. It will respond a success page with it works!


And now the LAMP is success installed.


Thursday, August 6, 2015

Window 7 Sharing issues with XP

For a network that with different OS version might have facing this issues as the older version of Windows unable to access the share folder on Window 7. The error message as below. For this error message we can know that it related to permission issues. So you might play around with the access right.


While you already make sure your access right is correct and the folder is accessible by Windows 7. This may be the window registry issues.

Solution:

1. Go the the particular Window 7 machine that sharing the folder. Locate to the following registry key and change it's value to 1. You may refer to this link for further study.

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\LargeSystemCache

2. Locate this next key and change it to 3, this is just that "Server" service (or part of it) setting

HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\Size

Restart the Window 7 and now the problem should be solve.