尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
BY O.W.O
1. WAP to find the average and sum of N numbers using command line argument.
ALGORITHMS
Step 1: Start and Pass the values through command line
Step 2: Convert the values to integer
Step 3: Find the sum and average
Step 4: Display the results.
Step 5: End the program.
Program Code
class CommandArg {
public static void main(String arg[]) {
int i,n;
double sum=0,Avg;
n=Integer.parseInt(arg[0]);
for(i=1;i<=n;i++) {
sum=sum+Double.parseDouble(arg[i]);
}
Avg=sum/n;
System.out.println ("The Sum is"+ sum);
System.out.println ("The Average is"+ Avg);
}
}
Output:
Java CommandArg 2 6 4
The Sum is 10
The Average is 5
1
BY O.W.O
2. Create a class student and read and display the details using member function
ALGORITHMS
Step 1: Create a class student with read and display the details using member function.
Step 2: Create the class student with data members (name, rollno, batch) and member
functions (read(), display() ).
Step 3: Create an object using class student.
Step 4: Using object call the functions read () and display ().
code
class Student
{
String stName;
int stAge;
void initialize()
{
stName="loguk pa gwanyank";
stAge=23;
}
void display()
{
System.out.println("Student name:" +stName);
System.out.println("Student Age:" +stAge);
}
public static void main(String []args){
objStudent = new Student();
objStudent.initialize();
objStudent.display();
}
} OUTPUT
2
BY O.W.O
3. Create class square with data members( length, area and perimeter) and member
functions
ALGORITHMS
Step 1: Create class square with data members( length, area and perimeter) and member
functions ( read() , compute() and display())
Step 2: Create an object using class square
Step 3: Using object call the member functions read(), compute() and display()
import java.util.Scanner;
class SquareAreaDemo {
public static void main (String[] args)
{
System.out.println("Enter Side of Square:");
//Capture the user's input
Scanner scanner = new Scanner(System.in);
//Storing the captured value in a variable
double side = scanner.nextDouble();
//Area of Square = side*side
double area = side*side;
double peri=side*4;
double length=side+2;
System.out.println("Area of Square is: "+area);
System.out.println("Perimeter of Square is: "+peri);
System.out.println("lenght of Square is: "+length);
}
}
output
3
BY O.W.O
4. WAP to create a class with the parameterized constructor?
ALGORITHMS
Step 1: Create a class with necessary data members and member functions.
Step 2: Create a constructor with arguments.
Step 3: Within the main function create the objects and pass the values to the constructor.
code
class Example{
//Default constructor
Example(){
System.out.println("Default constructor");
}
Example (int i, int j){
System.out.print("parameterized constructor");
System.out.println(" with Two parameters");
}
Example(int i, int j, int k){
System.out.print("parameterized constructor");
System.out.println(" with Three parameters");
}
public static void main(String args[]){
//This will invoke default constructor
Example obj = new Example();
Example obj2 = new Example(12, 12);
Example obj3 = new Example(1, 2, 13);
}
}
Output
4
BY O.W.O
5. WAP to create and save a new text file .
ALGORITHMS
Step 1: Start the program.
Step 2: create class FileOutput.
Step 3: Read the number of bytes to be stored
Step 4: Use FileOutputStream to create a new file.
Step 5: Use the write function to write the contents to the file.
import java.io.*;
public class Trying
public static void main(String[] args) throws IOException {
String w = "Hello worldnhownarenyou";
FileWriter fw = new FileWriter("example.txt");
System.out.println("write to the file example.text-----");
fw.write(w);
System.out.println("writing complete");
fw.close();
System.out.println();
FileReader fr=new FileReader("example.txt");
BufferedReader b=new BufferedReader(fr);
System.out.println("Reading the file example.txt-----");
while((w=b.readLine())!=null){
System.out.println(w);
}
fr.close();
System.out.println("Reading end");
}
}
OUTPUT
5
BY O.W.O
6. Write a program that illustrates the multilevel inheritance in java.
Algorithm:
Step 1: Create a class A
Step 2: Create another class B which derives from A using extends keyword
Step 3: Create another class C, which derives from B using, extends keyword.
Step 4: Create objects that can able to call the member functions of all the above classes from
the third class C.
CODE
class Person {
String name,address;
int age;
void personalDetails(String nm,int ag,String add) {
name = nm;
age = ag;
address =add;
}
void displaydetail() {
System.out.println("Name:"+name);
System.out.println("Age:"+age);
System.out.println("Address:"+address);
}
}
class employee extends Person {
int empid,salary;
void empdetails(int id,int sal) {
empid=id;
salary=sal;
}
void displayemployee() {
System.out.println("Employee ID"+empid);
System.out.println("Salary"+salary); }
}
interface bonus {
int bonus=1000;
void compute();
class worker extends employee implements bonus {
int amount;
public void compute() {
System.out.println("Bonus is :"+bonus);
amount=salary + bonus;
}
6
BY O.W.O
void workerdetails() {
displaydetail();
displayemployee();
compute();
System.out.println("Total Amount:"+amount); }
}
public class MultiIn {
public static void main(String[] args) {
worker obj = new worker();
obj.personalDetails("Dosh",25,"116,Tahiti");
obj.empdetails(101,2500);
obj.workerdetails(); }
}
Output:
Name: Dosh
Address: 116, Tahiti
Employee ID: 101
Salary: 2500
Bonus is 1000
Total Amount: 3500
7
BY O.W.O
7. Write a program that imports the user defined package and access the member
function of classes that are contained by the package.
Algorithm:
Step 1: Create a java program with data members and member functions.
Step 2: Package can be created by using package name;
Step 3: Save this in a separate folder
Step 4: Create another class outside the folder
Step 5: Import the package you created using import package name.
Step 6: Use the object to access the member function of that package class.
Code
package my_package;
public class Rate
{
public void firstresult()
{
System.out.println("This is first class results X-rated.");
}
}
import my_package.Rate;
class Bo
{
public static void main(String args[ ])
{
Rate obj= new Rate();
obj.firstresult();
}
}
Output:
This is first class results X-rated.
8
BY O.W.O
8. WAP that illustrates the exception handling concepts using try, catch and finally?
ALGORITHMS
Step 1: Write a program with necessary class name and functions.
Step 2: Write the code that are expected to cause error with in the try block.
Step 3: Write a catch block that can accept the error caused in try.
Step 4: Write some statements within finally block that are the statements to be executed
even when error occurred or not.
CODE
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class TryCatchFinally {
public static void main(String[] args) {
try { // main logic
System.out.println("Start of the main logic");
System.out.println("Try opening a file ...");
Scanner in = new Scanner(new File("test.in"));
System.out.println("File Found, processing the file ...");
System.out.println("End of the main logic");
} catch (FileNotFoundException ex) { // error handling separated from the main logic
System.out.println("File Not Found caught ...");
} finally { // always run regardless of exception status
System.out.println("finally-block runs regardless of the state of exception");
}
System.out.println("After try-catch-finally, life goes on...");
}
} OUTPUT
9
BY O.W.O
9. WAP to create a thread that implements the runnable interface
ALGORITHMS
Step 1: Create a class that implements the Runnable interface
Step 2: Call the run function and write a while loop that runs for certain condition
Step 3: Create another class runnable interface and write the main function
Step 4: Within the main function create the object for the first class
Step 5: Create an object for thread, pass the object created as an argument, and call the start
function.
Step 6: Execute the program to get the output.
code
class RunnableDemo implements Runnable {
private Thread t;
private String threadName;
RunnableDemo( String name){
threadName = name;
System.out.println("Creating " + threadName );
}
public void run() {
System.out.println("Running " + threadName );
try {
for(int i = 4; i > 0; i--) {
System.out.println("Thread: " + threadName + ", " + i);
// Let the thread sleep for a while.
Thread.sleep(50);
10
BY O.W.O
}
} catch (InterruptedException e) {
System.out.println("Thread " + threadName + " interrupted.");
}
System.out.println("Thread " + threadName + " exiting.");
}
public void start ()
{
System.out.println("Starting " + threadName );
if (t == null)
{
t = new Thread (this, threadName);
t.start ();
}
}
}
public class TestThread {
public static void main(String args[]) {
RunnableDemo R1 = new RunnableDemo( "Thread-1");
R1.start();
RunnableDemo R2 = new RunnableDemo( "Thread-2");
R2.start();
}
}
11
BY O.W.O
10. WAP to count the frequency of a given letter in a string.
ALGORITHMS
Step 1: Create a class that reads the a string value from keyboard
Step 2: Leave a prompt message that accepts the character whose frequency is to be found.
Step 3: Using an if statement compare that character with the char array and if found increase
the count of the character.
Step 4: Then display the message showing the total number of occurrences of that character.
CODE
import java.io.*;
class Frequency
{
static String n;
static int l;
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String : ");
n = br.readLine();
l = n.length();
freq();
}
12
BY O.W.O
public static void freq()
{
int s=0,f=-1;
for(int i=0;i<l;i++)
{
// Find frequecy
for(int j=0;j<l;j++)
{
if(n.charAt(i)==n.charAt(j))
s++;
}
// Check if the letter has occured before
for(int k=0;k<i;k++)
{
if(n.charAt(i)==n.charAt(k))
f = 1;
}
// Print the letter's frequency
if(f==-1)
System.out.println(n.charAt(i) +" = " +s);
s=0;
f=-1;
}
}
}
13
BY O.W.O
11. WAP to create a GUI which contains three labels, input box and a button. it should
perform the addition of two numbers entered in the input box when the button is clicked.
ALGORITHMS
Step 1: Import awt and applet package and the class must implements Actionlistener
interface.
Step 2: Create objects for Labels and Textboxes and Button
Step 3: Using add function add all the controls over the Applet.
Step 4: Use the addActionListener and actionPerformed function to perform the addition of
the values entered with in the textbox.
CODE
/*<applet code="ButtonAdd" height=200 width=200></applet>*/
import java.awt.*;
import java.applet.*;
import java.applet.Applet;
import java.awt.event.*;
public class ButtonAdd extends Applet implements ActionListener
{
Label title,fn,sn,res;
Button add;
TextField t1,t2,t3;
int x=0,y=0,z;
14
BY O.W.O
public void init()
{
title=new Label("Arithmetic operationn");
fn=new Label("First numbern");t1=new TextField(20);
sn=new Label("Second numbern");t2=new TextField(20);
res=new Label("Resultn");
t3=new TextField(20);
add=new Button("Add");
add.addActionListener(this);
add(title);add(fn);add(sn);add(res);add(t1);add(t2);add(t3);add(add);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==add)
{
x=Integer.parseInt(t1.getText());
y=Integer.parseInt(t2.getText());
z=x+y;
t3.setText(String.valueOf(z))
}
}
}
OUTPUT
15
BY O.W.O
16

