Sunday, May 25

Install LAMP (Linux Apache Mysql PHP) in ubuntu

 

Step 1 : Install Apache2

sudo apt-get update
sudo apt-get install apache2
To check the installation,try the following address in the browser
http://localhost:80/ 

Step 2 : Install Mysql

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
Enter the mysql root password,when promted during installation To do simple auto configuration of mysql follow these commands

sudo mysql_install_db
sudo /usr/bin/mysql_secure_installation
Then enter the mysql root password entered earlier
press 'n' to not change the current password

Remove anonymous users? [Y/n] y 
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] n
Reload privilege tables now? [Y/n] y
For Production machines, press 'y' for option 'Remove test database and access to it?'

Step 3 : Install PHP

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
Then after installation, open below file and edit with sudo privelege.
etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>

          DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

</IfModule>
To install other php modules or extension, first find it
apt-cache search php5-
Then install that required module
sudo apt-get install <module_name>
The default server public folder is in the below path
/var/www/

Step 4 : Restart Apache Web Server

sudo service apache2 restart 

Friday, April 11

String is immutable in java


Yes, it true that string is immutable in java which means that the String object doesn't change.
But that can't be true because we have seen many occasions in the program where the String variable is changed.

Yes its true, but we have our understanding of String a bit wrong here. Actually unlike C program, in Java, String is not a primitive variable but a special Class. So in our code  actually we are creating a String object for new character sequence.

For more understanding go to this link String can't be immutable in java

Friday, April 4

Neo4j Community Build Error


To build the neo4j community,  I am following  the steps as done in Travis CI link here.

But i am getting the error below
[ERROR] Failed to execute goal org.neo4j.build.plugins:license-maven-plugin:3:check (check-licenses) on project neo4j-kernel: Some files do not have the expected license header -> [Help 1] 
To solve this "Build the community/license-check submodule first." as suggested in SO link here.

But still i am getting the same error.

Please check whether my steps taken are correct or not.


/$ mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.6.0_30, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-60-generic", arch: "amd64", family: "unix"



/$ cd ~/Workspace/neo4jdev/community-experiments/licensecheck-config/
~/Workspace/neo4jdev/community-experiments/licensecheck-config$ mvn install

