invoke gdb to debug java programs - java

i am pretty new to programming, and having some trouble with debugging java programs. I try to use gdb to debug my java program, but no matter how hard i try, it still does not work at all.
The error message in the minibuffer of emacs(GUI) is always "No such file or directory , gdb". I am sure that my currrent directory is the the same as the sourcefile and the compiled file(executable file compiled with "javac -g xx.java") .
So, my confusion is that: Does the error has something to do with:
1. wrong syntax of invoking gdb (used Meta gdb xx )
2. what is the executable java file for gdb/ how gdb identify them
3. is it possible that my installation of EMACS is incomplete, as i input the gdb to the command line(Win8 system), NO gdb prompt appears at all(something like(gdb....))

Error No such file or directory, gdb
If the error message is coming from emacs, it means that gdb is not installed. To fix it, install gdb. Note that gdb is not part of emacs, it's a separate program. If you get gdb with a bundle, it would usually be part of gcc, the GNU Compiler Collection, not Emacs. The source is the same - FSF (Free Software Foundation) / GNU Project (GNU is Not Unix), but it is different / separate packages.
If the error message is coming from gdb, it means that gdb cannot find the executable. See next point for this.
However, looking at your description, it's more likely that gdb is not installed at all.
gdb cannot debug Java directly
gdb cannot be used to debug Java programs in general, it can only be used to debug Java programs that were compiled into binaries using gcj. See also Java Debugging with gdb from its manual.
You may want to go for jdb instead, which is the Java Debugger that comes with a JDK.
Emacs for Java? Use an IDE instead
Emacs is a great text editor indeed. The jokes that people make about Emacs, like "Actually Emacs is a Common Lisp implementation for developing computer games which happens to have one of the two best text editors as a demo app" are a pun on its greatness. I'm a vim user myself, and I have only the deepest respect for Emacs and what it contributes to computer science (i.e. Common Lisp).
But no matter how good Emacs and vim are, these days the IDEs beat them to it.
The three most popular Java IDEs
Eclipse
NetBeans
IntelliJ IDEA
I recommend IntelliJ IDEA and have my reasons for it, but you can't really choose wrong. They're all good!
What do the IDEs offer?
Syntax Highlighting
Bleeding edge with the latest Java versions
Hundreds of additional checks (especially IntelliJ IDEA: Inspections)
Lots of typical edits automated (especially IntelliJ IDEA: Intentions)
Refactoring
Java Debugging
Java Decompilation
Code Coverage
Code Completion
Integrated access to JavaDoc help
Integration with Unit Test frameworks
Integration with Version Control Systems
Integration with Android SDK and Emulator
Integration with the typical Java build tools Ant, Maven, Gradle
A lot more with those many plugins
Several of these things are also offered by Emacs or vim - but not all of them.
What about my Emacs (or vim) knowledge?
I'm a vim power user myself, but I wouldn't use vim for any Java that exceeds Hello, World, because an IDE like IntelliJ IDEA is just so much better. One argument that is often made is that we users invest a lot into editors like vim and emacs learning all their shortcuts for productivity. This knowledge does not need to be lost. IntelliJ IDEA has an IdeaVim plugin for Vim users and an emacsIDEA plugin for Emacs users. I don't know, but I could imagine that the other IDEs have similar plugins.

Related

Java beginnings using Netbeans

I'm just about starting to learn Java. Reading about, I installed Netbeans.
Running Apache Netbeans IDE 11.2.
The Java version is 13.0.2.
I'm promptly follow the Quickstart guide on the netbeans website.
File>>New project>> Java >> Java Application.
Errhmm, I don't have this 'Java' option. All I have is
So what's the difference between Java & Java with Maven/Cradle/Ant . At this point in time, I intend to start with basics of Java programming and then move on from there. SO which option am I meant to be starting with? If I'm missing Java, how can I add it ? Going through the installation procedures didn't give me any option to choose from.
p:s - this is all running on Mac OS Catalina
You can start with any of Java with ... option. I use Java with Ant option.
Maven, Gradle, Ant are build-tool addons i.e. they provide additional support if you intend to use any of these as your build tool.
When you choose Java with Ant option, it will let you create, compile, debug and run your Java programs without requiring anything additional. After using this option, you will get an interface as shown in the screenshot given below:
Maven, Gradle and Ant are build tool which allows you to compile, unit test, package and (if you like) even deploy your Java applications (they do support other languages btw).
I suggest you to start with one of those (Maven is very popular and probably a little bit easier than the others) instead of relying on your Java IDE specific features.
Once you master a build tool you can change IDE (IntelliJ is also a very good option ;-)) and will still work as before. You also find plenty of resources and help (like Stackoverflow) if you need hit some problems.
Best of luck!

