Monday, September 14, 2015

What are new changes in java 8 for Date API?

Java8 Introduced new classes , easy to use

java.time.LocalDate;
java.time.LocalTime;
java.time.LocalDateTime;

Use the above Date Time classes with below arguments for specific need
java.time.Month;
java.time.ZoneId;
java.time.LocalTime;
java.time.ZoneOffset;

java.time.Instant; Obtains the current instant from the system clock.
java.time.Duration;  Obtains a Duration representing a number of standard 24 hour days.


Sunday, September 13, 2015

Problem with commiting new code to SVN ?

You have created a new project and added to version control, but at while commiting to SVN is  pointed to different SVN URL, which is not actual svn url


To solve such problem, detele the .svn hidden folder.

This solves the problem and point you to right SVN URL after svn synch


Saturday, September 12, 2015

What are hibernate.hbm2ddl.auto values?

validate | update | create | create-drop
  • validate- existing schema
  • update- only update your schema once created
  • create- create schema every time
hibernate.hbm2ddl.auto Automatically validates or exports schema
DDL to the database when the
SessionFactory is created. With create-drop,
the database schema will be dropped
when the SessionFactory is closed explicitly.
e.g. validate | update | create | createdrop

An internal error occurred during: "reload maven project". java.lang.NullPointerException

My Eclipse  failed to update some maven deps. and not responding, killed the  eclipse.exe procees

I have got this error when launching eclipse after the crash

An internal error occurred during: "reload maven project". java.lang.NullPointerException

 remove this file .metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi

problem solved!!

Friday, September 11, 2015

An internal error occurred during: "Starting Tomcat v8.0 Server at localhost". Could not initialize class java.net.SocksSocketImpl

Got this error at server start up:

An internal error occurred during: "Starting Tomcat v8.0 Server at localhost".
Could not initialize class java.net.SocksSocketImpl

Possible reason : issue with default HTTP port 8080

Solution : Change the HTTP port to some other value like 8087, and restart the server

This might solve the problem

Example Server configuration file :

F:\Eclipse-wks\Servers\Tomcat v8.0 Server at localhost-config\server.xml (if you are using Eclipse IDE )

F:\WebAppServers\apache-tomcat-8.0.24\conf\server.xml

   <Connector connectionTimeout="20000" port="8087" protocol="HTTP/1.1" redirectPort="8443"/>

Thursday, September 10, 2015

Tuesday, September 8, 2015

How to create and apply patch file in svn?

Creating a patch :
Suppose you have modified the project code and want to know the lines you changed.
You can export all you code changes to a file and  reviewed with you manager

Use svn diff command to export changes into a file.
Eg: <projectDir>$svn diff > myPatch.diff

Applying a patch :
Similarly you want to import others code changes in the form of patch file.
command to import / apply all changes is
<projectDir>$svn patch <patchfile> <projectDir>
Eg: svn patch xyz_changes.diff  /home/xxx/workspace/projectX

You can do these tasks in GUI mode as well in eclipse.
Right click on project:
Team --> Create Patch
Team --> Apply Patch

Monday, September 7, 2015

How to work with rpm packages installation, upgrade and roll-back, delete?



  • The following rpm command installs Mysql client package.

             # rpm -ivh  MySQL-client-3.23.57-1.i386.rpm

  • You can use rpm command to query all the packages installed in your system.

             # rpm -qa
             # rpm -qa | grep MySQL-client


  • Query a Particular RPM Package using rpm -q

              # rpm -q MySQL-client


  • Information about Installed RPM Package using rpm -qi

             # rpm -qi MySQL-client


  • If you have an RPM file that you would like to install, but want to know more information about it before installing, you can do the following:

                # rpm -qip MySQL-client-3.23.57-1.i386.rpm


  • List all the Files in a Package using rpm -qlp

               $ rpm -qlp MySQL-client-3.23.57-1.i386.rpm


  • Uninstalling a RPM Package using rpm -e

                 # rpm -ev MySQL-client


  • Upgrading a RPM Package using rpm -Uvh

                  # rpm -Uvh MySQL-client-3.23.57-1.i386.rpm


  • Downgrade or rollback rpm to old version

                # rpm -Uvh --oldpackage "~/MySQL-client-3.23.57-1.i386.rpm"



How to know TCP/IP port listening or free in UNIX / Linux?

Use netstat command in linux / unix and grep for a port number

>netstat -anp | grep <port_number>

How to export and import mysql dump ?

To take export / backup of mysql DB, use following command

>mysqldump -u <db_username> -p<db_password> -h<db_host> db_name  > db_name_backup.sql

To take export / backup of table in mysql DB, use following command
 
>mysqldump -u <db_username> -p<db_password> -h<db_host> table_name > table_name_backup.sql

Similarly To import or dump the data into mysql database use following command
 
>mysql -u <db_username> -p<db_password> -h<db_host> db_name < ~/db_name_backup.sql (ensure db_name_backup.sql present in home directory)

How to kill Some Java Process without Input PID?

To extract the PID use awk command and send the argument to xargs command.

ex: To kill activemq process use the below command

ps -ef | grep $USER | grep java | grep activemq | awk '{print $2}' | xargs kill -9

Saturday, September 5, 2015

How to analyze how much time a program spends in each part of the code?

    To do this analysis use -prof option, like below.

F:\JavaSamples>java -prof Test
Hello World!
Dumping CPU usage in old prof format ... done.

F:\JavaSamples>dir

After running java application, The JVM dumps the each part of code / api calls into a seperate file named  java.prof

java.prof:
count callee caller time
1375 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V java.lang.AbstractStringBuilder.append(C)Ljava/lang/AbstractStringBuilder; 0
1306 java.lang.String.charAt(I)C java.lang.String$CaseInsensitiveComparator.compare(Ljava/lang/String;Ljava/lang/String;)I 15
759 java.io.WinNTFileSystem.isSlash(C)Z java.io.WinNTFileSystem.normalize(Ljava/lang/String;II)Ljava/lang/String; 0
759 java.lang.String.charAt(I)C java.io.WinNTFileSystem.normalize(Ljava/lang/String;II)Ljava/lang/String; 0
755 java.lang.CharacterDataLatin1.getProperties(I)I java.lang.CharacterDataLatin1.toLowerCase(I)I 0
755 java.lang.CharacterDataLatin1.toLowerCase(I)I java.lang.Character.toLowerCase(I)I 0
..

Friday, September 4, 2015

How to compile and run java code in EditPlus?

Run EditPlus,

Navigate to Tools --> Configure User Tools -->

1. Change GroupName to javac
2. Add Tool like below
and also for java


finally use the user tools from tool bar
That all..

How to start learning java?

   To start learning java, you need JDK (Java Development Kit) and some text editor like EditPlus or power full IDE like Eclipse

Download the JDK from Oracle site and install it.

Set Environment variable PATH and CLASSPATH

Write a sample java program with the text editor and compile with javac compiler
and run the class with java tool / JVM

MainClass.java :
public class MainClass {
    public static void main(String[] args) {
        System.out.println("Java");
    }
}
>javac MainClass.java
>java MainClass

You may get compile time or runtime error if you not properly set Environment variables


PATH must point to bin directory of JDK like C:\Program Files\Java\jdk1.8.0_45\bin

CLASSPATH must point to lib directory of JDK / JRE like C:\Program Files\Java\jdk1.8.0_45\jre\lib or C:\Program Files\Java\jre1.8.0_51\lib

choose JDK's JRE for better compatibility