//java applet code for hello world
import java.awt.*;
import java.applet.*;
/*
<applet code="appletEx" width=100 height=100>
</applet>
*/
public class appletEx extends Applet
public void paint(Graphics g)
g.drawString("Hello World", 50, 50);
HTML code fro above program
<html>
<applet code="appletEx", width=100 height=100>
</applet>
</html>
www.awillguru.com
Run method in command line
C:\Users\awill\Desktop\practical>set path="C:\Program Files\Java\jdk-10.0.2\bin"
C:\Users\awill\Desktop\practical>javac -deprecation appletEx.java
appletEx.java:10: warning: [deprecation] Applet in java.applet has been deprecat
ed
public class appletEx extends Applet
1 warning
C:\Users\awill\Desktop\practical>appletviewer appletEx.html
Warning: Applet API and AppletViewer are deprecated.
Warning: Can't read AppletViewer properties file: C:\Users\awill\.hotjava\proper
ties Using defaults.
//program to add two variable and print in applet
import java.applet.*;
import java.awt.*;
public class addapplet extends Applet
public void paint(Graphics g)
int a=10;
www.awillguru.com
int b=20;
int c= a+b;
String str= "Sum is: " + String.valueOf(c);
g.drawString(str,100,100);
<html>
<body>
<p>this will print sum in applet</p>
<applet code="addapplet" height=400 width=400>
</applet>
</body>
</html>
//normal java program
import java.util.*;
public class test
public static void main(String args[])
System.out.println("Enter a value");
Scanner sc= new Scanner(System.in);
www.awillguru.com
int value= sc.nextInt();
System.out.println("value in main:"+value);
test t =new test();
int aw=t.awill(value);
System.out.println("now return value:"+aw);
int awill(int v)
System.out.println("value in awill:"+v);
return 20;
//program to find factorial by recursion
class FactRec
public static void main(String args[])
int i,fact=1;
int number=5;//It is the number to calculate factorial
fact = factorial(number);
System.out.println("Factorial of "+number+" is: "+fact);
www.awillguru.com
static int factorial(int n)
if (n == 0)
return 1;
else
return(n * factorial(n-1));
} }
//program to find factorial in a loop
import java.util.*;
public class facto
public static void main(String args[])
{ boolean b;
String f;
Scanner sc= new Scanner(System.in);
Scanner ch=new Scanner(System.in);
do{
System.out.println("Enter a value for factorial:");
int n=sc.nextInt();
int fact=fact(n);
System.out.println("The factorial is:"+fact);
www.awillguru.com
System.out.println("more factorial press y . For exit press n");
f=ch.nextLine();
System.out.println("you entered::"+f);
} while(f.equalsIgnoreCase("yes")|| f.equalsIgnoreCase("y"));
static int fact(int n)
if(n==0 || n==1)
return 1;
else return n*fact(n-1);
www.awillguru.com