Adv Java
Programming

1. What Is the Java Technology 2. Points to keep in mind for pyramid. 3. Java Pyramid Program on type 1 4. Java Pyramid Program on type 2 5. Java Pyramid Programs on Type 3 6. Java Pyramid Programs on type 4 7. Java Pyramid Programs on type 5 8. Classes and Objects 9. Recursive functions 10. Constructors in Java 11. Method Overloading 12. Constructor Overloading 13. Inheritance in Java 14. Interface in Java 15. Method Overriding and Hiding Method 16. The final keyword 17. Exception Handling 18. Properties, System & Runtime Class in Java 19. Building Java GUI 20. Layout Managers 21. Menu Bar 22. Applets 23. Threading 24. Java Netwoking 25. Programs for Science and Engineer 26. Prg to demonstrate pre and post increment 27. Prg to convert Farenheit to Celsius temperature 28. Prg to convert kilogram to different units 29. Prg to calculate surface area and volume of sphere 30. Prg to calculate frequency 31. Prg to determine co-ordinate points 32. Prg to determine Equilateral, Isosceles or Scalene triangle 33. Prg to demonstrate conditional operator 34. Prg to calculate Final and initial interest amount 35. Prg to separate entered number 36. Prg to examine while loops and conditions 37. Prg to calculate number of year 38. Prg to find Armstrong number or not 39. Prg to find all Armstrong number 40. Prg to find limited Armstrong number 41. Prg to find Armstrong number using user defined function 42. Prg to find frequency of student 43. Prg to find maximum and minimum number 44. Prg to print number triangle 45. Prg to print vertical number triangle 46. Prg to print number triangle 47. Prg to print binary right angle triangle 48. Prg to print * triangle 49. Prg to to print rhombus 50. Prg to print entered number triangle 51. Prg to to find nCr and nPr 52. Prg to enter an element in array 53. Prg to sort number using array 54. Prg to find the position of element in array 55. Prg to find the position of element in array using boolean flag 56. Prg to add one extra element in an array 57. Prg to find the equation of line 58. Prg to find the common element from two array 59. Prg to find the highest scorer 60. Prg to create a square of number 61. Prg to create Pascal triangle 62. Prg to subtraction, multiplication and division using methods and classes 63. Prg to determine salary grade 64. Prg for complex number 65. Prg to calculate area 66. Prg for Greatest Common Divisior 67. Prg for displaying studenta mark sheet 68. Prg for demonstrating inheritance 69. Prg to calculate area of triangle 70. Prg for calculating volume of sphere or hemisphere 71. Prg for demonstrate classes 72. Prg for employee details 73. Prg for demonstrating super and base class 74. Prg for Bank Account 75. Prg for professor and student details 76. Prg for Addition, Multiplication and finding Transpose of two matrix 77. Prg for counting number of words in a string 78. Prg to count number of vowels and consonants in a string 79. Prg to fine number of upper case, lower case, white spaces and digit in a string 80. Prg to fine number of upper case, lower case, white spaces and digit in a string without inbuilt function 81. Prg to arrange a string in alphabetic order 82. Prg to count the number of character occurrence in a string 83. Prg to find the string length and character position 84. Prg for converting first character of word into upper case 85. Prg for demonstrating vectors for manipulating records 86. Prg for manupulting items record using vectors 87. Prg for bank transaction 88. Prg for counting number of days between any two different date 89. Prg for exception handling 90. Prg for throwing exception 91. Prg for exception 92. Prg to throw exception when number is invalid 93. Prg for renaming the current thread 94. Prg for demonstrating strat method of thread 95. Prg to demonstrate sleep and and join method of thread 96. Prg to demonstrate yield method of thread 97. Prg for demonstrating thread in class inheritance 98. Threading program using runnable interface 99. Thread program using sleep 100. Java Applet program for creating fancy round eye 101. Java Applet program for creating fancy face 102. Java Applet program for drawing string 103. Java Applet program for creating fancy face 104. Java Applet program for displaying fancy fonts 105. Java Applet program for drawing and filling rectangle 106. Java Applet program for creating house 107. Java Applet program to show lifecycle of applet 108. Java Applet program for creating polygon 109. Java Applet program for creating rectangle 110. Java Applet program for drawing line 111. Java Applet program for getting applet width and height 112. Interview Question & Answer part 1 113. Interview Question & Answer part 2 114. Interview Question & Answer part 3 115. Interview Question & Answer part 4 116. Interview Question & Answer part 5 117. Interview Question & Answer part 6 118. Interview Question & Answer part 7 119. Interview Question & Answer part 8 120. Interview Question & Answer part 9 121. Interview Question & Answer part 10 122. Interview Question & Answer part 11
Pr.Pg Next Pg

Applets tutorials

  • Applets are small applications that are accessed on an Internet server, transported over the Internet, automatically installed, and run as part of a web document.

  • After an applet arrives on the client, it has limited access to resources so that it can produce a graphical user interface and run complex computations without introducing the risk of viruses or breaching data integrity.

  • Below is the simple applet demo:

 

 

Example: Java Simple Applet Demo for drawing a string

 Sam Madam

//Program name AppletDemo.java

// Java Simple Applet Demo for drawing a string

import java.awt.*;

import java.applet.*;