More Related Content

What's hot

Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
Rabin BK
 
Chapitre 3 elements de base de java
Chapitre 3  elements de base de javaChapitre 3  elements de base de java
Chapitre 3 elements de base de java
Amir Souissi
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Java practical
Java practicalJava practical
Java practical
shweta-sharma99
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
Abu Zaman
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
aleenaguen
 
Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.
Meghaj Mallick
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Sachin Sharma
 
Void pointer in c
Void pointer in cVoid pointer in c
Void pointer in c
SANDIP MORADIYA
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
Koganti Ravikumar
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
Sunil OS
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
Victer Paul
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
Ilio Catallo
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: Arrays
Martin Chapman
 
Function
FunctionFunction
Function
jayesh30sikchi
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
ICS
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
Sets
SetsSets

What's hot (20)

Polymorphism in C++
Polymorphism in C++Polymorphism in C++
Polymorphism in C++
 
Chapitre 3 elements de base de java
Chapitre 3  elements de base de javaChapitre 3  elements de base de java
Chapitre 3 elements de base de java
 
Chap 9(functions)
Chap 9(functions)Chap 9(functions)
Chap 9(functions)
 
Java practical
Java practicalJava practical
Java practical
 
This pointer
This pointerThis pointer
This pointer
 
Presentation on function
Presentation on functionPresentation on function
Presentation on function
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.Pointer Basics,Constant Pointers & Pointer to Constant.
Pointer Basics,Constant Pointers & Pointer to Constant.
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Void pointer in c
Void pointer in cVoid pointer in c
Void pointer in c
 
