How to run jsp program in eclipse using tomcat server

  • Hi friends today we will see basic example of how to run jsp (java server pages) program using tomcat server in eclipse IDE.
  • For this we need to create dynamic web project in eclipse
  • Lets see how to run jsp program in tomcat server step by step.
  • Print hello world using jsp program


Required software: 



  • After downloading eclipse and tomcat server. open eclipse and add server and select tomcat version and giver downloaded tomcat folder path.

Step 1: Open eclipse and create dynamic web project:

  • Now we need to create dynamic web project for this in eclipse 
  • New => other=> web=> Dynamic web project


how to run jsp program in tomcat server eclipse



Step 2 : Create a dynamic web project

  • Click on next => and give MyFirstJsp as project name.
  • Click on Next=> click next here select generate xml deployment descriptor check box
  • And click on finish.
  • So now project will be created and with default xml file.


  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javae
  4. /web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  5. http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  6.   <display-name>MyFirstJsp</display-name>
  7.   <welcome-file-list>
  8.     <welcome-file>index.html</welcome-file>
  9.     <welcome-file>index.htm</welcome-file>
  10.     <welcome-file>index.jsp</welcome-file>
  11.     <welcome-file>default.html</welcome-file>
  12.     <welcome-file>default.htm</welcome-file>
  13.     <welcome-file>default.jsp</welcome-file>
  14.   </welcome-file-list>
  15. </web-app>

Step 3: Create a JSP page


run jsp on eclipse


  • Right click on web content folder and select new => JSP file => give index.jsp


Step 4 : Edit Jsp page

  • Edit the JSP page and give Page title and in the body section create one paragraph tag and write some text like Hello world.


  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2.     pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or
  4. /TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Welcome</title></head>
  9. <body>
  10. <p>Hello World</p>
  11. </body>
  12. </html>


Step 5: Run dynamic web project using tomcat server

  • So index.jsp is present in welcome file list of web.xml file then whenever server starts it loads welcome file i.e index.jsp
  • We can give any name t our jsp but it should present in web.xml as welcome file
  • <welcome-file>index.htm</welcome-file> . no need of other files which names are created by default we can delete those things.
  • Right click on the project and => run as => run on server=> select tomcat version = >add our project if not added click on finish. 
how to compile jsp program in tomcat

Java interface programming questions

  • We can develop interfaces by using "interface" keyword. 
  • A class will implements all the methods in an interface.
  • By default interface methods are abstract.
  • Lets see some interesting java programming interview questions on interfaces.
  • Interface programming questions in java




Java interface interview programs part 1: interface programming java

Program #1: what will happen if we define normal methods in interface

  1. package interfaceinverviewprograms.instanceofjava;
  2. public interface A{
  3.  
  4. /**
  5. * @java interface  interview programming  questions and answers for freshers and experienced
  6.  */
  7.   
  8. void show() {
  9.         
  10.         System.out.println("Hello world");
  11.  
  12.     }
  13. }





Program #2:java interview programs to practice: Non static variables in interface

  1. package interfaceinverviewprograms.instanceofjava;
  2. public interface A{
  3.  
  4. /**
  5. * @java interface  interview programming  questions and answers for freshers and experienced
  6.  */
  7.   
  8. int a,b;

  9. }





Program #3:java interview programs to practice: which modifiers interface allows

  1. package interfaceinverviewprograms.instanceofjava;
  2. public interface A{
  3.  
  4. /**
  5. * @java interface  interview programming  questions and answers for freshers and experienced
  6.  */
  7.   
  8. private int x;
  9. protected int y;

  10. }





Program #4:java interview programs to practice: interface allows constructor?

  1. package interfaceinverviewprograms.instanceofjava;
  2. public interface A{
  3.  
  4. /**
  5. * @java interface  interview programming  questions and answers for freshers and experienced
  6.  */
  7. A(){
  8.  
  9. }

  10. }





Exception handling in method overriding in java

  • Defining multiple methods with same name and same signature in super class and sub class known as method overriding.
  • When Overriding a method there is a chance of having statements which may cause exceptions so we need to handle those inside method.
  • Otherwise simply we can give responsibility of handling exceptions to calling method.
  • We can give the responsibility of handling exceptions of a method to calling place by using throws keyword in java.
  • Now we are going to discuss about exception handling in method overriding in java.
  • When am method is overridden in sub class and super class method having throws exception. Then we have some scenarios to discuss.



