Debugging Java Applications with NetBeans

 
 from:https://manikandanmv.wordpress.com/2009/09/24/debugging-java-applications-with-netbeans/
 

Netbeans provides an easy environment for debugging or troubleshooting your Java applications. With netbeans debugger, you can step through the code line by line while viewing status of variables, threads and other informations.  No need to add println() statements for finding problems that occur in your apps. Instead use breakpointss
Following things you can perform with Netbeans debugger

  1. step through application code line by line
  2. step through JDK source code.
  3. using break points, execute specific parts of code at a time
  4. track the value of a variable/expression.
  5. fix code on the fly and apply those code changes and continue the debugging session.
  6. options to suspend threads/execution at an exception.
  7. step back to the beginning of a previously called method. (pop a call in the current call stack).

Java Platform Debugger Architecture

It has 3 layers, which provides the infrastructure for debugging applications.

Layer-1: high-level interface for debugging

Layer-2: format of information transfer

Layer-3: low-level native interface, applies code changes at jvm level.

Debugger Parameters

Netbeans debugger allows you to enable remote debugging to already running Java application. For this, you must run your application in debug mode, forreference of introduction about how to  run you application in debug mode.


Attaching the Debugger to a running application.
Java Debug Wire Protocol(JDWP) – which defines the format of information and requests transferred  between debugged application and debugger.

From the main menu, select Debug -> Attach Debugger

Below window will pop-up.

Connector – select the appropriate connection type.
Transport – specifies JDPA transport protocol – automatically filled based on connector.
Host – Machine where the debugging application is running.
Port – Port number that the application listens on.
Timeout – durations that the debugger waits for a connection to be established.

Debugger commands.

Commands for debugging a java app.

F7 – step into – executes each source line , if it has method call, and source code is available, pointer moves to that method and executes it. otherwise pointer moves to the next line in the file.
F8 – step over – executes each source line without stepping through the individual instructions/commands.
F4 – run to cursor – execute the program from the current line.
F5 – continue – resumes debugging until it reaches a next breakpoint or exception or until the program terminates normally.

Setting Breakpoints

Breakpoint is a marker that you can set to specify where execution should pause when you are running your application in the IDE’s debugger.
with breakpoints you can,

  • monitor the values of variables
  • take control of program execution by stepping through code line by line.
  • detect when an object is created.
  • detect when the value of a variable is changed.

Fixing code during a debugging session.

Apply Code Changes – Its an useful feature. This can save lot of time, otherwise waiting for source to be rebuilt and restarting the server/debugging session.
It is useful for

  • Fine-tune the code.(fixing minor issues)
  • change the logic within a method.

This does not work for the following changes.

  • add/remove methods or fields
  • change the access modifiers of a class, method , field
  • refactor the class hierarchy.

In simplest form, It should not accept the skeleton changes.

Note : Once restarted the server, applied code changes are not taking effect for next time because “Apply code changes” works on particular jvm instance only

For fixing code on the fly while debugging session, you must attach your application source code and jar files properly.

Advantages of using debugger

  • Easily and quickly find and resolve the problem.
  • Understand the flow of your application code is easier

