Tuesday, February 20, 2018

private methods on Interface


  1.   Private methods can be used on interface from java 9.
  2.   This will help in
    1.     Avoiding code duplication.
    2.     Ensuring code re-usability.
    3.     Improving code readability.
         There is a possibility of writing common code on more than one default methods, which leads to code duplication. Introduction of private methods will avoid this code duplication.

Example:  On java 8 - Default methods with duplication code.

In the below example, we can see common code is used on both the default methods M1 and M2.

public interface intra {
default void m1() {
    //Business code for M1
    // common code
}

default void m2() {
    //Business code for M2
    //common code
}
}

Example:  From Java 9 - Default methods with Private method.

In the below example, Common code is extracted and added as a private method which can be called by default methods.

public interface intra {

default void m1() {
    //Business code for M1
     Common ();
}

default void m2() {
      //Business code for M2
      Common ();
}

private void common () {
            //Common code
            }
}

Friday, May 29, 2015

Cannot change version of project facet Dynamic Web Module to 2.5

  • Deselect the Dynamic Web Module in your project facets. Right click the Project -> preferences -> Project Facets
  • Then run Maven -> Update Project again.

Monday, May 18, 2015

Forgotten PostgreSQL Windows password

I have used net user postgres postgres to reset the password for my database but instead of a success message I am getting "System error 5 has occurred. Access is denied."
You've reset (or tried to reset) the service account password. PostgreSQL won't run as Administrator for security reasons and the installer generally sets it up with a "postgres" user account in PostgreSQL 9.1 and older1. On Windows you can't start a service as a user without saving the password of the user in the registry, so that's what the installer does.
If you change the password for the Windows user account postgres, the PostgreSQL service can no longer start. So don't do that, you'll have to fix the service configuration to store the updated password.
Thankfully I think another mistake prevented you from doing that. It looks like you're probably running your command prompt without using "Run as Administrator" on an unprivileged Windows user account or a machine with UAC, so it isn't running with the access permissions required to change the password for the postgres user.
Before you try to change that password, make sure it's really what you want to do. What's the problem you're trying to solve here? Are you attempting to install a database update or something else that's asking for the password for the postgres Windows user?
Most likely you're just trying to log in to the database. For that, you use the (unfortunately completely unrelated) password stored in the database its self. Since you've lost/forgotten it you'll have to reset it:
  • Find your pg_hba.conf, usually in C:\Program Files\PostgreSQL\9.1\data\pg_hba.conf
  • If necessary, set the permissions on it so that you can modify it; your user account might not be able to do so until you use the security tab in the properties dialog to give yourself that right by using an admin override. Alternately, find notepad / notepad++ in your start menu, right click, choose "Run as administrator", then use File->Open to open pg_hba.conf that way.
  • Edit it to set the "host" line for user "postgres" on host "127.0.0.1/32" to "trust". You can add the line if it isn't there; just insert:
    host all postgres 127.0.0.1/32 trust
    before any other lines. (You can ignore comments, lines beginning with #).
  • Restart the PostgreSQL service from the Services control panel (start->run->services.msc)
  • connect using psql or PgAdmin-III or whatever you prefer
  • ALTER USER postgres PASSWORD 'postgres'
  • remove the line you added to pg_hba.conf or change it back
  • restart PostgreSQL again.

Thursday, May 7, 2015

How to Create VirtualHost in Tomcat 7/8

Source : http://tecadmin.net/create-virtualhost-in-tomcat/

Why VirtualHost ?

Virtual Hosting provides us to host multiple domains (websites) on single server. It is an concept of resource sharing between multiple hosting account. The best use of Virtual hosting is shared hosting servers, where multiple users can host multiple websites on single server.

Setup Details:

We have created a Linux server with ip 192.168.1.100 for Tomcat hosting services only. Soinstall Tomcat 8 and configured to run on port 80. After than we have deployed two java web applications on tomcat using Tomcat Admin panel. Now both applications are running on following urls
http://192.168.1.100/myapp
http://192.168.1.100/myapp2
Now we want to run both web applications on main domains ( example.com & mydomain.org ). So that end users can access web application by using main domain name.

Create Virtual Hosts:

To create virtual hosts in Tomcat, first navigate to Tomcat installation directory and edit config/server.xml file in favorite editor. Add following host entries in configuration file.
 
<Host name="example.com"  appBase="webapps" unpackWARs="true" autoDeploy="true">
 www.example.com
 
 example_access_log
" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> /opt/tomcat8/webapps/myapp" debug="0" reloadable="true"/> </Host> <Host name="mydomain.org" appBase="webapps" unpackWARs="true" autoDeploy="true"> www.mydomain.org mydomain_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> /opt/tomcat8/webapps/myapp2" debug="0" reloadable="true"/> </Host>

Restart Tomcat Service

After adding virtualhost in Tomcat, we need to restart Tomcat service. Use tomcat init service to restart it or if you don’t have init service for tomcat, execute following commands from tomcat installation directory.
# ./bin/shutdown.sh
# ./bin/startup.sh

Tuesday, May 5, 2015

For killing a process linux


For killing a process that is associated with multiple processes, you need to kill that by using process id associated with that process.

To get the process id of that java process run

ps -A |grep java
output of this command will give the list of java processes running on your system. Note down Process ID (PID) of that process whom you want to kill and run

kill -9 PID

Friday, April 11, 2014

Generate Java objects from DTD or XML

On  Jdk installed machine use this following Command  to generate java classes.

1.    Create a folder.  (say Test is the folder).

2.    Copy the DTD file in the location.

3.    On command prompt use the command

xjc -dtd -d com –p [Package structure] [Dtd file name with .dtd extention]

Java classes will be created inside test folder with the specified package structure.

UNIX Commands



Read write access
sudo chmod 777 /foldername/foldername


to provide access to jboss server
sudo chown jboss.jboss /foldername/foldername

To check how many instance is running 
ps -ef | grep "java"


Delete all files

sudo rm -r ./*

Copy files from one folder to another

sudo cp -r /data/das/ /usr/local/jboss5/server/all-with-hornetq/


ln -s /webroot/home/httpd/test.com/index.php /home/vivek/index.php

private methods on Interface

  Private methods can be used on interface from java 9.   This will help in     Avoiding code duplication.     Ensuring code re-usab...