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

Properties, System & Runtime Class in Java tutorials

Properties

  • The Propertiesclass implements a mapping of names to values (a String to String map).

  • The propertyNames method returns an Enumeration of all property names.The getProperty method returns a String representing the value of the named property.

  • You can also read and write a properties collection into a file using load and store.

 

 

Example: Java program to get properties of execution environment

 Sam Madam

//Program name Property.java

// Java program to get properties of execution environment

import java.util.Enumeration;

import java.util.Properties;

public class Property

{

public static void main(String[] args)

{

Properties props = System.getProperties();

Enumeration propNames = props.propertyNames();

while ( propNames.hasMoreElements() )

{

String propName = (String) propNames.nextElement();

String property = props.getProperty(propName);

System.out.println("property ’" + propName

+ "’ is ’" + property + "’");

}

}

}

Output

property ’java.runtime.name’ is ’Java(TM) SE Runtime Environment’

property ’sun.boot.library.path’ is ’C:\Program Files\Java\jdk1.6.0\jre\bin’

property ’java.vm.version’ is ’1.6.0-b105’

property ’java.vm.vendor’ is ’Sun Microsystems Inc.’

property ’java.vendor.url’ is ’http://java.sun.com/’

property ’path.separator’ is ’;’

property ’java.vm.name’ is ’Java HotSpot(TM) Client VM’

property ’file.encoding.pkg’ is ’sun.io’

property ’user.country’ is ’US’

property ’sun.java.launcher’ is ’SUN_STANDARD’

property ’sun.os.patch.level’ is ’Service Pack 2’

property ’java.vm.specification.name’ is ’Java Virtual Machine Specification’

property ’user.dir’ is ’C:\Documents and Settings\samstaff\My Documents\NetBeansProjects\JavaApplication1’

property ’java.runtime.version’ is ’1.6.0-b105’

property ’java.awt.graphicsenv’ is ’sun.awt.Win32GraphicsEnvironment’

property ’java.endorsed.dirs’ is ’C:\Program Files\Java\jdk1.6.0\jre\lib\endorsed’

property ’os.arch’ is ’x86’

property ’java.io.tmpdir’ is ’C:\DOCUME~1\samstaff\LOCALS~1\Temp\’

property ’line.separator’ is ’

property ’java.vm.specification.vendor’ is ’Sun Microsystems Inc.’

property ’user.variant’ is ’’

property ’os.name’ is ’Windows XP’

property ’sun.jnu.encoding’ is ’Cp1252’

property ’java.library.path’ is ’C:\Program Files\Java\jdk1.6.0\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.6.0\bin’

property ’java.specification.name’ is ’Java Platform API Specification’

property ’java.class.version’ is ’50.0’

property ’sun.management.compiler’ is ’HotSpot Client Compiler’

property ’os.version’ is ’5.1’

property ’user.home’ is ’C:\Documents and Settings\samstaff’

property ’user.timezone’ is ’’

property ’java.security.policy’ is ’applet.policy’

property ’java.awt.printerjob’ is ’sun.awt.windows.WPrinterJob’

property ’file.encoding’ is ’UTF-8’

property ’java.specification.version’ is ’1.6’

property ’user.name’ is ’samstaff’

property ’java.class.path’ is ’C:\Documents and Settings\samstaff\My Documents\NetBeansProjects\JavaApplication1\build\classes;C:\Documents and Settings\samstaff\My Documents\NetBeansProjects\JavaApplication1\src’

property ’java.vm.specification.version’ is ’1.0’

property ’sun.arch.data.model’ is ’32’

property ’java.home’ is ’C:\Program Files\Java\jdk1.6.0\jre’

property ’java.specification.vendor’ is ’Sun Microsystems Inc.’

property ’user.language’ is ’en’

property ’awt.toolkit’ is ’sun.awt.windows.WToolkit’

property ’java.vm.info’ is ’mixed mode, sharing’

property ’java.version’ is ’1.6.0’

property ’java.ext.dirs’ is ’C:\Program Files\Java\jdk1.6.0\jre\lib\ext;C:\WINDOWS\Sun\Java\lib\ext’

property ’sun.boot.class.path’ is ’C:\Program Files\Java\jdk1.6.0\jre\lib\resources.jar;C:\Program Files\Java\jdk1.6.0\jre\lib\rt.jar;C:\Program Files\Java\jdk1.6.0\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.6.0\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.6.0\jre\lib\jce.jar;C:\Program Files\Java\jdk1.6.0\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.6.0\jre\classes’

property ’java.vendor’ is ’Sun Microsystems Inc.’

property ’file.separator’ is ’\’

property ’java.vendor.url.bug’ is ’http://java.sun.com/cgi-bin/bugreport.cgi’

property ’sun.cpu.endian’ is ’little’

property ’sun.io.unicode.encoding’ is ’UnicodeLittle’