What project files does Visual Studio Code create via its Java extensions?

I give a computer programming course I have written, and I recently switched to recommending Visual Studio Code in the course. We are starting out with the basics, so I just wanted a simple editor. We started learning Git, and one student's repository suddenly had all sorts of cruft in it, including:
.settings/
.vscode/
.classpath
.project
In particular the .settings directory had all sorts of Eclipse settings, such as I would expect to see in an Eclipse project.
The student explained to me that these came from VS Code after installing its Java extensions. But why are the VS Code Java extensions creating Eclipse files? And where is all this documented, so that I can update my lessons with the exact details and avoid this problem in the future?
Thanks in advance.
Simplified the Language Support for Java™ by Red Hat is the headless Eclipse Java IDE integrated into Visual Studio Code via the Language Server Protocol (LSP). See the self-description of the extension:
Provides Java™ language support via Eclipse JDT Language Server, which
utilizes Eclipse JDT, M2Eclipse and Buildship.
Except for .vscode/, the mentioned files are Eclipse Java IDE files.
Because in Eclipse these files are not intended to be edited manually, there is little or no documentation about them (the Java compiler settings in .settings/org.eclipse.jdt.core.prefs are similar to the command line arguments of the Eclipse batch compiler).
For example, the documentation of the Java extension recommends using the Eclipse Java IDE to edit the formatter settings (which are also stored in .settings/org.eclipse.jdt.core.prefs) and concludes:
No it's not an ideal solution, but it should be done only once, unless
you regularly change your formatter settings.

If I've Downloaded JDK, Do I Need to Download Eclipse Too?

I'm pretty new to programming and to Java, so I'm really not sure.
I know that JDK has its own compiler and the JRE too so would I really need Eclipse?
You need the JRE to run java code on your computer and the JDK to write it. However, many programmers tend to prefer an IDE (Integrated Development Environment) to use along side for actually writing the code, debugging, and execute it much more efficiently. Eclipse is a good example of one, and one of the many used/preferred IDE's (in my opinion at least) out there. However, others exist too:
DrJava
Netbeans
BlueJ
JCreator
These editors are much more preferred because they make it easier to learn / write code. However, you may choose a normal text editor (like sublime, atom, textedit, notepad, textmate, etc..) or even the command line. Mac & Linux have "vim" built in which is a command line editor too which I tend to prefer.
Yes, the JDK and JRE are necessary to run java but Eclipse is the tool that will allow you to code, debug and execute easier.
Think of JDK as the engine of a car and Eclipse or any other IDE like the wheel.

MakeFile for Java?

I've looked at several questions and read through a couple of tutorials but MakeFile is still a bit of a confusing concept to me.
From what I understand, it is essentially a set of rules for building up Unix commands to compile and run the code?
So far, I have been just running my Unix commands as such:
>> javac Main.java SomeClass1.java SomeClass2.java
>> java Main input_file.txt
because my Main function takes in an input_file.
I want to be able to make this more efficient by using Make, but I am having trouble with understanding the concepts.
Any help is much appreciated!
Thank you!
Make is a build tool - a piece of software to compile the source code of software projects into an executable.
When you are creating small, simple programs, you don't really need a build tool. You can just compile your code by running the compiler javac on the command line. But when you start working on a larger project with many source files, it's going to be too cumbersome to compile all the source files by hand. You'll want to use a build tool. Besides compiling your code, a build tool can help you perform other tasks, such as automatically running unit tests and automatically managing dependencies (libraries that your program needs).
For a Java project, consider using a Java build tool such as Apache Ant, Apache Maven or Gradle. Those are the de-facto standard build tools for Java projects, and the big Java IDEs (Eclipse, IntelliJ and NetBeans) have support for these tools.
Make is mainly used for C and C++ projects and is not very well suited for Java.

How to disable ant in eclipse

I am new to Python and only installed Eclipse + Pydev as the autoformatting possibilities would help me with the annoyingly stringent indentation rules of Python, which weren't being caught by Geany for example. (These have cost me HOURS of futile searching for even very simple intentaion problems).
I don't need Java or Jython (yet), so how do I disable the interference from Ant at Run time?
Or is there another IDE with autoformatting that doesn't need Java support that would be better suited?
Ant doesn't run in Eclipse at runtime unless you have an Ant builder on the project. (it might be something else causing whatever behavior is bothering you.) That said, Eclipse is a heavy IDE if you only want it for the formatting help. If you are using other features like debugging, PyDev is helpful.
You might consider a lightweight IDE. NotePad++ has a Python plugin.

Categories

Resources