Function in C
Function in CFunction in C
Function in C
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
C++ Standard Template Library
C++ Standard Template LibraryC++ Standard Template Library
C++ Standard Template Library
 
Programming in Java: Arrays
Programming in Java: ArraysProgramming in Java: Arrays
Programming in Java: Arrays
 
Function
FunctionFunction
Function
 
Best Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part IIIBest Practices in Qt Quick/QML - Part III
Best Practices in Qt Quick/QML - Part III
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Sets
SetsSets
Sets
 

Viewers also liked

Java programs
Java programsJava programs
Java programs
Mukund Gandrakota
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
Iram Ramrajkar
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
Soumya Behera
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
Tareq Hasan
 
Java codes
Java codesJava codes
Java codes
Hussain Sherwani
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
Mumbai Academisc
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
Garuda Trainings
 

Viewers also liked (8)

Java programs
Java programsJava programs
Java programs
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Java: Java Applets
Java: Java AppletsJava: Java Applets
Java: Java Applets
 
Java codes
Java codesJava codes
Java codes
 
Java programming-examples
Java programming-examplesJava programming-examples
Java programming-examples
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 

Similar to Java practical

Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
Java programs
Java programsJava programs
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Ayes Chinmay
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
Lab4
Lab4Lab4
srgoc
srgocsrgoc
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
Soumya Behera
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
sameer farooq
 
