Ex No 8,9,10
Ex No 8,9,10
AIM
To write a java program that reads a file name from the user, displays information about whether the file
exists, whether the file is readable, or writable, the type of file and the length of the file in bytes.
PROCEDURE
1.Create a class filedemo. Get the file name from the user .
2.Use the file functions and display the information about the file.
5.getParent () -This method returns the pathname string of this abstract pathname’s parent, or
14.Invoke the predefined functions abd display the iformation about the file.
PROGRAM
import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
class FileDemo {
System.out.println("\n*****************");
System.out.println("FILE INFORMATION");
System.out.println("*****************");
if (file.exists()) {
} else {
if (file.canRead()) {
} else {
if (file.canWrite()) {
} else {
}
if (file.isDirectory()) {
System.out.println("It is a directory.");
} else {
System.out.println("Not a directory.");
if (file.isFile()) {
System.out.println("It is a file.");
} else {
System.out.println("Not a file.");
if (file.exists()) {
if (response.equalsIgnoreCase("yes")) {
if (file.delete()) {
} else {
} else {
System.out.println("File not deleted.");
scanner.close();
Result:
Thus the java program that reads a file name from the user, displays information about whether the file
exists, whether the file is readable, or writable, the type of file and the length of the file in byte.
AIM
To write a java program to find the maximum value from the given type of elements using a
generic function.
PROCEDURE
3.Create the objects of the class to hold integer,character and double values.
4.Create the method to compare the values and find the maximum value stored in the array.
5.Invoke the method with integer, character or double values . The output will be displayed based on
PROGRAM
T[] vals;
MyClass(T[] o) {
vals = o;
public T min() {
T v = vals[0];
if (vals[i].compareTo(v) < 0)
v = vals[i];
return v;
public T max() {
T v = vals[0];
if (vals[i].compareTo(v) > 0)
v = vals[i];
return v;
class GenDemo {
Result:
Thus the java program to find the maximum value from the given type of elements using a
Aim:
Algorithm:
Create the instance for frame anf textfields and necessary layouts
Program:
package buttonexample3;
import java.awt.*;
import java.awt.event.*;
tf.setBounds(50,50, 150,20);
b.setBounds(50,100,60,30);
b.addActionListener(new ActionListener() {
tf.setText("Welcome to Javatpoint.");
});
f.add(b);
f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
10.b. menus
import javax.swing.*;
class MenuExample
MenuExample(){
menu=new JMenu("Menu");
submenu.add(i4); submenu.add(i5);
menu.add(submenu);
mb.add(menu);
f.setJMenuBar(mb);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
new MenuExample();
}}
Result:
Thus the applications using JavaFX controls, layouts and menus has been executed.