473,414 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

methods and construtors

How can we get methods name and costructors name from java class before compilation?Please any body have any idea plaese share with me
Mar 13 '07 #1
15 1512
hirak1984
316 100+
[font=Verdana][size=2]question not clear at all.What are you trying to do please explain in details.[/size][/font]
How can we get methods name and costructors name from java class before compilation?Please any body have any idea plaese share with me
Mar 13 '07 #2
r035198x
13,262 8TB
How can we get methods name and costructors name from java class before compilation?Please any body have any idea plaese share with me
Please expalin what you mean by "before compilation".
Mar 13 '07 #3
Hi ,
I have one java class like test.java

public class test{


boolean packFrame = false;

private int a,b;
public test() {


System.out.println("Hi");
}
public static final void test45 (int i) {
int a=0,b=1;
if(a==b){
System.out.println("test");
}
System.out.println("Hi");
}

public static int test123 (int i,String s,int k) {


System.out.println("Hi");
return 5;
}

public void vee(int i){

try{
i +=1;
sum( a, b);
}
catch(Exception e){

}
}
public void sum(int a,int b){




try {
int sumab=0;
sumab= a+b;
} catch (RuntimeException e) {

e.printStackTrace();
}
}

I want this methods name and constructors name before compile this java class..


Please expalin what you mean by "before compilation".
Mar 13 '07 #4
output like
constructor :
test()
methods name : test45,test123,sum


Hi ,
I have one java class like test.java

public class test{


boolean packFrame = false;

private int a,b;
public test() {


System.out.println("Hi");
}
public static final void test45 (int i) {
int a=0,b=1;
if(a==b){
System.out.println("test");
}
System.out.println("Hi");
}

public static int test123 (int i,String s,int k) {


System.out.println("Hi");
return 5;
}

public void vee(int i){

try{
i +=1;
sum( a, b);
}
catch(Exception e){

}
}
public void sum(int a,int b){




try {
int sumab=0;
sumab= a+b;
} catch (RuntimeException e) {

e.printStackTrace();
}
}

I want this methods name and constructors name before compile this java class..
Mar 13 '07 #5
hirak1984
316 100+
you are confusing us.

which method name do you want?
And where is the " main " method in your code?
where from will the code start to compile or run?
is this your first java program?just go through some examples of writing a java program first.
Hi ,
I have one java class like test.java

public class test{


boolean packFrame = false;

private int a,b;
public test() {


System.out.println("Hi");
}
public static final void test45 (int i) {
int a=0,b=1;
if(a==b){
System.out.println("test");
}
System.out.println("Hi");
}

public static int test123 (int i,String s,int k) {


System.out.println("Hi");
return 5;
}

public void vee(int i){

try{
i +=1;
sum( a, b);
}
catch(Exception e){

}
}
public void sum(int a,int b){




try {
int sumab=0;
sumab= a+b;
} catch (RuntimeException e) {

e.printStackTrace();
}
}

I want this methods name and constructors name before compile this java class..
Mar 13 '07 #6
suppose this test.java class has save in different location , another one xyz.java , which can read test. java , and when we will compile xyz.java , that time it'll give test.java methods name and constructors name like test,test45,test123,sum.



you are confusing us.

which method name do you want?
And where is the " main " method in your code?
where from will the code start to compile or run?
is this your first java program?just go through some examples of writing a java program first.
Mar 13 '07 #7
r035198x
13,262 8TB
I'm not sure what you are trying to do here but you can have a look at the reflection API and see if that's what you want.
Mar 13 '07 #8
I know that through reflection it's possible , but this case we need compile first,
without compile the java class how can we get method name and constructor name?

I'm not sure what you are trying to do here but you can have a look at the reflection API and see if that's what you want.
Mar 13 '07 #9
r035198x
13,262 8TB
I know that through reflection it's possible , but this case we need compile first,
without compile the java class how can we get method name and constructor name?
Well you should realize then that the jvm won't have anything to do with it until you have created a class file. So you have to manipulate it as you would a text file. You'd have to open it using FileReader or Scanner and try to extract the function names. The constructors are easy to get but the method names require a bit more analysis.
Mar 13 '07 #10
hirak1984
316 100+
Ya I too cant find any other way.But why do you need to get the names before compilation?Not clear!
Well you should realize then that the jvm won't have anything to do with it until you have created a class file. So you have to manipulate it as you would a text file. You'd have to open it using FileReader or Scanner and try to extract the function names. The constructors are easy to get but the method names require a bit more analysis.
Mar 13 '07 #11
Yes that is right , but if any method is available in java API which is providing get method and constructors name before compile.Because if we'll think about ur suggestion for generic, then it's too difficult , the different programmer have different coding style. So getting method name is also difficult
You told that constructor is get too easy but I'm giving one example here
Suppose Test.java is class
public class Test{
test(){ --------------->constructor
System.out.println("Hi");
}
public void test(){ --------> Method
System.out.println("Hi");
}

Then how can we will differentiate here?


Well you should realize then that the jvm won't have anything to do with it until you have created a class file. So you have to manipulate it as you would a text file. You'd have to open it using FileReader or Scanner and try to extract the function names. The constructors are easy to get but the method names require a bit more analysis.
Mar 14 '07 #12
Because my requirement like that

Ya I too cant find any other way.But why do you need to get the names before compilation?Not clear!
Mar 14 '07 #13
r035198x
13,262 8TB
Yes that is right , but if any method is available in java API which is providing get method and constructors name before compile.Because if we'll think about ur suggestion for generic, then it's too difficult , the different programmer have different coding style. So getting method name is also difficult
You told that constructor is get too easy but I'm giving one example here
Suppose Test.java is class
public class Test{
test(){ --------------->constructor
System.out.println("Hi");
}
public void test(){ --------> Method
System.out.println("Hi");
}

Then how can we will differentiate here?


public class Test{
test(){ --------------->constructor
Wrong!

test() is not a constructor. Java is case sensitive.
To find the constructor you have to find where the name exactly matches the name of the class and then you would have to see what modifier was used for it e.g

Expand|Select|Wrap|Line Numbers
  1.  public class Test{ 
  2. Test(){ --------------->constructor
  3. }
  4. void Test() {//-------->not a constructor
  5. }
  6.  
It is possible to get them including the methods as well if you do your design right but the work required is almost as much as that required to write a compiler.
Mar 14 '07 #14
Yes that is right java is case sensitive ,

ok Test(){---------> constructor
}

public void Test(){-------->method.

}

void Test(){------>
}
then how can we differentiate method and constructor


public class Test{
test(){ --------------->constructor
Wrong!

test() is not a constructor. Java is case sensitive.
To find the constructor you have to find where the name exactly matches the name of the class and then you would have to see what modifier was used for it e.g

Expand|Select|Wrap|Line Numbers
  1.  public class Test{ 
  2. Test(){ --------------->constructor
  3. }
  4. void Test() {//-------->not a constructor
  5. }
  6.  
It is possible to get them including the methods as well if you do your design right but the work required is almost as much as that required to write a compiler.
Mar 14 '07 #15
r035198x
13,262 8TB
Yes that is right java is case sensitive ,

ok Test(){---------> constructor
}

public void Test(){-------->method.

}

void Test(){------>
}
then how can we differentiate method and constructor
That's the example I just gave and I did say that you'd then have to check the modifier that was used. e.g if the modifier is public or protected then it's a constructor, if there is no modifier, then it's a constructor again, otherwise it's a method.

However, to get it to work properly you'd need to parse the program first breaking it up into statements so that you have a statement on each line ...
Mar 14 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Axehelm | last post by:
Okay, I'm in a debate over whether or not static methods are a good idea in a general domain class. I'm personally not a fan of static methods but we seem to be using them to load an object. ...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
2
by: Mark | last post by:
I have it in my head that I saw a marketing document from Microsoft with the total number of classes and methods in the .NET Framework. Something like 70,000 methods? I don't need precise numbers,...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
3
by: amit tikoo | last post by:
Hi all I want to know reasons behind why we cannot delcare construtors virtual Thanks
3
by: rickeringill | last post by:
Hi comp.lang.javascript, I'm throwing this in for discussion. First up I don't claim to be any sort of authority on the ecmascript language spec - in fact I'm a relative newb to these more...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
2
by: fgh.vbn.rty | last post by:
Hi, I'm not sure if i'm asking the question correctly but anyway here it is. Say I have 3 classes - class A, class B, class R. 1) A and B are the building blocks and R is like a repository...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.