Java programs
Java programsJava programs
Java programs
jojeph
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
Java file
Java fileJava file
Java file
simarsimmygrewal
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
jagriti srivastava
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
Srinivasa Babji Josyula
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
Srinivasa Babji Josyula
 
Thread
ThreadThread
Thread
phanleson
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
anupamfootwear
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
Khurshid Asghar
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34
myrajendra
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
mustkeem khan
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 

Similar to Java practical (20)

Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Java programs
Java programsJava programs
Java programs
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Lab4
Lab4Lab4
Lab4
 
srgoc
srgocsrgoc
srgoc
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
Java programs
Java programsJava programs
Java programs
 
Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
39927902 c-labmanual
39927902 c-labmanual39927902 c-labmanual
39927902 c-labmanual
 
Thread
ThreadThread
Thread
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
 
Runnable interface.34
Runnable interface.34Runnable interface.34
Runnable interface.34
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 

Recently uploaded

An Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise IntegrationAn Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise Integration
Safe Software
 
Chapter 5 - Managing Test Activities V4.0
Chapter 5 - Managing Test Activities V4.0Chapter 5 - Managing Test Activities V4.0
Chapter 5 - Managing Test Activities V4.0
Neeraj Kumar Singh
 
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDBScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB
 
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
dipikamodels1
 
Fuxnet [EN] .pdf
Fuxnet [EN]                                   .pdfFuxnet [EN]                                   .pdf
Fuxnet [EN] .pdf
Overkill Security
 
Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2
DianaGray10
 
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc
 
Day 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data ManipulationDay 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data Manipulation
UiPathCommunity
 
Introduction to ThousandEyes AMER Webinar
Introduction  to ThousandEyes AMER WebinarIntroduction  to ThousandEyes AMER Webinar
Introduction to ThousandEyes AMER Webinar
ThousandEyes
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
Ortus Solutions, Corp
 
An All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS MarketAn All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS Market
ScyllaDB
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
Mydbops
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
Tobias Schneck
 
New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024
ThousandEyes
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
Guidelines for Effective Data Visualization
Guidelines for Effective Data VisualizationGuidelines for Effective Data Visualization
Guidelines for Effective Data Visualization
UmmeSalmaM1
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
Kieran Kunhya
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
AlexanderRichford
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 

Recently uploaded (20)

An Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise IntegrationAn Introduction to All Data Enterprise Integration
An Introduction to All Data Enterprise Integration
 
Chapter 5 - Managing Test Activities V4.0
Chapter 5 - Managing Test Activities V4.0Chapter 5 - Managing Test Activities V4.0
Chapter 5 - Managing Test Activities V4.0
 
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDBScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
ScyllaDB Leaps Forward with Dor Laor, CEO of ScyllaDB
 
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
Call Girls Kochi 💯Call Us 🔝 7426014248 🔝 Independent Kochi Escorts Service Av...
 
