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){
         this.student=student;
         this.rollno=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>(Student.java:8)
at sai.Student.<init>(Student.java:8).........

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.in);
        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;
                }
                else
                {
                    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.data.jpa.repository.config.EnableJpaRepositories;
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;

@Configuration
@EnableJpaRepositories("com.test.user.repository")
@EnableTransactionManagement
public class ApplicationConfig {

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
        dataSource.setUrl("xxx");
        dataSource.setUsername("xxx");
        dataSource.setPassword("xxx");
        return dataSource;
    }


    @Bean
    public EntityManagerFactory entityManagerFactory() {
        HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
        vendorAdapter.setGenerateDdl(true);
        LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
        factory.setJpaVendorAdapter(vendorAdapter);
        factory.setPackagesToScan("com.test.user.repository.domain");
        factory.setDataSource(dataSource());
        factory.afterPropertiesSet();
        return factory.getObject();
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        JpaTransactionManager txManager = new JpaTransactionManager();
        txManager.setEntityManagerFactory(entityManagerFactory());
        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:

[LOG_PATTERN] ABC1025...
[LOG_PATTERN] (XYZ-COULD-BE-A-MSG
[LOG_PATTERN] -WITH-DASH
[LOG_PATTERN] -SEPARATED-TEXT)
[LOG_PATTERN] ABC1026...
[LOG_PATTERN] (DEF-ANOTHER-SAME-KIND
[LOG_PATTERN] -OF-DASH-SEPARATED-TEXT)
[LOG_PATTERN] ABC1027...
...

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",
                "Subtraction",
                JOptionPane.QUESTION_MESSAGE);

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

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

        //Data Sum
        int sum = data1 - data2;

        //Output
        JOptionPane.showMessageDialog(null,  sum, "The Answer",         
JOptionPane.INFORMATION_MESSAGE);

    }
}

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("${my.propery.name}") syntax along with @PropertySource("classpath:my.properties").

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

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

@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}

and:

@Bean
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 RationalTest.java
RationalTest.java:1: error: package org.junit does not exist
import static org.junit.Assert.assertEquals;
                       ^
RationalTest.java:1: error: static import only from classes and interfaces
import static org.junit.Assert.assertEquals;
^
RationalTest.java:3: error: package org.junit does not exist
import org.junit.Test;
                ^
RationalTest.java:4: error: package org.junit does not exist
import org.junit.Before;
            ^

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

<project>


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

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

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


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

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

  <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="*Test.java"/>
        </fileset>
      </batchtest>
      <formatter type="brief" usefile="false" />
    </junit>
  </target>

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

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

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

</project>

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         Main.java       Rational.java      RationalTest.java~
build.gradle  index.html  LICENSE     Main.java~      Rational.java~     README.md
build.xml     javadoc     Main.class  Rational.class  RationalTest.java  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.