1.Super class method not throwing any exceptions.
2.Super class method  throws exceptions.


1.Super class method  Not throwing any exceptions.
  • When super class method not throws ant exception,
  • We can add throws unchecked exception in sub class overridden method.
  • We can not add throws checked exception.

Program #1: When super class method does not have any throws exception then we can add throws un checked exception in subclass overridden method.

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Super {
  3.  
  4.     /**
  5.      * @author www.instanceofjava.com
  6.      * @category throws in method overriding java
  7.      */
  8.     
  9.     
  10. public void show(){
  11.         
  12.  System.out.println("Super class show() method");
  13.  
  14. }
  15.  
  16. }

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Sub extends Super {
  3.  
  4. /**
  5. * @author www.instanceofjava.com
  6. * @category throws in method overriding java
  7. */
  8.     
  9. public void show() throws NullPointerException{
  10.         
  11.         System.out.println("Sub class show() method");
  12.  }

  13. public static void main(String[] args) {
  14.  
  15.    Sub obj = new Sub();
  16.     obj.show();
  17.  
  18. }
  19.  
  20. }
Output:

  1. Sub class show() method


Program #2: When super class method does not have any throws exception then we can not add throws checked exception in subclass overridden method.

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Super {
  3.  
  4.     /**
  5.      * @author www.instanceofjava.com
  6.      * @category throws in method overriding java
  7.      */
  8.     
  9.     
  10. public void show(){
  11.         
  12.  System.out.println("Super class show() method");
  13.  
  14. }
  15.  
  16. }

Exception handling in method overriding throws



2.Super class method  throws exceptions.

  • If super class method throws checked exceptions sub class overridden method can throw same exception , sub class exception or no exception but can not declare parent exception.
  • If super class method throws unchecked exceptions then no rules.


Program #3: When super class method  throws checked exception then we can add throws  checked exception in subclass overridden method.

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Super {
  3.  
  4.     /**
  5.      * @author www.instanceofjava.com
  6.      * @category throws in method overriding java
  7.      */
  8.     
  9.     
  10. public void show() throws IOException{
  11.         
  12.  System.out.println("Super class show() method");
  13.  
  14. }
  15.  
  16. }

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Sub extends Super {
  3.  
  4. /**
  5. * @author www.instanceofjava.com
  6. * @category throws in method overriding java
  7. */
  8.     
  9. public void show() throws IOException{
  10.         
  11.         System.out.println("Sub class show() method");
  12.  }

  13. public static void main(String[] args) {

  14.  
  15.    Sub obj = new Sub();
  16.  
  17.  try {
  18.             obj.show();
  19. } catch (IOException e) {
  20.          
  21.             e.printStackTrace();
  22. }
  23.  
  24. }
  25.  
  26. }
Output:

  1. Sub class show() method

Program #4: When super class method  throws unchecked exception then we can not add throws  checked exception in subclass overridden method.

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Super {
  3.  
  4.     /**
  5.      * @author www.instanceofjava.com
  6.      * @category throws in method overriding java
  7.      */
  8.     
  9.     
  10. public void show() throws ArithmeticException{
  11.         
  12.  System.out.println("Super class show() method");
  13.  
  14. }
  15.  
  16. }


throws in method overriding java


Program #5: When super class method  throws checked exception then we can not add throws its  parent exception in subclass overridden method.

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Super {
  3.  
  4.     /**
  5.      * @author www.instanceofjava.com
  6.      * @category throws in method overriding java
  7.      */
  8.     
  9.     
  10. public void show() throws FileNotFoundException{
  11.         
  12.  System.out.println("Super class show() method");
  13.  
  14. }
  15.  
  16. }

  1. package exceptionhandlingmethodoverridingjava;
  2. public class Sub extends Super {
  3.  
  4. /**
  5. * @author www.instanceofjava.com
  6. * @category throws in method overriding java
  7. */
  8.     
  9. public void show() throws IOException{
  10.         
  11.         System.out.println("Sub class show() method");
  12.  }

  13. public static void main(String[] args) {

  14.  
  15. Sub obj = new Sub();
  16.  
  17. try {
  18.            obj.show();
  19. } catch (Exception e) {
  20.           
  21.             e.printStackTrace();
  22. }
  23.  
  24. }
  25.  
  26. }

