Amity Institute of Information Technology, Noida
Uttar Pradesh
Practical File on
Java Programming
A report submitted for the partial fulfilment of the requirement for the
bachelor’s in computer application course (2019-2022) of Amity University.
Submitted To: Submitted By:
Dr Sarvesh Tanwar Akshat Srivastava
T201 A10046619014
BCA (Evening)
1. Write a Program to print the text “Welcome to World of Java” Save it with name
Welcome java in your folder.
Source Code:
public class Welcome {
public static void main(String[] args) {
[Link]("----------------------");
[Link]("Welcome to World of Java");
[Link]("----------------------");
Output:
2. Java Program to check Even or Odd number.
Source Code:
import [Link];
public class EvenOdd {
public static void main(String[] args) {
Scanner reader = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();
if(num % 2 == 0)
[Link](num + " is even");
else
[Link](num + " is odd");
}
Output:
3. Write a Java program to calculate a Factorial of a number.
Source Code:
import [Link];
public class Factorial {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("---------------------");
[Link]("Enter Number: ");
int num = [Link]();
[Link]();
int fact = 1; for (int i = 1; i <= num; i++) {
fact *= i; }
[Link]("Factorial of " + num + " is " + fact);
[Link]("---------------------");
Output:
4. Write a Java program that counts the number of objects created by using static
variable.
Source Code:
public class FibonacciSeries {
public static void main(String[] args) {
[Link]("---------------------");
int n = 10;
int a = 0, b = 1, c;
[Link](a + " " + b + " ");
for (int i = 0; i < n; i++) {
c = a + b;
a = b;
b = c;
[Link](c + " ");
[Link]();
[Link]("---------------------");
Output:
5. Write a java Program to check the number is Prime or not.
Source Code:
import [Link];
public class PrimeOrNot {
public boolean isPrime(int num) {
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) return false;
return true;
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
PrimeOrNot primeOrNot = new PrimeOrNot();
[Link]("---------------------");
[Link]("Enter Number: ");
int num = [Link]();
[Link]();
if([Link](num)) [Link](num + " is a Prime Number");
else [Link](num + " is not a Prime Number");
[Link]("---------------------");
Output:
6. Write a java program to check the given number is Armstrong Number or not.
Source Code:
public class Armstrong {
public static void main(String[] args) {
int number = 371, originalNumber, remainder, result = 0;
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber % 10;
result += [Link](remainder, 3);
originalNumber /= 10;
if(result == number)
[Link](number + " is an Armstrong number.");
else
[Link](number + " is not an Armstrong number.");
Output:
7. Write a Java program that prompts the user for an integer and then prints out all the
prime numbers up to that Integer.
Source Code:
import [Link];
class PrimeNumbers
{ public static void main(String[] args)
{ int n;
int p;
Scanner s=new Scanner([Link]);
[Link]("Enter a number: ");
n=[Link]();
for(int i=2;i<n;i++)
{ p=0;
for(int j=2;j<i;j++)
{ if(i%j==0)
p=1;
if(p==0)
[Link](i);
} } }
Output:
8. Write a Java program that checks whether a given string is a palindrome or not Ex:
MADAM is a palindrome.
Source Code:
class Main {
public static void main(String[] args) {
String str = "MADAM", reverseStr = "";
int strLength = [Link]();
for (int i = (strLength - 1); i >=0; --i) {
reverseStr = reverseStr + [Link](i);
if ([Link]().equals([Link]())) {
[Link](str + " is a Palindrome String.");
else {
[Link](str + " is not a Palindrome String.");
} } }
Output:
Write a Java program to perform basic Calculator operations
Source Code:
public class Calculator {
private static int add(int a,int b) {
return a + b;
private static int sub(int a,int b) {
return a - b;
private static int mul(int a,int b) {
return a * b;
private static float div(float a,float b) {
return a / b;
private static int mod(int a,int b) {
return a % b;
public static void main(String[] args) {
[Link]("---------------------");
int a = 97, b = 62;
[Link]("Addition: " + add(a, b));
[Link]("Subtraction: " + sub(a, b));
[Link]("Multiplication: " + mul(a, b));
[Link]("Division: " + div(a, b));
[Link]("Modulas: " + mod(a, b));
[Link]("---------------------");
}
Output:
9. Write a Java program to multiply two given matrices
Source Code:
public class MatrixMultiplicationExample{
public static void main(String args[]){
//creating two matrices
int a[][]={{1,1,1},{2,2,2},{3,3,3}};
int b[][]={{1,1,1},{2,2,2},{3,3,3}};
//creating another matrix to store the multiplication of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns
//multiplying and printing multiplication of 2 matrices
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
c[i][j]=0;
for(int k=0;k<3;k++)
c[i][j]+=a[i][k]*b[k][j];
}//end of k loop
[Link](c[i][j]+" "); //printing matrix element
}//end of j loop
[Link]();//new line }
}}
Output:
10. Write a Java program that reverses a given String
Source Code:
import [Link];
public class ReverseString {
public static String reverseString(String str) {
String reverseStr = "";
for (int i = [Link]() - 1; i >= 0; i--) {
reverseStr += [Link](i);
return reverseStr;
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("---------------------");
[Link]("Enter String: ");
String str = [Link]();
[Link]();
[Link]("Reverse String: " + reverseString(str));
[Link]("---------------------");
Output:
11. Write a Java program to sort the elements using bubble sort
Source Code:
public class BubbleSortExample {
static void bubbleSort(int[] arr) {
int n = [Link];
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j-1] > arr[j]){
//swap elements
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
} }
public static void main(String[] args) {
int arr[] ={3,60,35,2,45,320,5};
[Link]("Array Before Bubble Sort");
for(int i=0; i < [Link]; i++){
[Link](arr[i] + " ");
[Link]();
bubbleSort(arr);//sorting array elements using bubble sort
[Link]("Array After Bubble Sort");
for(int i=0; i < [Link]; i++){
[Link](arr[i] + " ");
Output:
12. Write a Java program to search an element using binary search
Source Code:
class BinarySearchExample{
public static void binarySearch(int arr[], int first, int last, int key){
int mid = (first + last)/2;
while( first <= last ){
if ( arr[mid] < key ){
first = mid + 1;
}else if ( arr[mid] == key ){
[Link]("Element is found at index: " + mid);
break;
}else{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last ){
[Link]("Element is not found!");
}
}
public static void main(String args[]){
int arr[] = {10,20,30,40,50};
int key = 30;
int last=[Link]-1;
binarySearch(arr,0,last,key);
}
}
Output:
13. Write a java program that implements Array Index out of bound Exception using built-
in-Exception
Source Code:
class ArithmeticException_Demo {
public static void main(String args[])
try {
int a = 30, b = 0;
int c = a / b; // cannot divide by zero
[Link]("Result = " + c);
catch (ArithmeticException e) {
[Link]("Can't divide a number by 0");
}
}
Output:
14. Write a java program to identify the significance of finally block in handling exceptions
Source Code:
import [Link].*;
class GFG {
public static void main(String[] args)
{ try { [Link]("inside try block");
// Not throw any exception
[Link](34 / 2);
// Not execute in this case
catch (ArithmeticException e) {
[Link]("Arithmetic Exception");
// Always execute
finally {
[Link](
"finally : i execute always.");
} } }
Output:
15. Write a java program that implements user defined exception
Source Code:
class MyException extends Exception{
String str1;
/* Constructor of custom exception class
* here I am copying the message that we are passing while
* throwing the exception to a string and then displaying
* that string along with the message.
*/
MyException(String str2) {
str1=str2;
public String toString(){
return ("MyException Occurred: "+str1) ;
class Example1{
public static void main(String args[]){
try{
[Link]("Starting of try block");
// I'm throwing the custom exception using throw
throw new MyException("This is My error Message");
}
catch(MyException exp){
[Link]("Catch Block") ;
[Link](exp) ;
Output:
16. Write a Java program that displays area of different Figures (Rectangle, Square,
Triangle) using the method overloading
Source Code:
class OverloadDemo
void area(float x)
[Link]("the area of the square is "+[Link](x, 2)+" sq units");
void area(float x, float y)
[Link]("the area of the rectangle is "+x*y+" sq units");
void area(double x)
double z = 3.14 * x * x;
[Link]("the area of the circle is "+z+" sq units");
}
}
class Overload
public static void main(String args[])
OverloadDemo ob = new OverloadDemo();
[Link](5);
[Link](11,12);
[Link](2.5);
Output:
Write a java program to calculate gross salary & net salary taking the following data
Source Code:
import [Link];
public class salary
public static void main(String args[])
double basic,da,hra,gross;
[Link]("Enter Basic salary of the employee\n");
Scanner obj1=new Scanner([Link]);
basic=[Link]();
da=40*basic/100;
hra=20*basic/100;
gross= basic+da+hra;
[Link]("The D.A of the basic salary of the employee is:" +da);
[Link]("The H.R.A of the basic salary of the employee is:" +hra);
[Link]("The Gross salary of the employee is:" +gross);
Output:
17. Write a java program to find the details of the students eligible to enroll for the
examination (Students, Department combinedly give the eligibility criteria for the
enrolment class) using interfaces
Source Code:
import [Link];
public class GetStudentDetails
public static void main(String args[])
String name;
int roll, math, phy, eng;
Scanner SC=new Scanner([Link]);
[Link]("Enter Name: ");
name=[Link]();
[Link]("Enter Roll Number: ");
roll=[Link]();
[Link]("Enter marks in Maths, Physics and English: ");
math=[Link]();
phy=[Link]();
eng=[Link]();
int total=math+eng+phy;
float perc=(float)total/300*100;
[Link]("Roll Number:" + roll +"\tName: "+name);
[Link]("Marks (Maths, Physics, English): " +math+","+phy+","+eng);
[Link]("Total: "+total +"\tPercentage: "+perc);
Output:
18. . Write a java program to calculate gross salary & net salary taking the following data
Source Code:
import [Link];
public class GrossSalary {
static float calculateGrossSalary(int basicSalary, int hra, int da, int pf) {
return basicSalary + (basicSalary * (hra/100f) + (basicSalary * (da/100f)) - (basicSalary * (pf/100f)));
}
public static void main(String[] args) {
[Link]("-----------------------");
Scanner scanner = new Scanner([Link]);
[Link]("Enter Basic Salary: ");
int basicSalary = [Link]();
[Link]("Enter HRA(%): ");
int hra = [Link]();
[Link]("Enter DA(%): ");
int da = [Link]();
[Link]("Enter PF(%): ");
int pf = [Link]();
[Link]();
int _grossSalary = (int) calculateGrossSalary(basicSalary, hra, da, pf);
[Link]("Gross Salary: " + _grossSalary);
[Link]("-----------------------");
}
Output:
19. Write a Java program to find the details of the students eligible to enroll for the
examination (Students, Department combinedly give the eligibility criteria for the
enrollment class) using interfaces
Source Code:
import [Link];
interface StudentDetails {
int id = 16;
StringBuilder name = new StringBuilder("Akshat");
String course = "BCA";
void getData();
class Department implements StudentDetails {
int attendance = 0;
public void setAttendance() {
Scanner scanner = new Scanner([Link]);
[Link]("Enter Attendance: ");
attendance = [Link]();
[Link]();
@Override
public void getData() {
[Link]("-----------------------");
[Link]("Student ID: " + id);
[Link]("Student Name: " + name);
[Link]("Student Class: " + course);
[Link]("-----------------------");
}}
class Exam extends Department {
public boolean eligible() {
return attendance >= 75;
public class Students {
public static void main(String[] args) {
Exam exam = new Exam();
[Link]();
[Link]();
[Link]("Is Eligible: " + [Link]());
Output:
Implement Operators
Left Shift Operator
Source Code:
package Shift;
public class LeftShift {
public static void main(String[] args) {
[Link](52 << 2);
[Link](2 << 2);
[Link](31 << 1);
[Link](20 << 3);
Output:
Right Shift Operator
Source Code:
package Shift;
public class RightShift {
public static void main(String[] args) {
[Link](52 >> 2);
[Link](2 >> 2);
[Link](31 >> 1);
[Link](20 >> 3);
Output:
All Operators using methods
Source Code:
package Shift;
class JavaOperators {
private int num = 5;
private int num2 = 7;
void logical() {
[Link]("-----Logical-----");
if(num > 0 && num < 10) [Link](num + " is between 0 - 10");
if(false || true) [Link]("True");
if(num != 6) [Link]("Number is not equal to 6");
void relational() {
[Link]("-----Relational-----");
if(num == num2) [Link]("both are equal");
if(num > num2) [Link](num + " is greater");
if(num < num2) [Link](num2 + " is greater");
if(num != num2) [Link]("both are not equal");
if(num >= num2) [Link](num + " is greater equal to " + num2);
if(num <= num2) [Link](num2 + " is greater equal to " + num);
void bitwise() {
[Link]("-----Bitwise-----");
[Link]("AND: " + (num & num2));
[Link]("OR: " + (num | num2));
[Link]("XOR: " + (num ^ num2));
[Link]("Complement: " + ~num) ;
public class OP {
public static void main(String[] args) {
JavaOperators javaOperators = new JavaOperators();
[Link]();
[Link]();
[Link]();
Output:
20. Implement Exceptions
Arithmetic Exception
Source Code:
package ExeptionHandling;
public class ArithmeticExp {
public static void main(String[] args) {
int num = 7;
int num2 = 0;
try {
[Link](num/num2);
} catch (ArithmeticException e) {
[Link]();
} catch (Exception e) {
[Link]();
Output:
Array Out of Bound Exception
Source Code:
package ExeptionHandling;
public class ArrayExp {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
try {
[Link](arr[22]);
} catch (ArrayIndexOutOfBoundsException e) {
[Link]();
} catch (Exception e) {
[Link]();
Output:
File Not Found Exception
Source Code:
package ExeptionHandling;
import [Link];
import [Link];
import [Link];
public class FileExp {
public static void main(String[] args) {
try {
File file = new File("");
FileReader fileReader = new FileReader(file);
[Link]();
} catch (FileNotFoundException e) {
[Link]();
} catch (Exception e) {
[Link]();
Output:
21. Array Exercises
Traversing Array
Source Code:
package JavaArrays;
public class TraversingArray {
public static void main(String[] args) {
int[] nums = {8, 3, 7, 9, 2, 4, 6, 1};
for (int i : nums) {
[Link](i);
Output:
22. Write a Program to find the percentage and grade of multiple students using methods
Source Code:
import [Link];
/***
@author Akshat
*/
class Student {
String name;
byte javaMarks;
byte pythonMarks;
byte cMarks;
byte cppMarks;
short totalMarks;
float percentage;
String grade;
private void gradeCalculate() {
if (percentage >= 90)
grade = "A+";
else if (percentage >= 80)
grade = "B+";
else if (percentage >= 60)
grade = "C";
else if (percentage >= 40)
grade = "D";
else
grade = "Fail";
Student(String name, byte javaMarks, byte pythonMarks, byte cMarks, byte cppMarks) {
[Link] = name;
[Link] = javaMarks;
[Link] = pythonMarks;
[Link] = cMarks;
[Link] = cppMarks;
totalMarks = (short) (javaMarks + pythonMarks + cMarks + cppMarks);
percentage = (totalMarks * 100.00f) / 400.00f;
gradeCalculate();
public void display() {
[Link]("Name: " + name + "\t" + "Java Marks: " + javaMarks + "\t" + "Python Marks: " + pythonMarks +
"\t" + "C Marks: " + cMarks + "\t" + "C++ Marks: " + cppMarks + "\t" + "Total Marks: " + totalMarks + "\t" +
"Percentage: " + percentage + "\t" + "Grade: " + grade);
public class GradeProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter Number of Students: ");
byte numberOfStudents = [Link]();
Student[] students = new Student[numberOfStudents];
for (int i = 0; i < [Link]; i++) {
[Link]("Enter Name of Student: ");
[Link]();
String name = [Link]();
[Link]("Enter Java Marks: ");
byte javaMarks = [Link]();
[Link]("Enter Python Marks: ");
byte pythonMarks = [Link]();
[Link]("Enter C Marks: ");
byte cMarks = [Link]();
[Link]("Enter C++ Marks: ");
byte cppMarks = [Link]();
students[i] = new Student(name, javaMarks, pythonMarks, cMarks, cppMarks);
[Link]();
for (int i = 0; i < [Link]; i++) {
students[i].display();
Output:
23. Inheritance
Constructor
Default Constructor
Source Code:
package Constructor;
class Demo {
Demo() {
[Link]("Default Constructor");
public class DefaultCon {
public static void main(String[] args) {
Demo demo = new Demo();
Output:
Parameterized Constructor
Source Code:
package Constructor;
class DemoTwo {
private int num;
private int num2;
DemoTwo(int num, int num2) {
[Link] = num;
this.num2 = num2;
[Link]("SUM: " + (num + num2));
public class ParaCon {
public static void main(String[] args) {
DemoTwo demoTwo = new DemoTwo(12, 8);
Output:
Constructor Overloading
Source Code:
package Constructor;
class DemoThree {
DemoThree(int num, int num2) {
[Link]("SUM: " + (num + num2));
DemoThree(int ...nums) {
int sum = 0;
for (int i = 0; i < [Link]; i++) {
sum += nums[i];
[Link]("Total SUM: " + sum);
public class OverloadingCon {
public static void main(String[] args) {
[Link]("----------");
DemoThree demoThree = new DemoThree(98, 13);
DemoThree demoThre2 = new DemoThree(98, 13, 78, 32, 4, 65);
[Link]("----------");
Output:
24. Threads in Java
Thread using Runnable Interface
Source Code:
package JavaThreads;
class Threading1 implements Runnable {
@Override
public void run() {
while(true) {
[Link]("Thread ID 1: " + [Link]().getId());
class Threading2 implements Runnable {
@Override
public void run() {
while(true) {
[Link]("Thread ID 2: " + [Link]().getId());
public class MultiThreadingTwo {
public static void main(String[] args) {
Threading1 bullet1 = new Threading1();
Thread gun1 = new Thread(bullet1);
Thread gun2 = new Thread(new Threading2());
[Link](Thread.MAX_PRIORITY);
[Link]();
[Link]();
Output:
Java Program for Thread priority
Source Code:
package JavaThreads;
class HelloWorld extends Thread{
@Override
public void run() {
[Link]();
while(true) {
[Link]("Hello Wolrd");
class Numbers extends Thread {
@Override
public void run() {
[Link]();
for (int i = 0; true; i++) {
[Link](i);
}
public class MultiThreading {
public static void main(String[] args) {
HelloWorld obj1 = new HelloWorld();
Numbers obj2 = new Numbers();
[Link](Thread.MAX_PRIORITY);
[Link]();
[Link]();
Output:
Program for sleep method in Java
Source Code:
Output:
Program for multiple Threads
Source Code:
package JavaThreads;
import PrimeOrNot;
import [Link];
class Factorial extends Thread {
int fact = 1;
int num;
Factorial(int num) {
[Link] = num;
@Override
public void run() {
for (int i = 1; i <= num; i++) {
fact *= i;
try {
[Link](5);
} catch (Exception e) {
[Link]();
[Link]("Factorial of " + num + " is " + fact);
class PrimeNumbers extends Thread {
int num;
PrimeNumbers(int num) {
[Link] = num;
@Override
public void run() {
for (int i = 2; i <= num; i++) {
if([Link](i)) [Link]("Prime Number: " + i);
try {
[Link](5);
} catch (Exception e) {
[Link]();
}
}
public class FactorialThread {
public static void main(String[] args) {
[Link]("----------------------------");
Scanner scanner = new Scanner([Link]);
[Link]("Enter Number for Prime Numbers: ");
int num1 = [Link]();
[Link]("Enter Number for Factorial: ");
int num2 = [Link]();
[Link]();
PrimeNumbers primeNumbers = new PrimeNumbers(num1);
Factorial factorial = new Factorial(num2);
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MAX_PRIORITY);
[Link]();
[Link]();
Output:
Importing package in Java
Source Code:
package Searching;
import [Link];
import [Link];
public class BinarySearch {
public static String bSearch(int num, int arr[]) {
byte minIndex = 0;
byte maxIndex = (byte) ([Link] - 1);
while (minIndex <= maxIndex) {
byte midIndex = (byte) ((minIndex + maxIndex) / 2);
// [Link](minIndex + " " + midIndex + " " + maxIndex);
if (arr[midIndex] == num)
return num + " is Present at " + (midIndex+1) + " Position";
else if (arr[midIndex] < num)
minIndex = (byte) (midIndex + 1);
else
maxIndex = (byte) (midIndex - 1);
return "Number Not Found!!";
public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);
[Link]("Enter Number of Length of an Array: ");
byte numberOfLength = [Link]();
int[] arr = new int[numberOfLength];
[Link]("Enter Elements one by one");
for (byte i = 0; i < [Link]; i++) {
arr[i] = [Link]();
[Link]("Enter Number to Search");
int num = [Link]();
[Link]();
arr = [Link](arr);
for (int i : arr) {
[Link](i + " ");
[Link]();
[Link](bSearch(num, arr));
Output:
25. Java String
String compareTo()
Source Code:
package JavaStrings;
public class CompareString {
public static void main(String[] args) {
String str = new String("Hello");
String str2 = new String("hello");
[Link]([Link](str2));
Output:
String concat()
Source Code:
package JavaStrings;
public class ConcatString {
public static void main(String[] args) {
String str = "Hello ";
String str2 = "World!!";
[Link]([Link](str2));
Output:
String Builder example
Source Code:
package JavaStrings;
import [Link];
public class SBuilder {
public static void main(String[] args) {
StringBuilder str = new StringBuilder("Akshat");
[Link](" Srivastava");
[Link](str);
Output:
String Buffer example
Source Code:
package JavaStrings;
import [Link];
public class SBuffer {
public static void main(String[] args) {
StringBuffer str = new StringBuffer("Hello World!!");
[Link]([Link]("r"));
Output:
26. Applet Programs
Hello World program
Source Code:
import [Link];
import [Link];
public class HelloWorld extends Applet{
public void paint(Graphics g) {
[Link]("Hello World!!", 100, 200);
<html>
<body>
<applet code=[Link] width=200 height=200>
</applet>
</body>
</html>
Output:
Animation program
Source Code:
import [Link].*;
import [Link].*;
public class JavaAnimation extends Applet {
Image img;
public void init() {
img = getImage(getDocumentBase(), "[Link]");
public void paint(Graphics graphics) {
for(int i = 50; i < 600; i++) {
[Link](img, i, 5, this);
try {
[Link](200);
} catch (Exception e) {
[Link]();
<html>
<body>
<applet code=[Link] width=1200 height=900>
</applet>
</body>
</html>
Output:
Ball program
Source Code:
import [Link].*;
import [Link].*;
public class BallProgram extends Applet{
int x = 0, y = 0, p = 2, q = 1;
int ballWidth = 100, ballHeight = 100, width, height;
Thread thread;
public void init() {
width = getSize().width;
height = getSize().height;
thread = new Thread();
public void start() {
[Link]();
public void run() {
while(true) {
x += p;
y += q;
repaint();
try {
[Link](200);
} catch (Exception e) {
[Link]();
if((x + ballWidth) >= width || x <= 0) {
p *= -1;
if((y + ballHeight) >= height || y <= 0) {
y *= -1;
public void paint(Graphics graphics) {
[Link]([Link]);
[Link](x, y, ballWidth, ballHeight);
<html>
<body>
<applet code=[Link] width=200 height=200>
</applet>
</body>
</html>
Output:
Rectangle program
Source Code:
import [Link].*;
import [Link].*;
public class RectangleProgram extends Applet {
public void paint(Graphics graphics) {
[Link]([Link]);
graphics.draw3DRect(100, 100, 50, 50, true);
[Link]([Link]);
graphics.fill3DRect(200, 200, 100, 100, true);
<html>
<body>
<applet code=[Link] width=200 height=200>
</applet>
</body>
</html>
Output:
27. Creating a [Link] file and demo maven project
Source Code:
[Link]:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="[Link] xmlns:xsi="[Link]
xsi:schemaLocation="[Link] [Link]
<modelVersion>4.0.0</modelVersion>
<groupId>[Link]</groupId>
<artifactId>mprogram</artifactId>
<version>1.0-SNAPSHOT</version>
<name>mprogram</name>
<!-- FIXME change it to the project's website -->
<url>[Link]
<properties>
<[Link]>UTF-8</[Link]>
<[Link]>1.7</[Link]>
<[Link]>1.7</[Link]>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom)
-->
<plugins>
<!-- clean lifecycle, see [Link] -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see [Link]
[Link]#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see [Link] -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
App:
package [Link];
/**
Hello world!
*/
public class App
public static void main( String[] args )
[Link]("Hello World!");