i would like to create a source code analyser for Java Project (like FindBugs and other static analysis programs) that would be able to detect certain method calls.
I would prefer to do it using Python, but any advice would be great !
I'm going to start by studying the FindBugs source code, but if anyone could explain to me the underlying concepts and if it's easily do-able, i would be really grateful.
Thank you for your time.
Olivier.
Read the book : Language implementation Patterns. It is a very accessible book out there and you can gauge the effort that will be required to achieve what you want to achieve
http://www.pragprog.com/titles/tpdsl/language-implementation-patterns
Related
I am currently developing a project in JavaFX that accepts a mathematical expression and evaluates it. I have managed to get basic operations and a good deal of algebra to work. I have also managed to perform definite integrations using the trapezoid rule.
The main problem I am facing is with indefinite integration. I looked up many symbolic computation libraries online like JCalculus, JavaCalculus, JScience, SymJa and others. But none of them were as good as SymPy in terms of functionality. I wanted to know if there is a way to send commands to SymPy from Java and receive the result back into Java.
I am thinking of providing an installer for my JavaFX app that will install Python and SymPy if necessitated by the solution. I also tried to understand Jython, believing that it would somehow by related to the problem but I could not understand its purpose and its usage.
Please help me. I am quite good at Java and JavaFX but my knowledge of Python is severely low and restricted. Step by step instructions and sample code is extremely appreciated.
Thanks in advance.
If you somehow manage to write sympy equivalent python code from your java input in a file, you can get the output of that code very easily.
Process p = Runtime.getRuntime().exec("python yourfile.py");
Take a look at this.
I am trying to create a lexical analyzer program using java.Program must have the concept of tokenization .I have beginner level knowledge in compiler programming.I know there are lot of Lexical generators exist on internet.I can use them to test my own lexical analyzer out put .But i need to do my own lexical analyzer .Can any one please give some best references or articles or ideas to start my cording ?
"Compilers Principles, Techniques and Tools" by Aho Sethi and Ullman has a chapter on lexical analysers. It includes a lot of the theory on regular expressions and finite automata that are core to this problem domain.
I would try taking a look at the source code for some of the better ones out there. I have used Sablecc in the past. If you go to this page describing how to to set you your environment, there is a link to the source code for it. Antlr is also a really commonly used one. Here is the source code for it.
Also, The Dragon Book is really good.
As Suggested by SK-logic I am adding Modern Compiler Implementation as another option.
I want to write some plugin to analysis Java source code. Which part of eclipse's plugin I have to know? I know this is a stupid question, but I really don't know where I have to start and I don't have too much time. I am not an actual programmer, I am a computer repair technician. So I just can write plugin (I love it) in spare time.
I am really grateful if someone give me a few pointers.
I didn't mean to be snarky above. So, I'd first recommend getting to understand the Eclipse architecture, plugin model and APIs. Here is an old, but still relevant tutorial:
http://eclipsepluginsite.com/#
It doesn't go into JDT at all, but does give you an idea about Eclipse plugins in general. So, once you understand that tutorial, you can move on to JDT:
http://www.vogella.com/articles/EclipseJDT/article.html
You'll need to master quite a lot -- the Builder API to hook into the incremental build process and get notified when files change, the IResource type hierarchy to get to the source files, the Java AST classes (there's a big bunch of those), some quirks concerning type bindings, etc. There is no simple pointer to give.
I've been using PHP all the time.
Any advice to taking on these two languages?
I would say it really depends if you're used to the way OOP (object oriented programming) works. If you're not familiar with this way of thinking I would definately go with the book "Objects First With Java". It might look really, really basic at first, and you might be able to skip the first chapter or two. But if you read it from chapter 2 or 3 or so and finish it, you should have a good amount of knowledge to start building applications.
It's a little hard to help here because I don't know your level of skill when it comes to OOP. :) I've been writing PHP for a long time and didn't know a thing about OOP until I read the above-mentioned book.
All the best,
Bo
The same way you learned PHP - read the documentation, write some code, compile or execute it, debug it. Repeat until you are good. But don't expect to master a language quickly - anyone can learn to write code in a given language, but it takes time and effort to actually write good, high quality, and idiomatic code in that language.
The way I learn new languages is to read the documentation and other people's source code. It really helps to see what is possible in the language, without having it all wrapped up in academic speak.
Books are also helpful, if you have the time/patience to read through them.
A really good idea is to look up programs written in those languages and see if you can write the pseudo code for the programs. Then compare those to the source code and see what the difference is.
The best way to learn Ruby and/or Java is to forget the "PHP way" and to tackle each new language under their own idioms.
Both Ruby and Java have a fair selection of books (dead tree, electronic, free and non-free) as well as numerous free online tutorials. Ruby even has a nifty online interactive tutorial by _why (you did search didn't you?).
Learning the basic operation and syntax of each language is essential to avoid wasting time with random guessing as to why X doesn't work like Y. (Hint: If X doesn't work like Y, it's because X isn't Y.)
Trying to learn two languages at once is probably not the best idea. Ruby is quite similar to PHP, so the transition may be fairly simple, depending on your prior experience with other dynamic languages. You may find this site useful: http://railsforphp.com/
I recommend you try and build basic applications. Have a target, use the documentation and search the blogs or ask somebody if you're stuck. That's how I learned Ruby.
Also, for Ruby and Rails documentation I like APIdock, too bad they don't have Ruby 1.9 (which I recommend you use).
Click this: code-golf
Then solve all the challenges that got at least 10 upvotes in both Java and Ruby. Don't worry about the golf-scoring part, just do the best you can. If you post your efforts you may get some feedback, and you can compare your results with others.
Keep it enjoyable and simple at first. Use the learning style that works for YOU. If you like reading docs - great, otherwise you'll just end up with a nasty aftertaste. I'll say keep it enjoyable again because your initial exposure/experience can be greatly influenced by how you hit it off with a new language. Try to approach it from an angle of familiarity, you will find that there's some overlap between what you know and the new material. It will help if you can introduce the new stuff with as much ease as possible.
Recall what speaks to you or demonstrates most effectively when you learn and plot your course based on that. If you like books, find one that suites your style. Most of the books will give you most of the same information so what will make the most difference in a case like this is style of the book. For me "Java Objects" by J. Baker did the trick, my friend swears by "Thinking in Java". ... or find some screencasts if you like screencasts.
Then of course fire up the debugger and step though some code, but what ever you do first make sure you're enjoying it.
Start with Ruby. There is a wonderful online tutorial that lets you try Ruby right in your browsers. It covers the essentials of flow control and collections.
http://tryruby.sophrinix.com/
Java and PHP have more in common syntactically than Ruby and PHP. Sometimes that makes it harder instead of easier when learning a new language. That's why I think learning Ruby before Java will help. Ruby is also a lot easier to learn than Java, so the emotional return is greater and you'll be more equipped for Java.
As to learning Java, start with a Tutorial using Tapestry. Not so that you learn Tapestry, but so you gain the benefit of rapid development.
"Java developers love it because they can make Java code changes and see them immediately ... no redeploy, no restart!"
The down side to Tapestry is potential mess of setting up Tomcat.
I'd recommend getting yourself familiar an IDE (i.e. Eclipse) and working through some basic HelloWorld-esque problems. This will let you understand the lifecycle of a java program and some basic I/O. Maybe even take parts of a PHP project you've written and port it over to Java to get the basic syntax ideas down.
I'm writing a Java application using Struts 2, but now I'd like to make it a hybrid Java & Scala project instead. I don't have much experience with Scala, but I learned Haskell years ago at college -- I really liked the functional programmed paradigm, but of course in class we were only given problems that were supremely suited to a functional solution! In the real world, I think some code is better suited to an imperative style, and I want to continue using Java for that (I know Scala supports imperative syntax, but I'm not ready to go in the direction of a pure Scala project just yet).
In a hybrid project, how does one decide what to code in Java and what to code in Scala?
Two things:
99% of Java code can be expressed in Scala
You can write projects that support mixed Java+Scala compilation. Your Scala code can call your Java code and your Java code can call your Scala code. (If you want to do the latter, I suggest defining the interface in Java and then just implementing it in Scala. Otherwise, calling Scala code from Java can get a little ugly.)
So the answer is: whatever parts you want. Your Scala code does not need to be purely functional. Your Scala code can call Java libraries. So pretty much any parts you could write in Java you could also write in Scala.
Now, some more practical considerations. When first trying Scala, some people pick relatively isolated, non-mission-critical parts of their program to write in Scala. Unit tests are a good candidate if you like that approach.
If you're familiar with Java and have learned Haskell in the past, I suggest treating Scala as a "better Java". Fundamentally, Scala compiles to JVM bytecode that is very, very similar to what Java outputs. The only difference is that Scala is more "productive": it produces more bytecode per line of code than Java does. Scala has a lot of things in common with Haskell (first-class functions, for-comprehensions are like Haskell's do-notation, limited type inference), but it's also very different (it's not lazy by default, it's not pure). So you can use some of your insights from Haskell to inspire your Scala style, but "under the hood" it's all Java bytecode.
In the spirit of your question, I recommend you write in Scala any code that involves heavy manipulation of collections, or that handle XML.
Scala's collection library is the foremost functional feature of Scala, and you'll experience great LoC reduction through its usage. Yes, there are Java alternatives, such as Google's collection library, but you asked what you should write in Scala. :-)
Scala also has native handling of XML. You might well find the transition difficult, if you try to take DOM code and make it work on Scala. But if you, instead, try to approach the problem and the Scala perspective and write it from scratch for Scala, you'll have gains.
I'd advise using Actors as well, but I'm not sure how well you can integrate that with Struts 2 code on Java. But if you have concurrent code, give Actors in Scala a thought.
It might sound silly, but why not write your entire project in Scala? It's a wonderful language that is far more expressive than Java while maintaining binary-compatible access to existing Java libraries.
Ask these questions of your project:
"What operations need side-effects?" and "What functionality is already covered well by Java libraries?" Then implement the rest in Scala.
However I would warn that hybrid projects are by their very nature more difficult than stand alone projects as you need to use multiple languages/environments. So given you claim not much experience with Scala I'd recommend playing with some toy projects first, perhaps a subset of your full goal. That will also give you a feel for where the divide should occur.