0% found this document useful (0 votes)
8 views3 pages

Excercise 9.1 (Record)

Java program for future use

Uploaded by

Siva Shankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Excercise 9.1 (Record)

Java program for future use

Uploaded by

Siva Shankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.io.

*;

import java.util.*;

import java.util.regex.*;

public class PublicMethodLister {

public static void main(String[] args) {

if (args.length < 1) {

System.out.println("Usage: java PublicMethodLister <filename>");

return;

String fileName = args[0];

try {

List<String> publicMethods = getPublicMethodNames(fileName);

System.out.println("Public methods:");

for (String method : publicMethods) {

System.out.println(method);

} catch (IOException e) {

System.out.println("Error reading file: " + e.getMessage());

private static List<String> getPublicMethodNames(String fileName) throws IOException {

List<String> publicMethods = new ArrayList<>();

Pattern methodPattern = Pattern.compile("\\bpublic\\s+\\w+\\s+(\\w+)\\s*\\(");


try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {

String line;

while ((line = reader.readLine()) != null) {

Matcher matcher = methodPattern.matcher(line);

if (matcher.find()) {

publicMethods.add(matcher.group(1));

return publicMethods;

}
Output:

You might also like