Debugging java application with netbean的更多相关文章

  1. velocity模板引擎学习(4)-在standalone的java application中使用velocity及velocity-tools

    通常velocity是配合spring mvc之类的框架在web中使用,但velocity本身其实对运行环境没有过多的限制,在单独的java application中也可以独立使用,下面演示了利用ve ...

  2. maven: 打包可运行的jar包(java application)及依赖项处理

    IDE环境中,可以直接用exec-maven-plugin插件来运行java application,类似下面这样: <plugin> <groupId>org.codehau ...

  3. How to run a (Tomcat)Java application server on a Azure virtual machine

    http://www.windowsazure.com/en-us/documentation/articles/virtual-machines-java-run-tomcat-applicatio ...

  4. The differences between Java application and Java applet

    在Java语言中,能够独立运行的程序称为Java应用程序(Application).Java语言还有另外一种程序--Applet程序.Applet程序(也称Java小程序)是运行于各种网页文件中,用于 ...

  5. Java Applet与Java Application的区别

    转自:http://www.educity.cn/java/500609.html 在Java语言中,能够独立运行的程序称为Java应用程序(Application).Java语言还有另外一种程序-- ...

  6. How to deploy JAVA Application on Azure Service Fabric

    At this moment, Azure Service Fabric does not support JAVA application natively (but it's on the sup ...

  7. Java Applet与Java Application的特点

    java application是应用程序,用于桌面开发,java applet是小应用程序,一般嵌入到网页里运行.applet一般用于B/S页面上作为插件式的开发,而application主要是桌面 ...

  8. 非web环境的注解配置的spring项目应用(non-web, Spring-data-jpa, JavaConfig, Java Application, Maven, AnnotationConfigApplicationContext)

    非web环境的spring应用 springframework提供的spring容器,非常适合应用于javaweb环境中. 同时,spring组件的低耦合性为普通java应用也提供了足够的支持. 以下 ...

  9. 解决Run As -> Java Application不能运行问题

    转自:https://breakshell.iteye.com/blog/467130 点 Run As -> Java Application 不能运行,报的错误如下: Plug-in org ...

随机推荐

  1. 三栏布局之 css3 calc和 flex

    圣杯布局的实现,有很多种. 大致都是借助 padding, margin, float之类的,当然这是传统的实现方式.更多的参考方式圣杯布局小结. 这里说的是用css3 cal 和flex来实现,因为 ...

  2. 《algorithms Unlocked》读书笔记3——计数排序

    <Algorithms Unlocked>是 <算法导论>的合著者之一 Thomas H. Cormen 写的一本算法基础,算是啃CLRS前的开胃菜和辅助教材.如果CLRS的厚 ...

  3. python并发编程之多进程

    一同步与异步 同步执行:一个进程在执行任务时,另一个进程必须等待执行完毕,才能继续执行 异步执行:一个进程在执行任务时,另一个进程无需等待其执行完毕就可以执行,当有消息返回时,系统会提醒后者进行处理, ...

  4. 汇编debug与masm命令

    汇编语言这块是我之前写在网易博客上的,不过那个账号基本已经作废了,所以现在抽个时间把当时的博客搬到CSDN上. 汇编命令(编译器masm命令):找到masm所在的文件夹,我的在d:\MASM中,用cm ...

  5. asp.net mvc 记录Action耗时

    可能有些时候需要记录Action的执行时间来优化系统功能,这时可以用过滤器来实现. 新建项目 项目名称随便取 身份验证:不进行身份验证 安装Nlog 这里使用NLog来输出日志,具体使用说明请看:ht ...

  6. meta标签有何作用?一起来学习一下

    平日里总是沉迷于写页面写组件思考业务逻辑,解决冲突找出bug,猛的发现躲在head标签里的一大串标签时什么?这么多meta标签好多居然都不知其存在的意义.所以决定记录一下学习到的知识点. 先搞明白以上 ...

  7. C语言实现整数和16进制互相转换

    编译环境:Dev-C++ 5.2.0.3 使用sprintf()函数实现转换,代码如下: #include <stdio.h> #include <stdlib.h> int ...

  8. python编码问题和逻辑运算

    1,回顾昨天课程及作业 #1.使用while循环输入 1 2 3 4 5 6 8 9 10 ''' count = 0 while count < 10: count += 1 # count ...

  9. JaveScript数组(JS知识点归纳五)

    1.概念 a)作用--用于保存多个数据,便于对数据的使用 b)数组元素--数组中的数据 c)索引--数组中的元素按照下标(数值)的方式排列(从0 开始),依次递增(也有可能是字符串的类型--不用) d ...

  10. Codeforces 839A Arya and Bran【暴力】

    A. Arya and Bran time limit per test:1 second memory limit per test:256 megabytes input:standard inp ...