Yahoo sold to US telecoms giant Verizon

22nd July 2016:

  • Verizon is closing in on a deal to buy Yahoo’s core business for about $5 billion.
  • The value of the deal is reportedly around $5 billion for the core parts of Yahoo.
  • Verizon communications ready to pay  around $5 billion for yahoo's core business in search, email, advertising and media.
  • The $3 billion offer Verizon is expected to make next second bid is lower than the $4 billion to $8 billion bids that Yahoo’s Internet business, which includes its news sites and ad business. 

25th July 2016:

  • Yahoo agreed to sell its core operating business to Verizon for $4.8 billion on today morning.
  • US internet firm Yahoo is being acquired by American telecom's giant Verizon Communications for $4.8 billion.
  • "I love Yahoo, and I believe in all of you," Mayer said in a statement. "It’s important to me to see Yahoo into its next chapter."
  • Here Is Marissa Mayer's Final Letter To Yahoo Employees

Yahoo !!
  • 1994 Yahoo - which stands for Yet Another Hierarchically Organized Oracle - is founded
  • 2000 Yahoo valued at $125bn at height of dot.com boom
  • 2002 Google rejects a $3bn bid from Yahoo
  • 2008 Microsoft's $44.6bn offer for Yahoo is turned down
  • 2013 Blogging site Tumblr acquired by Yahoo for $1.1bn
  • 2015 Yahoo makes net loss of $4.4bn
  • 2016 Verizon agrees $4.8bn deal to buy Yahoo




verizon yahoo finance

What happened to Yahoo? 

  • On 18th July yahoo posted a deep loss which explains the challenges facing a potential acquirer of the shrinking internet business.
  • Yahoo loosing its visitors day by day if we observe internet search visitors statistics.

Loosing visitors :

  • Yahoo value lies in its users. But now it is loosing visitors and no more competition to google and Facebook. Yahoo losts its competitive edge
  • Analysis of the statistics from last decade shows how yahoo loosing its advertising revenue and search traffic.
  • Yahoo search engine share decreased from 42% to 12%.
  • Revenue share dropped from 25% to 3%.
verizon yahoo deal


The Company is Shrinking:

  • In 2015 its $4.4 loss in annual net income.
  • Yahoo hired Marissa mayer from google to get some positive results but she but it became largely unsuccessful.
  • Yahoo fired key people also resigned some key people because of pressure from share holders.
  • The company has sixth decline in last seven periods.


So Its Verizon Yahoo !

  • SunTrust analyst Robert Peck recently estimated that Verizon would lay off upwards of 40% of Yahoo’s 10,000 full-time employees (in order to save roughly $2 billion).
  • “Google has access to me on my mobile phone but is kind of missing the cable box and internet access data that Verizon has,” said Shar VanBoskirk, a digital marketing analyst at the research firm Forrester.


How to open notepad using java program

  • Notepad is a text editor from windows operating system. We use notepad for writing text files.
  • We can open a new notepad using java code.
  • By using the concept of running another application by Runtime class in java.
  • By creating object of runtime and calling  exec() method by passing application name.
  • Lets see how to open a notepad using java code




Program #1: Java example program to open notepad


  1. package interestingJavaprograms;
  2. import java.io.IOException;
  3.  
  4. public class NotepadJava {
  5.  
  6.     /**
  7.      * @ www.instanceofjava.com
  8.      * @ how to open a new notepad using java program
  9.      */
  10. public static void main(String[] args) {
  11.        
  12.           Runtime rt = Runtime.getRuntime();
  13.           
  14. try {
  15.       rt.exec("notepad");
  16. }
  17.  catch (IOException ex) {
  18.  
  19.  System.out.println(ex);
  20.  
  21. }  
  22.  
  23. }
  24.  
  25. }

 Output:

open notepad using java


