Posts

Introduction to OSGi(Java Modular)

Image
OSGi Alliance is the governing body of this stranded and it was started at 1999. their initial goal was create open stranded for network devices. Based on this idea this specification introduced for Java also. Eclipse was first in Java. they introduced OSGi based Eclipse IDE at 2004 June.
OSGi is way to define dynamic module in java. There are main three OSGi container implemented for Java,such as Apache Felix, Eclipse Equinox and Knopflefish.
Why OSGi? Because OSGi provide ability to divided application in to multiple module and those module easy to manage with other dependencies. other than that is very easy to install, update,stop and delete module without stop engine(Ex: Tomcat web application container). We can have multiple version of implementation with effecting to other references.
There are main 3 layers in web based Java framework(Presentation , Business layer and  DAO layer). There we can divide it into three OSGi based module. then we can very easily fixed bug in one laye…

Advanced Java questions -4

Image
A program which will accept three sentences (one sentence per line) and print the words having Initial Caps within the sentences. Below is an example.

Here is an example. If the below three sentences are given to the program as input,

This is a Program
Coding test of Initial Caps
the program Will Test You

Then, the output would look like:

This
Program
Coding
Initial
Caps
Will
Test
You

Solution:
Pattern p = Pattern.compile("^[A-Z]");


Advanced Java questions -3

Where 1999 is the year and 5 is the numeric sequence of the month (corresponding to June). The program should display the day on which June 28, 1999 fell, and in this case the output will be MONDAY.

The output should be displayed in uppercase letters.

Suppose the following INPUT sequence is given to the program:

1999-5
1998-6

Then the output should be:

MONDAY
TUESDAY

Solution:


import java.text.DateFormatSymbols; import java.util.Calendar; import java.util.Scanner; public class Solution { /** * @param args */ public static void main(String[] args) { boolean condition = false; do { Scanner scanner = new Scanner(System.in); String value = scanner.nextLine(); condition = value.equalsIgnoreCase("exit"); if(!condition && value.contains("-")){ calculate(value); } System.out.println("Count is: " + condition); } while (!condition); } private static void calculate(String value) { final String[] input = value.split(…

Advanced java questions -2

Write a program that prints the numbers between 258 and 393 (both inclusive) which do not end with 5. The program should print the output so as to have one value per line. The output would therefore follow the below format:


value1
value2
value3
.
..
.
so on
Solution:
public class Solution2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int start = 258; int end = 393; for (int i = start; i < end; i++) { if(i%10 !=5){ System.out.println(i); } } } }

Advanced Java questions

A program which will accept a single pair of strings separated by a comma; the program should calculate the sum of ASCII values of the characters of each string. The program should then subtract the sum of the ASCII values of the second string from the sum of the ASCII values of the first string.

Suppose the following input is given to the program:

123ABC,456DEF

Then the sum of the ASCII values of the characters in '123ABC' is 348 and in '456DEF' it is 366. The Difference between these numbers is 348 – 366 = -18
The corresponding output to be printed by the program is:

-18

Solution:
import java.util.Scanner; public class Solution { /** * @param args */ public static void main(String[] args) { boolean condition = false; do { Scanner scanner = new Scanner(System.in); String value = scanner.nextLine(); condition = value.equalsIgnoreCase("exit"); if(!condition && value.contains(",")){ calculate(value); } } while …

Google App Engine DataNucleus “does not seem to have been enhanced” Issue

Image
I got DataNucleus exception while developing a Google App Engine based Web Application for one of my office clients. Here is the error message.

javax.jdo.JDOUserException: Persistent class "Class com.xxxxx.xxxxx.domain.XXXXXUser does not seem to have been enhanced. You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class. at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:375) at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:252) NestedThrowablesStackTrace:
Persistent class "Class com.xxxxx.xxxxx.domain.XXXXXUser does not seem to have been enhanced. You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it.Please check the specification of the MetaData for this class. org.datanucleus.store.exceptions…

How to parse toString date value to Date object

I have some issue with toString date value parse to Date object. here is my solution for that.

try { Date cutterntTime = new Date(); String dateStringValue = cutterntTime.toString(); //String dateStringValue = Thu May 05 11:26:49 IST 2011; DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); Date date = (Date)formatter.parse(dateStringValue); System.out.println("Date Value is : " + date); } catch (ParseException e){ System.out.println("Exception :"+e); }