Hello World Android Studio

Hi, After installing Android Studio Let us see how to create our very first program Hello World

Step1 : Welcome to Android Studio 
Hello World Android




 You will see the above screen , Click on first option Start a New Android Studio Project.

Step 2: New Project 
 
Hello World Android


 Give name as your with in application name .I have given it as Hello World on my convenience.
You can also change project location and click next.

Step 3: Form factors

Hello World Android

 In this Step you have to choose the device on which you want to run your app .I have chosen only for tablets and phone .So we have tremendous options in tablet and phone emulators in Android Studio.

Step 4: Choose activity 

Hello World Android Studio
Hello World Android

 You can choose any activity from the options as shown above .If you are beginner I would suggest you to choose  Blank Acitvity  for your first app.

Step 5: Activity Name 


Hello World Android Studio
Hello World Android



Fill the activity name and other things as shown above . As my program is HelloWorld so i have chosen name as Hello Activity .

Step 6: Project opens  


Hello World Android Studio
Hello World Android
Step 7: Code  

A screen of main project will open as shown below with text view as Hello World .


Hello World Android Studio
Hello World Android



As this is our first program need not to go  in depth just run it with Run green button in the top 

Whole structure and code we will learn in next program.



Step 8: Run 

Run this program and this will show you the output on emulator .I am using Nexus 7 as AVD .How to add a AVD in your studio you can see here.


Hello World Android Studio
Hello World Android
If you are facing some errors in running the above program you can refer below as I was also facing many errors so I have drafted them for your help .





Spring MVC Tutorial Hello World

Hi guys ,Today I am going to explain you Spring MVC with a very simple program Hello World in Eclipse IDE .I have explained in tseps the whole procedure If you are facing any problem please write below in comments I ll solve it asap.

Step 1: First you need to Make a Dynamic project in Eclipse. Select file ->Dynamic Web project->Fill Name->Finish.



I gave name as SpringMVCHelloWorld


Step 2: Now you need to add some spring jars to your project lib folder and build path . Please refer to the screenshot below and add the exact version jars otherwise you may face some errors.




Step 3: Now we need to add some more files to the structure .I ll explain the wholw flow at the end ,first let us make the project work .You need

  • JavainhouseController.java
  • Index.jsp
  • WelcomePage.jsp
  • web.xml
  • welcome-servlet.xml
JavainHouseController.java


package com.javainhouse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class JavainhouseController {

@RequestMapping("/javainhouse")
public ModelAndView helloWorld() {

   String message =  "Welcome to Javainhouse";
 

   return new ModelAndView("WelcomePage", "welcomeMessage", message);
}//ModelAndView closed

}

Index.jsp

<html>
<head>
<title>JavainHouse SpringMVC</title>
</head>
<body>

<font size="2px" face="verdana">
  Welcome...
   <a href="javainhouse.html"><br> Click here</a>
</font>

</body>

</html>

WelcomePage.jsp

<html>
<body>
     ${welcomeMessage}
  </font>
</body>

</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
<servlet>
  <servlet-name>welcome</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
     <servlet-name>welcome</servlet-name>
     <url-pattern>/</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
     <welcome-file>Index.jsp</welcome-file>
  </welcome-file-list>

</web-app>

welome-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<context:component-scan base-package="com.javainhouse" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

</beans>


Step 4: The directory structure of all the files should be shown as in the screenshot below:





Step 5: Let us Run the project by right click on Index.jsp->Run on server .You ll see both the screens as below :






Execution :

1. web.xml is the very first file read by the spring .In web.xml ,we have given name of two servelts one is welcome and other is Dispatcher Servlet .For Dispacther Servlet we have given load startup as 1 which means it will be the first servlet loaded by spring .

2. After that servlet name is given as welcome ,now spring ll find a filename as welcome-servlet.xml in whole project and read it.

3. In welcome-spring.xml ,we have given <context:component-scan base-package="com.javainhouse" /> which means that in this base packages the Handler mapper need to look for the particular controller for the request given.

4. Index.jsp ll be the first jsp file which ll be loaded at first and display the output to the user .When user click on Click Here link then Handler mappper will start  looking for the controller for this particular request means with Request mapping as javainhouse.

5.  helloWorld() method will be executed and string message will be set.and Model with name welcomeMessage with value "Welcome to Javainhouse" and view WelcomePage ll be returned to the Dispather Servlet .

6. Now in welome-servlet.xml next thing is view resolver which ll be helping to resolve the directory structure of view returened i.e. WelcomePage . If ll prefix  WelcomePage  with jsp and suffix with .jsp i.e. now we ll find WelcomePage.jsp in folder jsp and this view ll be return to the user as shown.