EXTERNAL PROGRAMS
/** Develop a program to display all the even numbers between 1 to 20 using for loop and if statement
*/
classexteven
public static void main(String arg[])
[Link]("\n Even Numbers Between 1 to 20 are :- ");
for(int i=1;i<20;i++)
if(i%2==0)
[Link]("\t"+i);
/** Develop a Program to create a class Student with data members student_name, roll_no and branch.
Initialize and display values of data members */
class Student
{
String student_name="Srushti",branch="Syco";
introll_no=60;
void display()
[Link]("\n Name = "+student_name+"\n Branch = "+branch+"\n Roll Number = "+roll_no);
public static void main(String arg[])
Student s=new Student();
[Link]();
//[Link]
*************************************************************************************
/** Develop a program to check entered String is palindrome or not */
[Link].*;
classextpalinstring
{
public static void main(String arg[])
String original, reverse = "";
Scanner sc = new Scanner([Link]);
[Link]("Enter a string to check if it is a palindrome :- ");
original = [Link]();
int length = [Link]();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + [Link](i);
if ([Link](reverse))
[Link]("<<<<<<<<<<<<< Entered string/number is a palindrome >>>>>>>>>>>>>>>");
else
[Link]("<<<<<<<<<<<<< Entered string/number isn't a palindrome
>>>>>>>>>>>>>>");
//[Link]
************************************************************************************
/** Define an exception called 'No match Exception'that is thrown when a string is not equal to
"MSBTE". Write program */
[Link].*;
import [Link].*;
classNoMatchException extends Exception
String str;
NoMatchException(String a)
super(a);
public String toString()
return " Invalid String (No Matched Found With MSBTE String) "+str;
classextnomatchexc
public static void main(String arg[])
String str;
Scanner sc=new Scanner([Link]);
[Link]("\n Enter a String :- ");
str=[Link]();
if()
{
try
throw new NoMatchException(str);
catch(Exception e)
[Link](e);
else
[Link]("\n Match Found with MSBTE String ");
*************************************************************************************
/** Write a program that will count no. of characters in a file. */
-------------------------------------------------
[Link] file
hello!!!!!
Welcome to Sveri College
we are from syco class
--------------------------------------------------
import [Link].*;
public class extcountcharfile
public static void main(String arg[])
BufferedReader reader = null;
intcharCount = 0;
try
reader = new BufferedReader(new FileReader("[Link]"));
String currentLine = [Link]();
while (currentLine != null)
String[] words = [Link](" ");
for (String word : words)
charCount = charCount + [Link]();
currentLine = [Link]();
}
[Link]("Number Of Chars In A File : "+charCount);
catch (IOException e)
[Link]();
finally
try
[Link]();
catch (IOException e)
[Link]();
*************************************************************************************
/** Define a Package Named "myPackage"to include a class named "DisplayMsg" with one method to
display some message. Develop a program to import this package in a java application and call the
method difined in the package */
Package myPackage;
public class displayMsg
public void display()
[Link]("\n…. Be Unique ….");
//Accessing the Package
Import [Link];
public class extpack
public static void main(String arg[])
displayMsg dm=new displayMsg();
[Link]();
}
***********************************************************************************
/** Write a program to input name and age of person and throws user defined exception, if entered age
is negative. */
Import [Link].*;
import [Link].*;
classNegativeAgeException extends Exception
int age;
NegativeAgeException(int a)
age=a;
public String toString()
return "You Entered Invalid Age :- "+age;
classextageexc
public static void main(String arg[])
int age;
Scanner sc=new Scanner([Link]);
[Link]("\n Enter Name :- ");
String nm=[Link]();
[Link]("\n Enter Your Age :- ");
age=[Link]();
if(age<0)
try
throw new NegativeAgeException (age);
catch(NegativeAgeException ne)
[Link](ne);
else
[Link]("\n Name = "+nm);
[Link]("\n Age = "+age); }
}
*************************************************************************************
/** Write a program to create two threads so one thread will print ascending numbers whereas second
thread will print descending numbers between sequence 1 to 15 numbers */
class ascending extends Thread
public void run()
for(int i=1;i<15;i++)
[Link]("\t"+i);
class descending extends Thread
public void run()
for(int i=15;i>1;i--)
[Link]("\t"+i);
classextthread
{
public static void main(String arg[])
ascending a=new ascending();
[Link]();
descending d=new descending();
[Link]();
**After adding Synchronized Keyword Output Looks like :-**
/** Develop a program to create an applet to display the message "Welcome to the worlds of Applet
"with green color background and red color foreground.*/
Import [Link].*;
Import [Link].*;
public class extapp extends Applet
public void init()
setBackground([Link]);
setForeground([Link]);
public void paint(Graphics ge)
[Link]("Welcome to the Worlds of Applet ",50,100);
**********************************************************************************
/**Develop a program to copy the contents of the file "[Link]"into a new file "[Link]"*/
------------------------------------------------------------------------------------------------
Hello !!!!
Welcome to ShriVitthal Education and Research Institute of Engineering (Polytechnic)Pandharpur,
******** We are from SYCO class **********
------------------------------------------------------------------------------------------------
import [Link].*;
class extcopyfile
public static void main(String arg[])throws IOException
FileInputStream fin=new FileInputStream("[Link]");
FileOutputStream fout=new FileOutputStream("[Link]");
int b;
do
b=[Link]();
[Link](b);
}while(b!=-1);
//Copied File Successfully
/** Write a program to compute sum of digits of number */
import [Link].*;
class extsumdigit
public static void main(String arg[])
int num, digit, sum=0;
Scanner sc=new Scanner([Link]);
[Link]("\n Enter the number = ");
num=[Link]();
while(num>0)
digit=num%10;
sum=sum+digit;
num=num/10;
[Link]("\n Sum of Digits: " +sum);
}
*************************************************************************************
/** Write a program to generate Fibonacci's Series.*/
import [Link].*;
class extfibonacci
public static void main(String arg[])
int n1=0,n2=1,n3,count=0,i;
Scanner sc=new Scanner([Link]);
[Link]("\n How much numbers you've required into the series ?(Enter total count) :- ");
count=[Link]();
[Link](n1+"\t"+n2);
for(i=2;i<count;++i)
n3=n1+n2;
[Link]("\t"+n3);
n1=n2;
n2=n3;
}
*************************************************************************************
/**Write a program to create a vector with seven elements as [10,20,50,20,40,10,20]. Remove element
at 3rd and 4th position. Insert new element at 3rd position. Display the original and current size of the
vector.*/
import [Link].*;
class extvector
public static void main(String arg[])
Vector v=new Vector(15);
[Link](new Integer(10));
[Link](new Integer(20));
[Link](new Integer(50));
[Link](new Integer(20));
[Link](new Integer(40));
[Link](new Integer(10));
[Link](new Integer(20));
[Link]("\n Original Size of The Vector = "+[Link]());
[Link]("\n Vector Class :- "+v);
[Link](3);
[Link](4);
[Link]("\n After Deletion Vector Class :- "+v);
[Link](new Integer(30),3);
[Link]("\n After Insertion :- "+v);
[Link]("\n Current Size of The Vector = "+[Link]());
**********************************************************************************
/**Write a program to accept a number as command line argument and print the number is even or
odd. */
import [Link].*;
class extcmdeven
public static void main(String arg[])
String s1=arg[0];
int n=[Link](s1);
if(n%2==0)
{
[Link]("\n .......... Entered Number is Even .........");
else
[Link]("\n !!!! Entered Number is Odd !!!!");
**********************************************************************************
/** create an applet to display the string " Applet Graphics Programming " with font " Courier New" ,
size :25 points and BOLD + ITALIC. */
import [Link].*;
import [Link].*;
public class extappfontop extends Applet
public void paint(Graphics g)
Font f=new Font("Courier New",[Link]+[Link],25);
[Link]("Applet Graphics Programming", 50,100);
}
}
/*
<applet code="[Link]" width=300 height=300></applet>
*/
/** Accept any string containing all types of characters and symbols from user and count only number of
digits.*/
import [Link].*;
class extcountstrdigit
public static void main(String arg[])throws Exception
BufferedReader br=new BufferedReader(new InputStreamReader([Link]));
[Link]("\n Enter a String which Contains numbers,character and also
Symbols :- ");
String sv=[Link]();
int l=[Link]();
char ch[]=new char[l];
ch=[Link]();
int c=0;
for(int i=0;i<l;i++)
if([Link](ch[i]))
c++;
[Link]("\n String = "+sv);
[Link]("\n ------------------------------------------------");
[Link]("\n Total Number of Digits from Entered String = "+c);
[Link]("\n ------------------------------------------------");
**********************************************************************************
/** Write a program to check whether entered number is prime or not */
import [Link].*;
class extprime
public static void main(String arg[])
int num,i,count=0;
Scanner sc=new Scanner([Link]);
[Link]("\n Enter a Number := ");
num=[Link]();
for(i=2;i<=num/2;i=i+1)
if(num%i==0)
count++;
break;
if(num==0||num==1)
[Link]("\n You entered neigther prime nor composite number ");
else if(count==0)
[Link]("\nAWW!!!\n...Entered Number is Prime....");
else
[Link]("\nOOPS !!\n....Entered number is not prime....");
}
*************************************************************************************
/** implement the following
Class : Person Interface : Manager
Name, address accept(),salary()
Class : Employee
ID, basic */
import [Link].*;
interface Manager
public void accept();
public void salary();
class Person
String name,address;
public void accept()
Scanner sc=new Scanner([Link]);
[Link]("\n Enter Name :- ");
name=[Link]();
[Link]("\n Enter Your Address :- ");
address=[Link]();
class Employee extends Person implements Manager
int Id,basic;
void getdata()
Scanner s=new Scanner([Link]);
[Link]("\n Enter ID :- ");
Id=[Link]();
[Link]("\n Enter Basic Salary :- ");
basic=[Link]();
public void salary()
[Link]("\n Name = "+name);
[Link]("\n ID ="+Id);
[Link]("\n Address = "+address);
[Link]("\n Basic Salary = "+basic);
class extinterface
public static void main(String arg[])
Employee emp=new Employee();
[Link]();
[Link]();
[Link]();
*************************************************************************************
/** Write an applet program that display the logo of Olympic. All the circle are of same radius, assume
the radius.*/
import [Link].*;
import [Link].*;
public class extolympic extends Applet
public void paint(Graphics g)
[Link]([Link]);
[Link](50,50,75,75);
[Link]([Link]);
[Link](130,50,75,75);
[Link]([Link]);
[Link](210,50,75,75);
[Link]([Link]);
[Link](95,90,75,75);
[Link]([Link]);
[Link](175,90,75,75);
/*
<applet code="[Link]" width=400 height=400>
</applet>
*/
*************************************************************************
/** Define a class employee with data members as emp_id and salary, Accept data for 5 objects and
print it.*/
import [Link].*;
class employee
int emp_id,salary;
void accept()
Scanner sc=new Scanner([Link]);
[Link]("\n Enter Employee Id :- ");
emp_id=[Link]();
[Link]("\n Enter Salary :- ");
salary=[Link]();
void print()
{
[Link]("\n Id = "+emp_id);
[Link]("\n Salary= "+salary);
class extemp
public static void main(String arg[])
employee e[]=new employee[5];
[Link]("\n -------- FILL YOUR DETAILS --------");
for(int i=0;i<5;i++)
e[i]=new employee();
e[i].accept();
[Link]("\n-------- EMPLOYEE DETAILS --------");
for(int i=0;i<5;i++)
e[i].print();
}
**********************************************************************************
/** Write a thread program for implementing the 'Runnable interface'.*/
class myThread implements Runnable
synchronized public void run()
for(int i=0;i<=20;i++)
[Link]("\t"+i);
}
class extrunnableinter
public static void main(String arg[])
myThread m=new myThread();
Thread t=new Thread(m);
[Link]();
**********************************************************************************