Program #2: Java example program to open notepad and after 2 seconds close it.


  1. package interestingJavaprograms;
  2. import java.io.IOException;
  3.  
  4. public class NotepadJava {
  5.  
  6.     /**
  7.      * @ www.instanceofjava.com
  8.      * @ how to open a new notepad using java program
  9.      */
  10. public static void main(String[] args) throws InterruptedException, IOException {
  11.         
  12. Runtime runTime = Runtime.getRuntime();
  13. System.out.println("Opening notepad");
  14. Process process = runTime.exec("notepad");
  15.           
  16. try {
  17.  
  18.  
  19. Thread.sleep(200); 

  20.  process.destroy();
  21.  System.out.println("Closing notepad");
  22.  
  23. }
  24.  catch (Exception ex) {
  25.  
  26.  System.out.println(ex);
  27.  
  28. }  
  29.  
  30. }
  31.  
  32. }

  • We can open already existing notepad also for that we need to specify notepad.exe location and path of the destination file.
  • We need to pass these two parameters  to exec method of runtime class.
  • runTime.exec("C:\\Windows\\System32\\notepad.exe E:\\Samplenotepad.txt");

Program #3: Java example program to open exiting notepad txt file.


  1. package interestingJavaprograms;
  2. import java.io.IOException;
  3.  
  4. public class NotepadJava {
  5.  
  6.     /**
  7.      * @ www.instanceofjava.com
  8.      * @ how to open a new notepad using java program
  9.      */
  10. public static void main(String[] args) {
  11.        
  12.           Runtime rt = Runtime.getRuntime();
  13.           
  14. try {
  15.    runTime.exec("C:\\Windows\\System32\\notepad.exe E:\\Samplenotepad.txt");
  16. }
  17.  catch (IOException ex) {
  18.  
  19.  System.out.println(ex);
  20.  
  21. }  
  22.  
  23. }
  24.  
  25. }

Java program to remove vowels from string java

  • java program to remove vowels from a string
  • To remove vowels from a string we can use predefined method of string  replaceAll()
  • By passing all vowels to the method replaceAll() with empty it will replaces all vowels with empty. 
  • Check below topic for more programs on string 
  • Java Experience interview programs on strings



 Program #1: Java example program to remove all vowels from a String



  1. package inheritanceInterviewPrograms;
  2. public class RemoveVowels {
  3.  
  4.     /**
  5.      * @www.instanceofjava.com 
  6.      * @String interview programs asked in interviews
  7.      * @Remove vowels from a string in java
  8.      */
  9.  
  10.  public static void main(String[] args) {
  11.  
  12.         String str = "RemoveVowels";
  13.         String resustr = str.replaceAll("[aeiouAEIOU]", "");
  14.         System.out.println(resustr);
  15.  
  16.     }
  17.  
  18. }

 Output:


  1. RmvVwls

Program #2: Java example program to remove all vowels from a String by taking input from user


remove vowels from string

Java program to reverse vowels of a string


Program : Java example program to Reverse Vowels  in a String



  1. package inheritanceInterviewPrograms;
  2. /*
  3.  * @www.instanceofjava.com
  4.  */
  5. public class ReverseVowels {
  6.     public static String reverseVowels(String string) {
  7.  
  8.         String vowelsStr = "aeiouAEIOU";
  9.  
  10.         int lo = 0;
  11.         int hi = string.length() - 1;
  12.         char[] ch = string.toCharArray();
  13.  
  14.  while (lo < hi) {
  15.  
  16.      if (!vowelsStr.contains(String.valueOf(string.charAt(lo)))) {
  17.                 lo++;
  18.                 continue;
  19.        }
  20.  
  21.     if (!vowelsStr.contains(String.valueOf(string.charAt(hi)))) {
  22.                 hi--;
  23.                 continue;
  24.        }
  25.  
  26.     // swaping variables
  27.      swap(ch, lo, hi);
  28.             lo++;
  29.             hi--;
  30.       }
  31.  
  32.         return String.valueOf(ch);
  33.     }
  34.  
  35. private static void swap(char[] ch, int lo, int hi) {
  36.  
  37.         char temparray = ch[lo];
  38.         ch[lo] = ch[hi];
  39.         ch[hi] = temparray;
  40.  
  41.  }
  42.     
  43. public static void main (String args[]) {
  44.         
  45.          
  46.  System.out.println("After reversing vowels in a string="reverseVowels("InstanceOfjava"));
  47.         
  48.          
  49. }
  50.  
  51. }
Output:


  1. After reversing vowels in a string=anstancOefjavI


Select Menu