[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.239s
[INFO] Finished at: Fri Apr 04 15:06:07 IST 2014
[INFO] Final Memory: 14M/148M



~/Workspace/neo4jdev/community-experiments/licensecheck-config$ cd ..
~/Workspace/neo4jdev/community-experiments$ MAVEN_OPTS="-Xss2m -Xmx1G"
~/Workspace/neo4jdev/community-experiments$ mvn install -DskipTests

[INFO] --- license-maven-plugin:3:check (check-licenses) @ neo4j-kernel ---
[INFO] Checking licenses...

[INFO] [INFO] Missing header in: /~/Workspace/neo4jdev/community-experiments/kernel/src/test/java/org/neo4j/unsafe/batchinsert/BatchInserterImplTest.java
[INFO] Missing header in: /~/Workspace/neo4jdev/community-experiments/kernel/src/test/java/org/neo4j/kernel/RaceBetweenCommitAndGetMoreRelationshipsIT.java
[INFO] Missing header in: /~/Workspace/neo4jdev/community-experiments/kernel/src/main/java/org/neo4j/tooling/GlobalGraphOperations.java

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Neo4j - Graph Database Kernel ..................... FAILURE [1.719s]
[INFO] Neo4j - JMX support ............................... SKIPPED
[INFO] Neo4j - Usage Data Collection ..................... SKIPPED
[INFO] Neo4j - Graphviz generation ....................... SKIPPED
[INFO] Neo4j - Lucene Index .............................. SKIPPED
[INFO] Neo4j - Graph Algorithms .......................... SKIPPED
[INFO] Neo4j - Graph Matching ............................ SKIPPED
[INFO] Neo4j - Cypher .................................... SKIPPED
[INFO] Neo4j Community ................................... SKIPPED
[INFO] Neo4j Community ................................... SKIPPED
[INFO] Neo4j - Generic shell ............................. SKIPPED
[INFO] Neo4j Examples .................................... SKIPPED
[INFO] Neo4j Server API .................................. SKIPPED
[INFO] Neo4j Server ...................................... SKIPPED
[INFO] Neo4j Server Examples ............................. SKIPPED
[INFO] Licensing configuration ........................... SKIPPED
[INFO] Neo4j Community Build ............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.427s
[INFO] Finished at: Fri Apr 04 15:08:26 IST 2014
[INFO] Final Memory: 14M/153M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.neo4j.build.plugins:license-maven-plugin:3:check (check-licenses) on project neo4j-kernel: Some files do not have the expected license header -> [Help 1]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


Resolved

The license check is failing may because of some repository url may have changed,  which we have no control of so its better to skip the license check.

The following command will help to skip license check and build sucessfully.
$ mvn install -DskipTests -Dlicensing.skip

In linux os, it build successfully but in windows there were some issues in project "neo4j-browser" so i skipped that project to successfully  build in windows too.

Below is the error in windows in project neo4j-browser
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Licensing configuration ........................... SUCCESS [  2.796 s]
[INFO] Neo4j - Primitive Collections ..................... SUCCESS [  0.794 s]
[INFO] Neo4j - Graph Database Kernel ..................... SUCCESS [01:34 min]
[INFO] Neo4j - JMX support ............................... SUCCESS [  1.362 s]
[INFO] Neo4j - Usage Data Collection ..................... SUCCESS [  3.880 s]
[INFO] Neo4j - Monitor Logging ........................... SUCCESS [  1.120 s]
[INFO] Neo4j - Graphviz generation ....................... SUCCESS [  1.592 s]
[INFO] Neo4j - Lucene Index .............................. SUCCESS [  4.390 s]
[INFO] Neo4j - Graph Algorithms .......................... SUCCESS [  2.070 s]
[INFO] Neo4j - Graph Matching ............................ SUCCESS [  1.230 s]
[INFO] Neo4j Community Cypher Build ...................... SUCCESS [ 11.080 s]
[INFO] Neo4j - Cypher Commons ............................ SUCCESS [ 50.804 s]
[INFO] Neo4j - Cypher Compiler 2.1 ....................... SUCCESS [03:45 min]
[INFO] Neo4j - Cypher .................................... SUCCESS [ 37.636 s]
[INFO] Neo4j Community ................................... SUCCESS [  1.420 s]
[INFO] Neo4j GraphGist ................................... SUCCESS [  6.780 s]
[INFO] Neo4j - Cypher Documentation ...................... SUCCESS [ 36.070 s]
[INFO] Neo4j Community ................................... SUCCESS [  0.750 s]
[INFO] Neo4j - Generic shell ............................. SUCCESS [  3.550 s]
[INFO] Neo4j Examples .................................... SUCCESS [  1.790 s]
[INFO] Neo4j Server API .................................. SUCCESS [  1.920 s]
[INFO] Neo4j Browser ..................................... FAILURE [  0.430 s]
[INFO] Neo4j Server ...................................... SKIPPED
[INFO] Neo4j - Server Plugin Tests ....................... SKIPPED
[INFO] Neo4j Server Examples ............................. SKIPPED
[INFO] Neo4j Community Build ............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 08:15 min
[INFO] Finished at: 2014-04-11T17:08:08+05:30
[INFO] Final Memory: 54M/302M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (default) on project neo4j-browser: An An
t BuildException has occured: unless=cmdsuccess -> [Help 1]

Now if you want to continue by skipping the project "Neo4j Browser", follow the below command
$ mvn install -DskipTests -Dlicensing.skip -e -rf :neo4j-server


Atlas, successfully build
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Neo4j Server ...................................... SUCCESS [01:55 min]
[INFO] Neo4j - Server Plugin Tests ....................... SUCCESS [  3.482 s]
[INFO] Neo4j Server Examples ............................. SUCCESS [  1.880 s]
[INFO] Neo4j Community Build ............................. SUCCESS [  0.440 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:05 min
[INFO] Finished at: 2014-04-11T17:20:07+05:30
[INFO] Final Memory: 46M/227M
[INFO] ------------------------------------------------------------------------


Saturday, February 16

Difference between public, private, protected and default



 

  Access Modifier Visibility


Modifier
Class
Package
Subclass
Everywhere
public
Yes
Yes
Yes
Yes
protected
Yes
Yes
Yes
No
default
Yes
Yes
No
No
private
Yes
No
No
No

public  - Members are visible in same class, same package, sub classes and in other classes.

protected - Members are visible in same class, same package, sub classes but not in other classes.

default - Members are visible in same class, same package but not in sub classes and other classes.

private - Members are visible only in same class but not in same package, sub classes and other classes.

  

  Access Modifier Level Applicability


Modifier
Member Field
Member Method
Nested Class
Top Level Class
public
Yes
Yes
Yes
Yes
default
Yes
Yes
Yes
Yes
private
Yes
Yes
Yes
No
protected
Yes
Yes
Yes
No
 
 public, default  - These modifiers can be applied to members of the class and also to the top class. 

 private, protected  - These modifiers can be applied to member of a class only but not to the top class.



Simple Inheritance

parent.java
package r1;
public class parent
{
        int x;
      
       public parent()
       {
              x=10;
       }
             
       public static void main(String args[])
       {
             
              parent p = new parent();
              System.out.println("parent main x="+p.x);
       }
}

Output
parent main x=10


sub1.java
package r1;
public class sub1 extends parent  // a subclass of parent
{
       sub1()
       {
              x=20;
       }
      
       public static void main(String args[])
       {
              sub1 s1 = new sub1();
              System.out.println("In r1 pckg, sub1 class, main fn, sub1.x = "+s1.x);           
       }     
}

Output
In r1 pckg, sub1 class, main fn, sub1.x = 20


Examples of  Access Modifiers

Following are the errors that occurs if access modifiers are not used properly:


private - The field parent.x is not visible

parent.java
package r1;
public class parent
{
        private int x;      // private access modifier
}

sub1.java
package r1;  // same package as the parent
public class sub1 extends parent  // a subclass of parent
{
       sub1()
       {
              x=20;
       }
      
       public static void main(String args[])
       {
              sub1 s1 = new sub1();
              System.out.println("In r1 pckg, sub1 class, main fn, sub1.x = "+s1.x);           
       }     
}
Output
The field parent.x is not visible

Because: sub1.java is not the same class where x is declared.



default - The field parent.x is not visible

parent.java
package r1;
public class parent
{
        int x;  // no access modifier is default
}

sub2.java
// sub2 class is not part of r1 package
import r1.parent;   // so  its imported
public class sub2 extends parent  // a subclass of parent
{
       sub2()
       {
              x=30;
       }
      
       public static void main(String args[])
       {
              sub2 s2 = new sub2();
              System.out.println("In no pckg, sub2 class, main fn, sub2.x = "+s2.x);
       }     
}

Output
The field parent.x is not visible

Because: sub2.java is not in the same package of parent where x is declared.



 protected - The field parent.x is not visible

parent.java
package r1;
public class parent
{
        protected int x;  // protected access modifier
}

some1.java
// some1 class is not part of r1 package
import r1.parent;
public class some1 // not a subclass of parent
{            
       public static void main(String args[])
       {
          parent p = new parent();
          System.out.println("In no pckg, some1 class, main fn, parent.x = "+p.x);
       }     
}

Output
The field parent.x is not visible

Because: some1.java is neither in the same package nor in subclass of parent  where x is declared.