property ’sun.desktop’ is ’windows’

property ’sun.cpu.isalist’ is ’’

 

System

  • System Class provides a system-independent interface to system functionality.

  • One of the more useful things provided by this Class are the standard input and output streams.

  • The standard input streams are used for reading character data. The standard output streams are used for printing.

 

For example:

System.out.println("Welcome to cbtSAM!");


Runtime

  • The Runtime class encapsulates the runtime environment. Basically this class is used for memory management and executing additional processes.

  • Every java program has the single instance of this class to allow the application to interface with the environment. The current runtime instance can be obtained from the getRuntime() method.

  • The Runtime class has various methods ranging from executing processes to exiting or quitting their instances. The processes of the OS can also be called from within the JVM by using Runtime methods provided with the jdk.

  • The exiting of a process can be assigned by using int variables within the Runtime method.

  • Garbage collection in Java is an automatic process and runs periodically. The garbage collector can be manually invoked by calling the gc() method on the current runtime instance.

  • Also the programmer can determine memory allocation details by calling totalmemory() and freememory() methods.

 

 

Example: Java program to demonstrate Runtime class

 Sam Madam

// Program name Runtimes.java

// Java program to demonstrate Runtime class

public class Runtimes

{

public static void main(String[] args)

{

System.out.println("Available processors (cores): " +

Runtime.getRuntime().availableProcessors());

System.out.println("Free memory (bytes): " +

Runtime.getRuntime().freeMemory());

long maxMemory = Runtime.getRuntime().maxMemory();

System.out.println("Maximum memory (bytes): " +maxMemory);

System.out.println("Total memory (bytes): " +

Runtime.getRuntime().totalMemory());

File[] roots = File.listRoots();

for (File root : roots)

{

System.out.println("File system root: " + root.getAbsolutePath());

System.out.println("Total space (bytes): " + root.getTotalSpace());

System.out.println("Free space (bytes): " + root.getFreeSpace());

System.out.println("Usable space (bytes): " + root.getUsableSpace());

}

}

}

Output

Available processors (cores): 1

Free memory (bytes): 4976336

Maximum memory (bytes): 66650112

Total memory (bytes): 5177344

File system root: C:\

Total space (bytes): 10067709952

Free space (bytes): 2474627072

Usable space (bytes): 2474627072

File system root: D:\

Total space (bytes): 9944330240

Free space (bytes): 2528292864

Usable space (bytes): 2528292864

 

 

Example: Java program for system information

 Sam Madam

// Program name SystemInfo.java

// Java program for system information

public class SystemInfo

{

public static void main(String[] args)

{

String osName= System.getProperty("os.name");

String osVersion= System.getProperty("os.version");

String osArch=System.getProperty("os.arch");

String proc=System.getenv("PROCESSOR_IDENTIFIER");

String procarch=System.getenv("PROCESSOR_ARCHITECTURE");

String num=System.getenv("NUMBER_OF_PROCESSORS");

System.out.println("Operating System Name :" +osName);

System.out.println("Operating System Version :" +osVersion);

System.out.println("Operating System Architecture :" +osArch);

System.out.println("Processor :" +proc);

System.out.println("Processor Architecture :" +procarch);

System.out.println("Number of Processor :" +num);

}

}

Output

Operating System Name :Windows XP

Operating System Version :5.1

Operating System Architecture :x86

Processor :x86 Family 15 Model 1 Stepping 3, GenuineIntel

Processor Architecture :x86

Number of Processor :1

 


 

Example: Java program to start another process

 Sam Madam

//Program name RuntimeExe.java

// Java program to start another process

import java.io.IOException;

import java.util.Scanner;

public class RuntimeExe

{

public static void main(String[] args) throws IOException

{

Runtime rs = Runtime.getRuntime();

int choice;

String AppName;

System.out.println("1 for opening Notepad");

System.out.println("2 for opening Calculator");

System.out.println("3 for opening your Application");

System.out.print("Enter your choice : ");

Scanner scan=new Scanner(System.in);

choice=scan.nextInt();

try

{

if(choice==1)

{

rs.exec("notepad");

}

else if(choice==2)

{

rs.exec("calc");

}

else if(choice==3)

{

System.out.print("Enter your Application Name :");

AppName=scan.next();

rs.exec(AppName+".exe");

}

else

{

System.out.println("Wrong choice..");

}

}catch(Exception ex)

{

System.out.println("Exception occur :" +ex.getMessage());

}

}

}

Output

1 for opening Notepad

2 for opening Calculator

3 for opening your Application

Enter your choice : 2

 

 

1 for opening Notepad

2 for opening Calculator

3 for opening your Application

Enter your choice : 4

Wrong choice..

 

1 for opening Notepad

2 for opening Calculator

3 for opening your Application

Enter your choice : 3

Enter your Application Name :Notepad

Pr.Pg border                                              Next Pg