Fuxnet [EN] .pdf
Fuxnet [EN]                                   .pdfFuxnet [EN]                                   .pdf
Fuxnet [EN] .pdf
 
Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2Communications Mining Series - Zero to Hero - Session 2
Communications Mining Series - Zero to Hero - Session 2
 
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
TrustArc Webinar - Your Guide for Smooth Cross-Border Data Transfers and Glob...
 
Day 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data ManipulationDay 4 - Excel Automation and Data Manipulation
Day 4 - Excel Automation and Data Manipulation
 
Introduction to ThousandEyes AMER Webinar
Introduction  to ThousandEyes AMER WebinarIntroduction  to ThousandEyes AMER Webinar
Introduction to ThousandEyes AMER Webinar
 
Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!Introducing BoxLang : A new JVM language for productivity and modularity!
Introducing BoxLang : A new JVM language for productivity and modularity!
 
An All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS MarketAn All-Around Benchmark of the DBaaS Market
An All-Around Benchmark of the DBaaS Market
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - MydbopsMySQL InnoDB Storage Engine: Deep Dive - Mydbops
MySQL InnoDB Storage Engine: Deep Dive - Mydbops
 
Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!Containers & AI - Beauty and the Beast!?!
Containers & AI - Beauty and the Beast!?!
 
New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024New ThousandEyes Product Features and Release Highlights: June 2024
New ThousandEyes Product Features and Release Highlights: June 2024
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
Guidelines for Effective Data Visualization
Guidelines for Effective Data VisualizationGuidelines for Effective Data Visualization
Guidelines for Effective Data Visualization
 
Multivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back againMultivendor cloud production with VSF TR-11 - there and back again
Multivendor cloud production with VSF TR-11 - there and back again
 
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
QR Secure: A Hybrid Approach Using Machine Learning and Security Validation F...
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 

