Nipiduvojefudimoxoxeseriv

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Advanced java programs examples with output pdf free download

Java programs examples pdf: Exploring java programs from basic to advanced can be done via this ultimate BTech Geeks Java Programming Examples tutorial. An excellent way to learn this most effective java programming language is by practicing all these java programs. The following core java programs for beginners & experienced developers are
tested and provided with output for better learnings and practice.

Java Programmers who wish to upskill their programming skills should start practicing the best java programs. Here’s the new collection list of basic java programs for beginners and experienced java programmers. Not only the java programs examples but also the article provides the following information for more exploration about the java
program. They are: Java Basic Programs Java Basic Programs Pdf Java Programs Pdf All Java Programs Pdf Core Java Programs Pdf Java Code Examples Pdf Java Solved Programs Pdf Java Example Programs Pdf Java Programming Examples Pdf Java Programs For Practice Pdf Simple Java Programs For Beginners Pdf Basic Java Programs For
Beginners Pdf Top 100 Java Programs Pdf 100 Java Programs With Output Pdf Java Programs Examples With Output Java Programs Examples With Output Pdf 1000 Java Programs Pdf 1000 Java Programs Java 1000 Programs 1000 Java Programs Pdf Free Downloands. List of 1000+ Simple Java Programming Examples for Beginners Java Basic
Programs for Beginners | Basic Core Java Programs for Interview Java Decision Making and Loop Programming Examples Java Star Pattern Programs Java Number Pattern Programs Java Character pattern Programs Java Type Conversion Programs Java Geometrical Calculation Program Java Number Conversion Programs Java Number Programs Java
Matrix Programs Java Array Programs Java ArrayList Programs Java Vector Programs Java Singly Linked List Programs Java LinkedList Programs Java Functions Programs Java Program to Display Prime Numbers Between Intervals Using Function Java Program to Display Armstrong Numbers Between Intervals Using Function Java Program to Check
Whether a Number can be Expressed as Sum of Two Prime Numbers Java Program to Convert Binary Number to Decimal and vice-versa Java Program to Convert Octal Number to Decimal and vice-versa Java Program to Convert Binary Number to Octal and vice-versa Java Program to Call One Constructor from another Java Program to implement
private constructors Java Program to pass lambda expression as a method argument Java Program to pass method call as arguments to another method Java Program to Calculate the Execution Time of Methods Java Data Types With Examples Data Types in Java Java boolean Data Type with Example Java char Data Type with Example Java byte Data
Type with Example Java short Data Type with Example Java int Data Type with Example Java long Data Type with Example Java float Data Type with Example Java double Data Type with Example Java Non Premitive Data Type with Example Java Operators With Examples Java Class and Object Programs | Object and Class Java Programming Examples
Java Program to Calculate Difference Between Two Time Periods Java Program to Determine the class of an object Java Program to Create an enum class Java Program to Print object of a class Java Program to Create custom exception Java Program to Create an Immutable Class Java Program to Create a Class and Object Java Program to Create
Abstract Class Java Program to Create Singleton Class Java Program to Create an Interface Java Program to Sow Encapsulation in Class Java Program to Show Inheritance in Class Java Program to Show Abstraction in Class Java Program to Show Data Hiding in Class Java Program to Show Polymorphism in Class Java Program to Show Overloading of
Methods in Class Java Program to Show Overriding of Methods in Classes Java Program to Show Use of Super Keyword in Class Java Program to Show Use of This Keyword in Class Java Program to Show Usage of Static keyword in Class Java Program to Show Usage of Access Modifier Java Character Programs Java String Programs Java Network
Programs Java Miscellaneous Programs Java Collections Programs Java Program to Join Two Lists Java Program to Convert the ArrayList to an array and vice versa Java Program to Convert Map (HashMap) to List Java Program to Convert Array to Set (HashSet) and Vice-Versa Java Program to Sort a Map By Values Java Program to Sort ArrayList of
Custom Objects By Property Java Program to Implement LinkedList Java Program to Implement stack data structure Java Program to Implement the queue data structure Java Program to Get the middle element of LinkedList in a single iteration Java Program to Convert the LinkedList into an Array and vice versa Java Program to Convert the
ArrayList into a string and vice versa Java Program to Iterate over an ArrayList Java Program to Iterate over a HashMap Java Program to Iterate over a Set Java Program to Merge two lists Java Program to Update value of HashMap using key Java Program to Remove duplicate elements from ArrayList Java Program to Get key from HashMap using the
value Java Program to Detect loop in a LinkedList Java Program to Calculate union of two sets Java Program to Calculate the intersection of two sets Java Program to Calculate the difference between two sets Java Program to Check if a set is the subset of another set Java Program to Sort map by keys Java Program to Pass ArrayList as the function
argument Java Program to Iterate over ArrayList using Lambda Expression Java Program to Implement Binary Tree Data Structure Java Program to Perform the preorder tree traversal Java Program to Perform the postorder tree traversal Java Program to Perform the inorder tree traversal Java Program to Count number of leaf nodes in a tree Java
Program to Implement the graph data structure Java Program to Remove elements from the LinkedList. Java Program to Add elements to a LinkedList Java Program to Access elements from a LinkedList. Java Program to Use Different Types of a Collection Java Program to Print a Collection Java Program to Get the Size of the Collection Java Program
to Compare Elements in a Collection Java Program to Shuffle the Elements of a Collection Java Program to Reverse a Collection Java Program to Convert Collection into Array Java Program to Convert Array into Collection Java Program to Replace Elements in a List Java Program to Rotate Elements of a List Java Program to Iterate through Elements
of HashMap Java Algorithms Programs Java Program to Implement Bubble Sort algorithm Java Program to Implement Quick Sort Algorithm Java Program to Implement Merge Sort Algorithm Java Program to Implement Binary Search Algorithm Java Files Programs Java Program to Get the File Size Java Program to Create and Write into File Java
Program to Create a File and Write into the File Java Program to Delete a File Java Program to Get Current Working Directory Java Program to Create String from Contents of a File Java Program to Append Text to an Existing File Java Program to Convert File to byte array and Vice-Versa Java Program to Create Directories Java Program to Rename
File Java Program to Get all Files Present in a Directory Java Program to Copy File Java Program to Create File and Write to the File Java Program to Read the Content of a File Line by Line Java Program to Delete File in Java Java Program to Delete Empty and Non-empty Directory Java Program to Get the File Extension Java Program to Get the name
of the file from the absolute path Java Program to Get the relative path from two absolute paths Java Program to Count Number of lines present in the file Java Program to Create a temporary file Java Program to Make a File Read-Only Java Program to Compare Paths of Two files Java Program to Copy one file into another file Java Program to Print all
the Pattern that Matches Given Pattern From a File Java Program to Append a String in an Existing File Java Program to Read content from one file and writing it into another file Java Program to Read and printing all files from a zip file Java I/O Stream Programs Java Program to Convert InputStream to String Java Program to Convert OutputStream
to String Java Program to Convert a String into the InputStream Java Program to Convert the InputStream into Byte Array Java Program to Load File as InputStream Java Method Programs Java Program to Show Usage of Main() method Java Program to Show Use of Static and Non-static Methods Java Program to Show Usage of forEach() Method Java
Program to Show Usage of toString() Method Java Program to Show Usage of codePointAt() Method Java Program to Show Usage of compare() Method Java Program to Show Usage of equals() Method Java Program to Show Usage of hasNext() and next() Method Thread Lifecycle Methods start() Method run() Method Java Searching Programs Java
Program to Search an Element in an Array using Linear Search Java Program For Linear Search Java Program For Binary Search Java Program to Recursively Linearly Search an Element in an Array Java List Programs Java Program to Initializing a List Java Program to Find a Sublist in a List Java Program to Get Minimum and Maximum From a List
Java Program to Split a list into Two Halves Java Program to Remove a Sublist from a List Java Program to Remove Duplicates from an Array List Java Program to Remove Null from a List container Java Program to Sort Array list in an Ascending Order Java Program to Get First and Last Elements from an Array List Java Program to Convert a List of
String to Comma Separated String Java Program to Add Element at First and Last Position of a Linked list Java Program to Find Common Elements in Two ArrayList Java Program to Remove Repeated Element From An ArrayList Java Date and Time Programs LocalDate Class Programs: Java Directory Programs Java Program to Traverse in a directory
Java Program to Get the size of a directory Java Program to Delete a directory Java Program to Create directories recursively Java Program to Search for a file in a directory Java Program to Find the current working directory Java Program to Display all the directories in a directory Java Exceptions and Errors Programs Java Program to Show Runtime
exceptions Java Program to Show Types of errors Java Program to Handle the Exception Hierarchies Java Program to Handle the Exception Methods Java program to Handle the Checked exceptions Java Program to Handle the Unchecked Exceptions Java Program to Handle Divide By Zero and Multiple Exceptions Java Program to Show Unreachable
Code Error Java Program to Show Thread interface and memory consistency errors Java Multithreading Programs Java Program to Check the Thread Status Java Program to Suspend a Thread Java Program to Join Threads Java Program to Show Daemon Thread Java Examples on Mathematical Calculations Java Unit Conversion Program LENGTH:
AREA: TEMPERATURE TIME WEIGHT VOLUME Java Program to Convert Milliliter to Liter and Vice versa Java Program to Convert Cubic Meter to Cubic Centimeter and Cubic Centimeter to Cubic Meter Java Program to Convert Cubic Mile to Cubic Kilometer and Cubic Kilometer to Cubic Mile Java Program to Convert Cubic Foot to Cubic Inch and
Cubic Inch to Cubic Foot Java Program to Convert Cubic Yard to Cubic Foot and Cubic Foot to Cubic Yard SPEED DATA ENERGY POWER Java Algebraic Formula Program Java Program to Compute (a+b)2 where Value of a and b are Given Java Program to Compute (a-b)2 where Value of a and b are Given Java Program to Compute (a+b)3 where
Value of a and b are Given Java Program to Compute (a-b)3 where Value of a and b are Given Java Program to Compute (a+b)4 where Value of a and b are Given Java Program to Compute (a-b)4 where Value of a and b are Given Java Program to Compute a2+b2 where Value of a and b are Given Java Program to Compute a2-b2 where Value of a and b
are Given Java Program to Compute a3+b3 where Value of a and b are Given Java Program to Compute a3-b3 where Value of a and b are Given Java Program to Compute a4+b4 where Value of a and b are Given Java Program to Compute a4-b4 where Value of a and b are Given Java Program to Compute a5+b5 where Value of a and b are Given Java
Program to Compute a5-b5 where Value of a and b are Given Java Program to Compute a8-b8 where Value of a and b are Given Java Program to Compute (a+b+c)2 where Value of a, b and c are Given Java Program to Compute (a+b-c)2 where Value of a, b and c are Given Java Program to Compute (a-b+c)2 where Value of a, b and c are Given Java
Program to Compute (-a+b+c)2 where Value of a, b and c are Given Java Program to Compute (-a-b+c)2 where Value of a, b and c are Given Java Program to Compute (-a+b-c)2 where Value of a, b and c are Given Java Program to Compute (a-b-c)2 where Value of a, b and c are Given Java Program to Compute (a+b+c)3 where Value of a, b and c are
Given Java Program to Compute (a2+b2+c2) where Value of a, b and c are Given Java Program to Compute 2(ab+bc+ca) where Value of a, b and c are Given Java Program to Compute an-bn when n is a natural number Java Program to Compute an+bn when n is even number (n=2k) Java Program to Compute an+bn when n is odd number (n=2k+1)
Java Program to Compute 2(a2+b2) where Value of a and b are Given Java Program to Compute a3+b3+c3-3abc where Value of a, b and c are Given Java Program to Compute a3+b3-c3+3abc where Value of a, b and c are Given Java Program to Compute a3-b3-c3-3abc where Value of a, b and c are Given Java Program to Compute a3-b3+c3+3abc
where Value of a, b and c are Given Java Program to Compute a4+a2b2+b4 where Value of a and b are Given Java Program to Compute a4+a2+1 where Value of a and b are Given Java Program to Compute a^m*a^n where Value of a, m and n are Given Java Program to Compute a^m/a^n where Value of a, m and n are Given Java Program to
Compute (a^m)^n where Value of a, m and n are Given Java Program to Compute (ab)x where Value of a, b and x are Given Java Program to Compute (a/b)x where Value of a, b and x are Given Java Program to Compute (a)^1/x where Value of a, b and x are Given Java Program to Compute (a+b)2+(a-b)2 where Value of a and b are Given Java
Program to Compute (a+b)2-(a-b)2 where Value of a and b are Given Java Program to Compute (x+a)(x+b) where Value of x, a and b are Given Java Program to Compute (x+a)(x-b) where Value of x, a and b are Given Java Program to Compute (x-a)(x+b) where Value of x, a and b are Given Java Program to Compute (x-a)(x-b) where Value of x, a and b
are Given Java Program to Compute (x+p)(x+q)(x+r) where Value of x, p, q and r are Given Java Program to Compute x2+y2+z2-xy-yz-zx where Value of x, y and z are Given Java Program to Compute (b-c)+(c-a)+(a-b) where Value of a, b and c are Given Java Program to Compute a(b-c)+b(c-a)+c(a-b) where Value of a, b and c are Given Java Program
to Compute (b-c)2+(c-a)2+(a-b)2 where Value of a, b and c are Given Java Program to Compute a2(b-c)+b2(c-a)+c2(a-b) where Value of a, b and c are Given Java Program to Compute bc(b-c)+ca(c-a)+ab(a-b) where Value of a, b and c are Given Java Program to Compute a(b2-c2)+b(c2-a2)+c(a2-b2) where Value of a, b and c are Given Java Program to
Compute a3(b-c)+b3(c-a)+c3(a-b) where Value of a, b and c are Given Java Program to Compute (b+c)(c+a)(a+b) where Value of a, b and c are Given Java Program to Compute (a+b+c)(b+c-a)(c+a-b)(a+b-c) where Value of a, b and c are Given Java Program to Compute (a+b+c)(bc+ca+ab)-abc where Value of a, b and c are Given Java Program to
Compute a-n where Value of a and n are Given Java Program to Compute a0 where Value of a is Given Java Series Program Java Simple Programs on Special Numbers Java Program to Print Armstrong Number from 1 to 1000 Java Program to Check if a Given Number is Perfect Number Java Program to Check If a Given Number is Armstrong Number
Java Program to Check if a Given Number is Prime Number Java Program to Find Sum of Natural Numbers Using While Loop Java Program to Calculate the Sum, Multiplication, Division and Subtraction of Two Numbers Java Program to Print the Next 20 Leap Years Java Program to Print the First Twenty Perfect Squares Java Program to Input a
String with at least One Number, Print the Square of all the Numbers in a String Java Programming Examples on Fibonacci and Complex Numbers Java Program to Display Fibonacci Series Java Program to Print Fibonacci Series in Different Ways Java Program to Generate Fibonacci Numbers Java Program to Compute List of First 100 Fibonacci
Numbers Java Program to Add two Complex Numbers Java Program to Add Two Complex Numbers by Passing Class to a Function Java Examples on Recursion Java Data Types Programming Examples Java Program to Check Whether an Alphabet is Vowel or Consonant Java Program to Check if given Alphabets are Uppercase or Lowercase or Digits
Java Program to Illustrate Use of Binary Literals Java Program to Use Underscores in Numeric Literal Java Program to Illustrate the Usage of Decimal Integer, Octal Integer, HexaDecimal, Floating, Character Literals Java Program to Store Escape Sequence and Unicode Characters Using Character Literals Java Program to Perform Binary Addition of
Strings Java Special Programs with Outputs Java Program to Print a Semicolon without Using a Semicolon Anywhere in the Code Java Program to Print any Statement without Using Semicolon Java Program to Accept the Height of a Person & Categorize as Taller, Dwarf & Average Java Program to Generate a DOT Representation of a Graph Java
Program to Automatically Generate Essays for You Java Examples on Delegation Event Model Java Program to Handle MouseEvent Java Program to Handle KeyBoardEvent Java Program on Handling Check Boxes Java Program to Get and Set State and Get Label of a Check Box Java Programming Examples on Handling a TextField Java Program to
Create 2 Labels and Text Fields for Entering Name and Secured Password Java Program to Display Text in the Frame by Overriding PaintComponent() Method of JPanel Class Java Program to Display Some Text in the Frame with the Help of a Label Java Program to Create a Text Area and Display the Mouse Event When the Button on the Mouse is
Clicked, When the Mouse is Moved etc is Done by the User Java Program to Create Some Text Fields and Text Areas to Demonstrate Features Java Program to Trap the Key Code and Key Name Typed by the User on the KeyBoard and Display them in a Text Area Java Program to Trap a Key Which is Pressed on the KeyBoard and Display its Name in
the Text Area. In this Program, We Consider Some Keys Only for Demonstration Purpose Java Programs on Menu Bars and Menus Java Program to Create a Menu with Several Menu Items Java Program to Create a Menu and Handle the File Open Event for the User Java Program to Perform Menu Driven Arithmetic Operations Using Switch Case Java
Program to Create a Choice Menu to Select an Item and Display it in the Frame Java Example Programs on Applet Class Java Program to Create a Basic Applet Java Program to Create a Banner Using Applet Java Program to Display Clock Using Applet Java Program to Create and Fill Shapes using Applet Java Program to Goto a Link using Applet Java
Program to Create an Event Listener in Applet Java Program to Display Image Using Applet Java Program to Open a Link in a New window using Applet Java Program to Play Sound Using Applet Java Program to Perform Read and Write Operations for a File using Applet Java Program to Use Swing Applet in JAVA Java Program to Demonstrate a Basic
Calculator using Applet Java Program to Display Human Face using Applet Java Program to Load and Display an Image Using Applet Java Program to Find Square of a Given Number Using Applet Java Program to Change the Background Colour of Applet by Clicking on Control Button Advanced Java Programs with Output Java Program to Get Current
Date/TIme Java Program to Convert Milliseconds to Minutes and Seconds Java Program to Add Two Dates Java Program to Convert Byte Array to Hexadecimal Java Program to Lookup enum by String value Java Program to Calculate simple interest and compound interest Java Program to Implement multiple inheritance Java Program to Determine the
name and version of the operating system Java Program to Check if two of three boolean variables are true Java Program to Iterate over enum Java Program to Check the birthday and print Happy Birthday message Java Program to Access private members of a class More Java Programs Java Program to Convert Linked list to an Array Java Program to
Convert Vector to a List Java Program to Convert String to a List of Characters Java Program to Convert Iterator to a List Java Program to Convert List to a Map Java Program to Convert List to a Stream Java Program to Convert List to Set Java Program to Convert Set of String to Array of String Java Program to Convert String to Object Java Program
to Convert string value to byte value 10 Simple Java Example Programs for Beginners & Experienced Programmers The following 10 simple java programming examples help beginners and expert programmers learn and practice the short logic of the program for quick usage and upskill your knowledge. Let’s check these basic yet most commonly
asked java programs in interviews: 1. ‘Hello World’ Java Program: One of the most important programs to learn by all developers is an introduction program to java by printing “Hello World” words. Also, check more details about Hello Word Program using Java from here.
2. Prime Number Program in Java: Out of this plenty of basic java programs list, the most commonly asked programming example in interviews or examinations is Prime Number Java Program. Here is the simple & one-line code for the prime number program. Want to learn more variations about Java Program to Check if a Given Number is Prime
Number? Make use of the link provided here. 3.
Fibonacci Series in Java: By using the following simple code, you can easily grasp the logic behind the Fibonacci series. If you really excited to learn the various methods like using recursion and without recursion check out this Java Program to Display Fibonacci Series 4. Factorial Using Java: Here, we have given a simple code for a factorial java
programming example. If you want to explore more about it then go for this Java Program to Find Factorial of a Number 5. Decimal to Binary Conversion in Java: Check out this shortcode to convert the decimal from binary and practice it regularly for quick usage in the required time of programming. In case, are you a newbie to java conversion
programming examples? then view this Java Program for Decimal to Binary Conversion. 6. Matrix Transpose Java Code: Are you searching for the one-line code to find the transpose of a matrix? then look at the below code. If you need to learn the same program in a detailed manner then click on this Java Program to Find a Transpose of a Matrix.

7. Armstrong Number in Java: Need a simple program to check whether the given number is Armstrong or not? then make use of the following code for quick reference. For perfect programming in java, practicing the basic Java Program on Check Armstrong Number. 8. Palindrome Number using Java: This simple line of code is helpful for checking
the given number is palindrome or not. If required to learn more about the logic behind it then tap on this Java Program to Check Palindrome. 9. String Comparison in Java: The code for the Java program to compare strings is prevailing here in a short form. If you want to practice more logic on string comparison like Java Program to compare two
strings check out the given link.
10. Sorting an Array Using Java: The best and effective way to understand the array sorting logic is by practicing with the given code. Also, you can check out the different methods by using this link ie., Java Program to Sort an Array. Final Words Hoping that our collection of basic and simple java programs for beginners and experienced
programmers helped everyone a lot in learning the java programming language faster. If want to suggest more core java programming examples with output from basic to advanced level, then reach out to us by commenting below and our expert developers will look into them. Click the Ctrl+D shortcut and bookmark our website BTechgeeks.com for
getting assistance on any programming languages like C++, Python, etc. JAVA PROGRAM EXAMPLE WITH OUTPUT PDF Created By: Umar Farooque Khan 1 Copyright © pTutorial · All Rights Reserved How to compile and run java programs Compile: - javac JavaFileName Run Java: - java JavaClassName Let’s take an example of java program:
//Hello.java class Hello { public static void main(String args[]) { System.out.println("Welcome to Java!"); } } Compile: - javac Hello.java Run Java: - java Hello 2 Copyright © pTutorial · All Rights Reserved Program No. – 01 Write a program to print hello in java. class Hello { public static void main(String args[]) { System.out.println("Welcome to
Java!"); } } 3 Copyright © pTutorial · All Rights Reserved Output:- 4 Copyright © pTutorial · All Rights Reserved Program No. – 02 Write a program for object and class in java. class Rectangle { privateintl,b; public void setDimension(intx,int y) { l=x; b=y; } publicint area() { return l*b; } public void display() { System.out.println("Length="+l);
System.out.println("Breadth="+b); } public static void main(String ac[]) { Rectangle r=new Rectangle(); r.setDimension(5,10); r.display(); System.out.println("Area="+r.area()); } } 5 Copyright © pTutorial · All Rights Reserved Output: 6 Copyright © pTutorial · All Rights Reserved Program No. – 03 Write a program to explain the concept of this
keyword in java. classThisTest { int id; String name; ThisTest(intid,String name) { this.id = id; this.name = name; } void display() { System.out.println(id+" "+name); } public static void main(String args[]) { ThisTest s1 = new ThisTest(142,"Shamshad"); ThisTest s2 = new ThisTest(452,"John"); s1.display(); s2.display(); } } 7 Copyright © pTutorial ·
All Rights Reserved Output:- 8 Copyright © pTutorial · All Rights Reserved Program No. – 04 Write a program to explain the concept of super keyword in java. class Bike { int speed=50; } class Super extends Bike { int speed=100; void display() { System.out.println(super.speed); } public static void main(String args[]) { Super b=new Super();
b.display(); } } 9 Copyright © pTutorial · All Rights Reserved Output: 10 Copyright © pTutorial · All Rights Reserved Program No. – 05 Write a program for overloading in java. class Overloading { void sum(inta,int b) { System.out.println(a+b); } void sum(double a,double b) { System.out.println(a+b); } public static void main(String args[]) {
Overloading obj=new Overloading(); obj.sum(10.5,10.5); obj.sum(20,20); } } 11 Copyright © pTutorial · All Rights Reserved Output: 12 Copyright © pTutorial · All Rights Reserved Program No. – 06 Write an abstract class program in java. public abstract class shape { public abstract void calculatearea(); } public class circle extends shape {
privateintx,y; privateint radius; public circle() { x=15; y=15; radius=10; } public void calculatearea () { double area=3.14*(radius*radius); 13 Copyright © pTutorial · All Rights Reserved System.out.println("area="+area); } } class test1 { public static void main(String arr[]) { shape s =null; s=new circle(); s.calculatearea(); } } 14 Copyright ©
pTutorial · All Rights Reserved Output: 15 Copyright © pTutorial · All Rights Reserved Program No. – 07 Write a program and analyse its output in java. class A { static { System.out.println("Initilizing a.."); } public A() { System.out.println("Constructor is called"); } } class B { staticint b; static { b=2; System.out.println("I am in class B"); } } class C {
static 16 Copyright © pTutorial · All Rights Reserved { System.out.println("I am in class C"); } public static void display() { System.out.println("Displayed method is called"); } } class D { static { System.out.println("I am in class D"); } public static void main(String arr[]) { System.out.println("main method"); A z=new A(); System.out.println("Class b is
called"+B.b); C.display(); System.out.println("helo!!"); A q=new A(); } } 17 Copyright © pTutorial · All Rights Reserved Output: 18 Copyright © pTutorial · All Rights Reserved Program No. – 08 Write an Interface program in java. public interface Speaker { public void speak(); } public class Lecturer implements Speaker { public void speak() {
System.out.println("Lecturer view"); } } public class Politician implements Speaker { public void speak() { System.out.println("Politician view"); } } 19 Copyright © pTutorial · All Rights Reserved public class Test { public static void main(String arr[]) { Speaker sp=null; System.out.println("sp point to politician"); sp=new Politician(); sp.speak();
System.out.println("sp point to Lecturer"); sp=new Lecturer(); sp.speak(); } } 20 Copyright © pTutorial · All Rights Reserved Output: 21 Copyright © pTutorial · All Rights Reserved Program No. – 09 Write a program for command line argument.
classCommandLineArgument { public static void main (String arr[]) { try { int a=Integer.parseInt(arr[0]); int b=Integer.parseInt(arr[1]); int sum=a+b; System.out.println("result is =" +sum); } catch(Exception e) { System.out.println(e); } } } 22 Copyright © pTutorial · All Rights Reserved Output: 23 Copyright © pTutorial · All Rights Reserved
Program No. – 10 Write a program for Handling an Exception In java. classExceptionHandling { public static void main(String arr[]) { try { int a=Integer.parseInt(arr[0]); int b=Integer.parseInt(arr[1]); int sum = a/b; System.out.println("Result:"+ sum); } catch(Exception e) { System.out.println(e); } } } 24 Copyright © pTutorial · All Rights Reserved
Output: 25 Copyright © pTutorial · All Rights Reserved Program No. – 11 Write a program to calculate square for a number using swing. importjava.awt.*; importjavax.swing.*; public class InputOutput { public static void main(String arr[]) { String input=JOptionPane.showInputDialog("Enter a number"); int number=Integer.parseInt(input); int
square=number*number; System.out.println("square = "+square); JOptionPane.showMessageDialog(null,"Square: " +square); System.exit(0); } } 26 Copyright © pTutorial · All Rights Reserved Output: 27 Copyright © pTutorial · All Rights Reserved Program No. – 12 Write a program for comparing two string in java. importjava.awt.*;
importjavax.swing.*; public class Inp { public static void main(String arr[]) { int i=4,j=5; System.out.println("hello :"+i); System.out.println(i+j); String S1=new String ("india"); String S2="india"; if(S1==S2) System.out.print("comparing String using++operator"); if(S1.equals(S2)) System.out.print("comparing String using equal method"); 28
Copyright © pTutorial · All Rights Reserved } } Output: 29 Copyright © pTutorial · All Rights Reserved Program No. – 13 Write a program to handling an action event in java. importjava.awt.*; importjava.awt.event.*; classAEvent extends Frame implements ActionListener { TextFieldtf; AEvent() { tf=new TextField(); tf.setBounds(60,50,170,20);
Button b=new Button("click me"); b.setBounds(100,120,80,30); b.addActionListener(this); add(b); add(tf); setSize(300,300); setLayout(null); setVisible(true); } 30 Copyright © pTutorial · All Rights Reserved public void actionPerformed(ActionEvent e) { tf.setText("Welcome"); } public static void main(String args[]) { newAEvent(); } } 31 Copyright ©
pTutorial · All Rights Reserved Output: 32 Copyright © pTutorial · All Rights Reserved Program No. – 14 Write a program for a Constructor in java.
class A { int a; public A(int x) { a=x; } public A() { System.out.println("it is default constructor"); } { System.out.println("it is funny"); } public void display() { System.out.println("a="+a); } public static void main(String arg[]) { A x=new A(); x.display(); A y=new A(10); y.display(); } } 33 Copyright © pTutorial · All Rights Reserved Output: 34
Copyright © pTutorial · All Rights Reserved Program No. – 15 Write an Applet program to show different-different shapes in java. importjava.applet.Applet; importjava.awt.*; public class GraphicsDemo extends Applet { public void paint(Graphics g) { g.setColor(Color.red); g.drawString("Welcome",50, 50); g.drawLine(20,30,20,300);
g.drawRect(70,100,30,30); g.fillRect(170,100,30,30); g.drawOval(70,200,30,30); g.setColor(Color.pink); g.fillOval(170,200,30,30); g.drawArc(90,150,30,30,30,270); 35 Copyright © pTutorial · All Rights Reserved g.fillArc(270,150,30,30,0,180); } } /* */ 36 Copyright © pTutorial · All Rights Reserved Output: For any suggestions or request mail me at
[email protected]. We will respond as soon as possible for better experience. 37 Copyright © pTutorial · All Rights Reserved

You might also like