public class AppletDemo extends Applet

{

public void paint(Graphics g)

{

g.drawString("A Simple Applet", 20, 20);

}

}

Output

 

  • To execute an applet in a web browser, you need to write a short HTML text file that contains a tag that loads the applet. Currently, Sun recommends using the APPLET tag for this purpose. Here is the HTML file that executes Applet Demo:

<applet code="AppletDemo" width=200 height=60>

</applet>

  • The width and height statements specify the dimensions of the display area used by the applet.

  • After you create this file, you can execute your browser and then load this file, which causes AppletDemo to be executed.

  • To execute AppletDemo with an applet viewer, you may also execute the HTML file. For example, if the preceding HTML file is called RunDemo.html, then the following command line will run AppletDemo:

C:\>appletviewer RunDemo.html

  • However, a more convenient method exists that you can use to speed up testing. Simply include a comment at the head of your Java source code file that contains the APPLET tag.

  • By doing this, your code is documented with a prototype of the necessary HTML statements, and you can test your compiled applet merely by starting the applet viewer with your Java source code file. If you use this method, the AppletDemo source file looks like this:

import java.awt.*;

import java.applet.*;

/*

<applet code="AppletDemo" width=200 height=60>

</applet>

*/

public class AppletDemo extends Applet {

public void paint(Graphics g) {

g.drawString("A Simple Applet", 20, 20);

}

}

 

Structure of Applets

  • All but the most trivial applets override a set of methods that provides the basic mechanism by which the browser or applet viewer interfaces to the applet and controls its execution.

  • Four of these methods, init( ), start( ), stop( ), and destroy( ), apply to allapplets and are defined by Applet Class.

  • AWT-based applets will also override the paint( ) method, which is defined by the AWT Component class.

  • Below is the simple structure of Applets:

// An Applet Structure.

import java.awt.*;

import java.applet.*;

/*

<applet code="AppletName" width=300 height=100>

</applet>

*/

public class AppletName extends Applet {

// Called first.

public void init() {

// initialization

}

/* Called second, after init(). Also called whenever

the applet is restarted. */

public void start() {

// start or resume execution

}

// Called when the applet is stopped.

public void stop() {

// suspends execution

}

/* Called when applet is terminated. This is the last

method executed. */

public void destroy() {

// perform shutdown activities

}

// Called when an applet's window must be restored.

public void paint(Graphics g) {

// redisplay contents of window

}

}

 

 

Example: Java Applet for drawing a line

 Sam Madam

//Program name LineDemo.java

// Java Applet for drawing a line

import java.applet.*;

import java.awt.*;

public class LineDemo extends Applet

{

/*

<applet code="LineDemo.class" width=300 height=250></applet>

*/

public void paint(Graphics gp)

{

gp.drawLine(0, 0, getSize().width, getSize().height);

}

}

Output

 

 

 

Example: Java programs for drawing several lines on an applets

 Sam Madam

//Program name DrawingLines.java

//Java programs for drawing several lines on an applets

import java.applet.*;

import java.awt.*;

 

public class DrawingLines extends Applet {

/*

<applet code="DrawingLines" width=350 height=200>

</applet>

*/

int width, height;

 

public void init() {

width = getSize().width;

height = getSize().height;

setBackground( Color.black);

}

 

public void paint( Graphics g ) {

g.setColor( Color.green);

for ( int c = 0; c < 5; ++c ) {

g.drawLine( width, height, c * width / 10, 0 );

}

}

}

Output

 

 

 

Example: Java Applet program for demonstrating the life cycle of Applet

 Sam Madam

//Program name LifeCycle.java

// Java Applet program for demonstrating the life cycle of Applet

import java.awt.*;

public class LifeCycle extends java.applet.Applet

{

/*

<applet code="LifeCycle.class" width=260 height=250></applet>

*/

 

String message[] = new String[20];

int i = 0;

public void init()

{

message[i++] = "I am in init()";

message[i++] = "I am leaving init()";

}

public void start()

{

message[i++] = "I am in start()";

message[i++] = "I am leaving start()";

}

public void stop()

{

message[i++] = "I am in stop()";

message[i++] = "I am leaving stop()";

}

public void destroy()

{

message[i++] = "I am in destroy()";

message[i++] = "I am leaving destroy()";

}

public void paint(Graphics g)

{

for(int j = 0; j < i; j++)

g.drawString(message[j], 50, (j+1)*25);

 

}

}

Output

 

 

 

Example: Java Applet program for getting the size of Applet

 Sam Madam

//Program name SizeApplet.java

// Java Applet program for getting the size of Applet

import java.applet.*;

import java.awt.*;

 

public class SizeApplet extends Applet

{

/*

<applet code="SizeApplet.class" width=350 height=200></applet>

*/

public void paint(Graphics gp)

{

Dimension appletSize = this.getSize();

int appletHeight = appletSize.height;

int appletWidth = appletSize.width;

gp.drawString("This applet is " + appletHeight +

" pixels high by " + appletWidth +

" pixels wide.", 15, appletHeight/2);

showStatus(appletHeight+" x "+appletWidth);

}

}

Output

 

Now change the size of applet by dragging from edge of applet window and see the size change as below:

 

Pr.Pg border                                              Next Pg