Java practical

  • 1. BY O.W.O 1. WAP to find the average and sum of N numbers using command line argument. ALGORITHMS Step 1: Start and Pass the values through command line Step 2: Convert the values to integer Step 3: Find the sum and average Step 4: Display the results. Step 5: End the program. Program Code class CommandArg { public static void main(String arg[]) { int i,n; double sum=0,Avg; n=Integer.parseInt(arg[0]); for(i=1;i<=n;i++) { sum=sum+Double.parseDouble(arg[i]); } Avg=sum/n; System.out.println ("The Sum is"+ sum); System.out.println ("The Average is"+ Avg); } } Output: Java CommandArg 2 6 4 The Sum is 10 The Average is 5 1
  • 2. BY O.W.O 2. Create a class student and read and display the details using member function ALGORITHMS Step 1: Create a class student with read and display the details using member function. Step 2: Create the class student with data members (name, rollno, batch) and member functions (read(), display() ). Step 3: Create an object using class student. Step 4: Using object call the functions read () and display (). code class Student { String stName; int stAge; void initialize() { stName="loguk pa gwanyank"; stAge=23; } void display() { System.out.println("Student name:" +stName); System.out.println("Student Age:" +stAge); } public static void main(String []args){ objStudent = new Student(); objStudent.initialize(); objStudent.display(); } } OUTPUT 2
  • 3. BY O.W.O 3. Create class square with data members( length, area and perimeter) and member functions ALGORITHMS Step 1: Create class square with data members( length, area and perimeter) and member functions ( read() , compute() and display()) Step 2: Create an object using class square Step 3: Using object call the member functions read(), compute() and display() import java.util.Scanner; class SquareAreaDemo { public static void main (String[] args) { System.out.println("Enter Side of Square:"); //Capture the user's input Scanner scanner = new Scanner(System.in); //Storing the captured value in a variable double side = scanner.nextDouble(); //Area of Square = side*side double area = side*side; double peri=side*4; double length=side+2; System.out.println("Area of Square is: "+area); System.out.println("Perimeter of Square is: "+peri); System.out.println("lenght of Square is: "+length); } } output 3
  • 4. BY O.W.O 4. WAP to create a class with the parameterized constructor? ALGORITHMS Step 1: Create a class with necessary data members and member functions. Step 2: Create a constructor with arguments. Step 3: Within the main function create the objects and pass the values to the constructor. code class Example{ //Default constructor Example(){ System.out.println("Default constructor"); } Example (int i, int j){ System.out.print("parameterized constructor"); System.out.println(" with Two parameters"); } Example(int i, int j, int k){ System.out.print("parameterized constructor"); System.out.println(" with Three parameters"); } public static void main(String args[]){ //This will invoke default constructor Example obj = new Example(); Example obj2 = new Example(12, 12); Example obj3 = new Example(1, 2, 13); } } Output 4
  • 5. BY O.W.O 5. WAP to create and save a new text file . ALGORITHMS Step 1: Start the program. Step 2: create class FileOutput. Step 3: Read the number of bytes to be stored Step 4: Use FileOutputStream to create a new file. Step 5: Use the write function to write the contents to the file. import java.io.*; public class Trying public static void main(String[] args) throws IOException { String w = "Hello worldnhownarenyou"; FileWriter fw = new FileWriter("example.txt"); System.out.println("write to the file example.text-----"); fw.write(w); System.out.println("writing complete"); fw.close(); System.out.println(); FileReader fr=new FileReader("example.txt"); BufferedReader b=new BufferedReader(fr); System.out.println("Reading the file example.txt-----"); while((w=b.readLine())!=null){ System.out.println(w); } fr.close(); System.out.println("Reading end"); } } OUTPUT 5
  • 6. BY O.W.O 6. Write a program that illustrates the multilevel inheritance in java. Algorithm: Step 1: Create a class A Step 2: Create another class B which derives from A using extends keyword Step 3: Create another class C, which derives from B using, extends keyword. Step 4: Create objects that can able to call the member functions of all the above classes from the third class C. CODE class Person { String name,address; int age; void personalDetails(String nm,int ag,String add) { name = nm; age = ag; address =add; } void displaydetail() { System.out.println("Name:"+name); System.out.println("Age:"+age); System.out.println("Address:"+address); } } class employee extends Person { int empid,salary; void empdetails(int id,int sal) { empid=id; salary=sal; } void displayemployee() { System.out.println("Employee ID"+empid); System.out.println("Salary"+salary); } } interface bonus { int bonus=1000; void compute(); class worker extends employee implements bonus { int amount; public void compute() { System.out.println("Bonus is :"+bonus); amount=salary + bonus; } 6
  • 7. BY O.W.O void workerdetails() { displaydetail(); displayemployee(); compute(); System.out.println("Total Amount:"+amount); } } public class MultiIn { public static void main(String[] args) { worker obj = new worker(); obj.personalDetails("Dosh",25,"116,Tahiti"); obj.empdetails(101,2500); obj.workerdetails(); } } Output: Name: Dosh Address: 116, Tahiti Employee ID: 101 Salary: 2500 Bonus is 1000 Total Amount: 3500 7
  • 8. BY O.W.O 7. Write a program that imports the user defined package and access the member function of classes that are contained by the package. Algorithm: Step 1: Create a java program with data members and member functions. Step 2: Package can be created by using package name; Step 3: Save this in a separate folder Step 4: Create another class outside the folder Step 5: Import the package you created using import package name. Step 6: Use the object to access the member function of that package class. Code package my_package; public class Rate { public void firstresult() { System.out.println("This is first class results X-rated."); } } import my_package.Rate; class Bo { public static void main(String args[ ]) { Rate obj= new Rate(); obj.firstresult(); } } Output: This is first class results X-rated. 8
  • 9. BY O.W.O 8. WAP that illustrates the exception handling concepts using try, catch and finally? ALGORITHMS Step 1: Write a program with necessary class name and functions. Step 2: Write the code that are expected to cause error with in the try block. Step 3: Write a catch block that can accept the error caused in try. Step 4: Write some statements within finally block that are the statements to be executed even when error occurred or not. CODE import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class TryCatchFinally { public static void main(String[] args) { try { // main logic System.out.println("Start of the main logic"); System.out.println("Try opening a file ..."); Scanner in = new Scanner(new File("test.in")); System.out.println("File Found, processing the file ..."); System.out.println("End of the main logic"); } catch (FileNotFoundException ex) { // error handling separated from the main logic System.out.println("File Not Found caught ..."); } finally { // always run regardless of exception status System.out.println("finally-block runs regardless of the state of exception"); } System.out.println("After try-catch-finally, life goes on..."); } } OUTPUT 9
  • 10. BY O.W.O 9. WAP to create a thread that implements the runnable interface ALGORITHMS Step 1: Create a class that implements the Runnable interface Step 2: Call the run function and write a while loop that runs for certain condition Step 3: Create another class runnable interface and write the main function Step 4: Within the main function create the object for the first class Step 5: Create an object for thread, pass the object created as an argument, and call the start function. Step 6: Execute the program to get the output. code class RunnableDemo implements Runnable { private Thread t; private String threadName; RunnableDemo( String name){ threadName = name; System.out.println("Creating " + threadName ); } public void run() { System.out.println("Running " + threadName ); try { for(int i = 4; i > 0; i--) { System.out.println("Thread: " + threadName + ", " + i); // Let the thread sleep for a while. Thread.sleep(50); 10
  • 11. BY O.W.O } } catch (InterruptedException e) { System.out.println("Thread " + threadName + " interrupted."); } System.out.println("Thread " + threadName + " exiting."); } public void start () { System.out.println("Starting " + threadName ); if (t == null) { t = new Thread (this, threadName); t.start (); } } } public class TestThread { public static void main(String args[]) { RunnableDemo R1 = new RunnableDemo( "Thread-1"); R1.start(); RunnableDemo R2 = new RunnableDemo( "Thread-2"); R2.start(); } } 11
  • 12. BY O.W.O 10. WAP to count the frequency of a given letter in a string. ALGORITHMS Step 1: Create a class that reads the a string value from keyboard Step 2: Leave a prompt message that accepts the character whose frequency is to be found. Step 3: Using an if statement compare that character with the char array and if found increase the count of the character. Step 4: Then display the message showing the total number of occurrences of that character. CODE import java.io.*; class Frequency { static String n; static int l; public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter a String : "); n = br.readLine(); l = n.length(); freq(); } 12
  • 13. BY O.W.O public static void freq() { int s=0,f=-1; for(int i=0;i<l;i++) { // Find frequecy for(int j=0;j<l;j++) { if(n.charAt(i)==n.charAt(j)) s++; } // Check if the letter has occured before for(int k=0;k<i;k++) { if(n.charAt(i)==n.charAt(k)) f = 1; } // Print the letter's frequency if(f==-1) System.out.println(n.charAt(i) +" = " +s); s=0; f=-1; } } } 13
  • 14. BY O.W.O 11. WAP to create a GUI which contains three labels, input box and a button. it should perform the addition of two numbers entered in the input box when the button is clicked. ALGORITHMS Step 1: Import awt and applet package and the class must implements Actionlistener interface. Step 2: Create objects for Labels and Textboxes and Button Step 3: Using add function add all the controls over the Applet. Step 4: Use the addActionListener and actionPerformed function to perform the addition of the values entered with in the textbox. CODE /*<applet code="ButtonAdd" height=200 width=200></applet>*/ import java.awt.*; import java.applet.*; import java.applet.Applet; import java.awt.event.*; public class ButtonAdd extends Applet implements ActionListener { Label title,fn,sn,res; Button add; TextField t1,t2,t3; int x=0,y=0,z; 14
  • 15. BY O.W.O public void init() { title=new Label("Arithmetic operationn"); fn=new Label("First numbern");t1=new TextField(20); sn=new Label("Second numbern");t2=new TextField(20); res=new Label("Resultn"); t3=new TextField(20); add=new Button("Add"); add.addActionListener(this); add(title);add(fn);add(sn);add(res);add(t1);add(t2);add(t3);add(add); } public void actionPerformed(ActionEvent e) { if(e.getSource()==add) { x=Integer.parseInt(t1.getText()); y=Integer.parseInt(t2.getText()); z=x+y; t3.setText(String.valueOf(z)) } } } OUTPUT 15
  翻译: