Java source code parsing [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to track down a java variable in a java file - which variable it got assigned to, which method it was passed to.
How should I begin with?
Should I use line by line parsing or is there any other method?

It looks like you are asked to build a huge mansion; and you start by asking: "should my shovel to dig the cellar be better round; or more rectangular". Meaning: if you don't understand that parsing a java program requires more than "line by line" reading; then you are doomed to fail.
Anyway, depending on your underlying requirements, there are two possible answers:
As suggested by duffymo, you might want to learn using an IDE which allows you to easily identify "variable usage" within a project; and make modifications via "reflection"
Start using a fully fledged Java parser; like https://code.google.com/p/javaparser/wiki/UsingThisParser

Related

Run a math expression from string in java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to know if there is any efficient method to Run a math expression from string in java , Having some example input and results of that function.
Starting from simple linear functions : a*x+b .To more complex ones
Or is there any good source i can start reading.
I take your task as: take observed input-output and learn some representation which is able to do that transformation with new inputs.
(Some) Neural Networks can learn an approximation-function (Universal approximation theorem
) (and probably other approaches), but there is something important to remark:
Without assumptions about your function (e.g. smoothness), there can't be an algorithm achieving what you want to do! Without assumptions there are infinite many approximation-functions, which are all equally good on your examples, but behave arbitrarily different on new data!
(I'm also ignoring special-cases as: random-data or cryptographic random-generators where this mapping also can't be learned (the former in theory; the latter at least in practice)

I'm new at programming. I'm not sure how much to use methods [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So, I just finished my first program, but I haven't use any methods in it, since I'm just beginning to learn how to use them. Here's the original code : http://codepad.org/JiBfJI8Q I started to fractionate it but realised that it would be a method inside another all the way down. Is that actually the way to do it, or did I get the idea wrong?
without having looked at your code:
The general idea of methods is to separate small
portions of code which might be used at multiple other places in your code.
so yes, calling methods from within other methods is a good thing to do.
ideally your so called "composed methods" read out like a little story:
public void transaction(){
openDatabaseConnection();
addRecordsToDatabase();
closeDataseConnection();
}

user defined functions vs built in function in java five relevant differences over time and space complexities [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Please explain me the differences over time and space complexities in java for user defined and predefined functions in java. examples like, linked list, list, stack class. please explain this with valid example.
thank you.
There is nothing special in predefined function over user defined. The only thing is predefined has been written by somebody else for you. It depends on algorithm.
Crap code/implementation runs in a crap way. Doesn't matter if its user created or system/API provided. example at a high level is EJBs vs Spring.
Good written code runs pretty and sleek. Again doesn't matter who the hell wrote it.

Method class in Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am currently working on a project where I found this syntax:
Method m = bluetoothDevice.getClass().getMethod("createBond", (Class[]) null);
What is the purpose of "Method" class in Java and why we use it? Please elaborate with an example
Thanks in advance!
PS: I already saw the Java docs but not able to understand it.
The Method class is part of the "reflection" API which is about meta-programming. That means you can deal with structures of your program as data and process it in a java program. This allows flexible generic or abstract solutions. Method itself just represents a method in a Java class. There are other classes representing other parts of Java programs, too (e.g. Class).

Implementing jsp:include at Java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to start from a given file(i.e. a.html) and if I see a pattern as like that:
<!--$include file="b.html"-->
I will go that file(b.html) and take whatever it has and all files will be written as into a final file(i.e. output.html)
If I see an include at b.html I should follow that include too and take whatever it has and I should repeat it recursively at Java?
Any ideas?
PS: It is similar to what jsp:include does but I want to implement it myself. I will implement it as a Maven plugin and I constructed a maven plugin for my need however using recursion or not and using a regex pattern or any other efficient way is what I am looking for.
You need to create a function to get files list, e.g. getFileList(htmlFile:File): File[];
Create a readline function and create a function to parse line which pattern is like "^.*<!\\-\\-\\$include file\\=\"(.+)\\.(html|htm)\" \\-\\->.*$", this is a regular expression, it can match what your searched regex. let's defined the function's name as checkRule(line:String):boolean
If checkRule return true, and get file name, then recursively invoke getFileList by passing just found file name.
Be careful about infinite loop. For example, a.html includes b.html, and b.html includes a.html, it would become infinite loop. So you need to check file list to ignore the file.
Good luck!!!

Categories