Reason behind getting stackOverflowError exception?

I know this is wrong but I want to know the reason why I am getting

 class Student{

     String student;
     int rollno;

     Student stud=new Student("s",20);//(1st object)Thrown exception because of this line

     Student(String student,int rollno){

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Student stud=new Student("R",101);


Exception in thread "main" java.lang.StackOverflowError
at sai.Student.<init>(
at sai.Student.<init>(

When I am creating only one object(i.e 1st object) I wont get this error But when I create two object I am getting this error .

Calling boolean methods

My overall goal with this program is to validate that a user inputted string is in fact a valid number. I am required to use at least two methods, including the main method. I have read many posts related to calling user-defined methods from within the main method, but I am however struggling to make mine work. When declaring my isAValidNumber method, I keep getting the error “illegal start of expression”. How can I declare this method so that I can call it from within the main method and contentiously run it until the user enters an invalid invalid number?

import java.util.Scanner;

public class IsAValidNumber
    public static void main(String[] args)
        //prompt user for a valid number
        Scanner consoleInput = new Scanner(;
        System.out.print("nEnter a valid integer or floating point value: n");

        String input = consoleInput.nextLine(); 

        /* while(isAValidNumber = true)
        } */

        public static isAValidNumber(String input)
            for(int j=0;j<input.length();j++)
                if(input.matches("\d+(\.\d*)?|\.\d+") == true)
                    boolean isAValidNumber = true;
                    boolean isAValidNumber = false;

Load persistence config file in spring data jpa

I am using spring data jpa, and have defined the datasource, entity manager, and hibernate config in a Java class instead of xml. Here is my class –
My question is do I have to create a bean definition for this config class? How does it get loaded at Application startup? We are not using Spring boot, there is no main method etc. Please help.

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

public class ApplicationConfig {

    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        return dataSource;

    public EntityManagerFactory entityManagerFactory() {
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        return factory.getObject();

    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager txManager = new JpaTransactionManager();
        return txManager;

Spring Integration TCP Grouping by Tokens

I’m listening an IP with a specific port and print out the messages. The sample message is like the following:


How could I group each message by specifying a start and end token for example. So that, when it is started with ABC, then it would combine/group the next message until it found the next ABC. Thanks

How to remove all non-numerical characters from a string input in java?

I am trying to create a basic calculator program and I want to remove all non-numerical characters from the string input. (I am a java newbie). This is my
current code:

package calculator;
import javax.swing.JOptionPane;
public class sub {

    public static void main(String[] args) {

        //Text & Input Box #1
        String input = JOptionPane.showInputDialog(null,
                "Input the first number",

        //Input Box #2
        String input1 = JOptionPane.showInputDialog(null,
                "Input the second number",

        //Data Collection
        int data1 = Integer.parseInt(input);
        int data2 = Integer.parseInt(input1);

        //Data Sum
        int sum = data1 - data2;

        JOptionPane.showMessageDialog(null,  sum, "The Answer",         


Reading properties values from Resource and from System Variables in Spring 4

I’m trying to configure my Spring 4 application to be able to read properties values using the @Value annotation.
I need to be able to read values from .properties files as well as from system properties.

For reading from .properties file I am using @Value("${}") syntax along with @PropertySource("").

For reading from system properties I am using the @Value("#{systemProperties['myVariableName']}") syntax.

In my class, which is the main application configuration file I have both:

public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();


public static PropertyPlaceholderConfigurer propertyConfigurer() {
return new PropertyPlaceholderConfigurer();

When both Configurers are specified, I experience an issue in which sometimes the values are resolved and sometimes not (and I get a Could not resolve placeholder exception).

When only PropertyPlaceholderConfigurer is configured, I am able to read only from .properties file.

When only PropertySourcesPlaceholderConfigurer is configured, I am able to read only from system properties.

What is the best configuration for reading from both resources?

Compilation Error of My Test File: org.junit does not exist

I have seen this answer been solved for other circumstances but this is lab for my class and I do not have a pom.xml file to include dependencies but I have a build.xml file. The errors I get are:

[brianhumphreys@csil-13 lab01-BrianHumphreys-HenryJeng]$ javac error: package org.junit does not exist
import static org.junit.Assert.assertEquals;
                       ^ error: static import only from classes and interfaces
import static org.junit.Assert.assertEquals;
^ error: package org.junit does not exist
import org.junit.Test;
                ^ error: package org.junit does not exist
import org.junit.Before;

The Contents of my build.xml file are as follows:


  <path id="project.class.path">
    <pathelement location="build"/>
    <pathelement location="lib/junit-4.8.2.jar"/>

  <target name="compile" description="compile the code">
    <mkdir dir="build" />
    <javac srcdir="src"
           debug="true" >
      <classpath refid="project.class.path" />

  <target name="clean" description="clean up the project">
      <fileset dir="build" includes="*.class"/>
      <fileset dir="build" includes="*.jar"/>

  <target name="run" description="run the main">
    <java classname="Rational" classpath="build"/>

  <target name="jar" depends="compile" description="create a jar file">
    <jar destfile="build/rational.jar">
      <fileset dir="build" includes="*.class"/>
        <attribute name="Main-Class" value="Rational"/>

  <target name="test" depends="compile" description="run JUnit tests">
    <junit haltonerror="no" haltonfailure="no">
      <classpath refid="project.class.path" />
      <batchtest fork="yes">
        <fileset dir="src">
          <include name="*"/>
      <formatter type="brief" usefile="false" />

  <property name="javadoc_absolute_path" location="javadoc"/>

  <target name="javadoc" depends="compile" description="generate javadoc">
      <fileset dir="javadoc" />
    <javadoc destdir="javadoc">
      <fileset dir="src" >
        <include name="*.java"/>
      <classpath refid="project.class.path" />
      <link href="" />
      javadoc written to file://${javadoc_absolute_path}/index.html                              

  <target name="jar" depends="compile">
    <jar destfile="build/rational.jar">
      <fileset dir="." includes="*.class"/>
        <attribute name="Main-Class" value="Rational"/>


These are the contents of my directory(subdirectory ‘lib’ includes junit-4.8.2.jar):

[brianhumphreys@csil-13 lab01-BrianHumphreys-HenryJeng]$ ls
build         build.xml~  lib
build.gradle  index.html  LICENSE
build.xml     javadoc     Main.class  Rational.class  src 

I am lost as to why it will not compile. Please help. Let me know if there is anymore information that I should include.