Menu

Simple Spring project example

Create a implementation class ImplCode.java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import org.springframework.context.ApplicationContext;

import org.springframework.context.support.FileSystemXmlApplicationContext;

public class ImplCode {

 public static void main(String[] args) {

  ApplicationContext appContext=new FileSystemXmlApplicationContext("AppContextBeanFile.xml");

  Fruit fruit=appContext.getBean("fruit", Fruit.class);

  Vegetable veg=(Vegetable) appContext.getBean("veg");

  System.out.println(fruit.whoareyou());

  System.out.println(veg.whoareyou());

 }

}

Create a bean class Vegetable.java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
package rashiddemo;

public class Vegetable {

 public String whoareyou() {

  String intro="I am vegetable!!";

  return intro;

 }

}

Create another bean class Fruit.java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
package rashiddemo;

public class Fruit {

 public String whoareyou() {

  String intro="I am fruit!";

  return intro;

 }

}

Create a AppContextBeanFile.xml and add your bean classes using bean tag.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="fruit" class="rashiddemo.Fruit"></bean>

 <bean id="veg" class="rashiddemo.Vegitable"></bean>

</beans>

OpenJDK 64-Bit Error Not enough space | errno=12

[ERROR] OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000aab00000, 286261248, 0) failed; error='Not enough space' (errno=12)

Solutions

There are multiple ways through which you could fix this issue. Try any of the below step to fix the "Not enough space" error.

1. You can restart the server, this way cache will get cleared and you will get the required space for execution.

2. Increase the space for JVM or heap memory.

Puzzles

Four people need to cross a bridge in 17 minutes in the middle of the night. The bridge can only hold two or less people at any time and they only have one flashlight so they must travel together (or alone). The flashlight can only travel with a person so every time it crosses the bridge it must be carried back. Tom can cross in 1 minute, John can cross in 2 minutes, Sally can cross in 5 minutes, and Connor can cross in 10 minutes. If two people cross together they go as fast as the slower person.

How can they cross the bridge in 17 minutes or less?


Answer: First Tom and John will cross (2 minutes). Then Tom will bring the flashlight back (1 minute). Next Sally and Connor will cross (10 minutes). Then John will bring the flashlight back (2 minutes). Finally John and Tom will cross (2 minutes). 2 + 1 + 10 + 2 + 2 = 17 minutes.