简体   繁体   English

在哪里可以找到以下Java类

[英]Where can I find the following classes in Java

I am a .NET dev learning Java. 我是学习Java的.NET开发人员。 As a result, I understand all the fundamentals of programming like loops, variables, functions, etc. My biggest bottleneck is that I don't know my way around Java's packages like I do with .NET's. 结果,我了解了编程的所有基础知识,例如循环,变量,函数等。我最大的瓶颈是,我不像对待.NET那样了解Java软件包。

This is the reason for this thread - where do I find the following functionality in Java?: 这就是该线程的原因-在Java中哪里可以找到以下功能?

System.Diagnostics - where can I use things like stopwatch, programmatic breakpoints and loggers? System.Diagnostics-在哪里可以使用秒表,编程断点和记录器之类的东西?

Is there a Java equivalent of .NET performance counters? 是否有Java等价于.NET性能计数器?

What are weak keys in Java? Java中的弱键是什么? I just came across a collection which uses weak keys in Java so am asking here. 我刚遇到一个在Java中使用弱键的集合,所以在这里问。 :) :)

Thanks 谢谢

A dictionary which uses weak keys only keeps a weak reference to each key, so if the key is otherwise eligible for garbage collection, it may be collected and the dictionary will effectively lose the entry. 使用弱键的字典仅对每个键保持弱引用,因此,如果该键符合垃圾回收的条件,则可以对其进行收集,并且字典将有效地丢失条目。 See the docs for WeakReference for more about weak references. 有关弱引用的更多信息,请参见WeakReference的文档。

System.Diagnostics: I don't know of any equivalent for stopwatches and programmatic breakpoints. System.Diagnostics:我不知道秒表和程序断点的等效性。 For logging, look in java.util.logging or a 3rd party package such as log4j . 要进行日志记录,请查看java.util.logging或第三方软件包(例如log4j)

Performance counters: There may be some way of hooking some JVMs into Windows Performance Counters, but I've never seen them. 性能计数器:可能有一些方法可以将某些JVM挂接到Windows性能计数器中,但我从未见过。 There's VisualVM which you may find useful for some of the same things though. 虽然有VisualVM ,您可能会发现它们对于某些相同的事情很有用。

If you just want to time something, you can use System.nanoTime(). 如果只想计时,则可以使用System.nanoTime()。

long start = System.nanoTime();

// a bunch of code

long end = System.nanoTime();

System.out.println("Elapsed time in seconds: " + (end-start)/1000000000.0);

JAMon is one possible open-source Java Monitoring library that might fit your requirements. JAMon是一种可能满足您要求的开源Java监视库。

In addition, any performance/management counters are exposed through Java Management Extensions (JMX) 此外,任何性能/管理计数器都通过Java管理扩展(JMX)公开

Then you have a number of monitoring consoles: 然后,您有许多监视控制台:

  • jconsole comes with bundled with the Java installation (Swing based) jconsole与Java安装捆绑在一起(基于Swing)
  • MC4J open-source console (Swing based) MC4J开源控制台(基于SWING
  • eclipse-jmx console within Eclipse (SWT based) Eclipse中的eclipse-jmx控制台(基于SWT)
  • Most application servers will come with a web-based JMX console (eg: JBoss ) 大多数应用程序服务器将带有基于Web的JMX控制台(例如: JBoss

Alternatively, take a look at this other posting for ideas on how to monitor JMX statistics in Perfmon. 另外,请查看另一篇文章,以获取有关如何在Perfmon中监视JMX统计信息的想法。

Hope this helps. 希望这可以帮助。

As for loggers the package is: 对于记录器,软件包为:

java.util.loogging java.util.loogging

import java.util.loggin.Logger;

...

Logger logger = Logger.getLogger( this.getClass().getName() );

logger.fine( "Hello" );

logger.severe(" Oh oh ");

Here are some useful links: 以下是一些有用的链接:

http://java.sun.com/javase/6/docs/api/java/util/logging/Logger.html http://java.sun.com/javase/6/docs/api/java/util/logging/Logger.html

http://java.sun.com/javase/6/docs/api/ http://java.sun.com/javase/6/docs/api/

http://java.sun.com/javase/6/docs/api/allclasses-noframe.html http://java.sun.com/javase/6/docs/api/allclasses-noframe.html

You should check out http://commons.apache.org/ for a lot of your other queries. 您应该查看http://commons.apache.org/中的许多其他查询。 Java 1.4.2 and above have java.util.logging Java 1.4.2及更高版本具有java.util.logging

The concept of "weak keys" comes from encryption. “弱密钥”的概念来自加密。 Perhaps you were thinking of weak references? 也许您在想参考薄弱? Both .NET and Java support weak references. .NET和Java均支持弱引用。

I've noticed that common .NET classes reside in Java.Util (date is one of those common classes - something I and I'm sure every dev uses often in programming). 我注意到常见的.NET类驻留在Java.Util中(日期是这些常见类之一-我和我确定每个开发人员在编程中都会经常使用该类)。

Ah so weak keys is related to weak references - a concept I'm familiar of in .NET. 如此弱的键与弱引用有关-我在.NET中很熟悉这个概念。 That ends that question as it's answered now. 到现在为止,这个问题就结束了。 Thanks guys! 多谢你们!

As for performance monitoring (counters), looks like there's no built in functionality into Java. 至于性能监视(计数器),似乎Java中没有内置功能。 Then again, performance counters is a Windows feature and not just a class in .NET I guess? 再说一次,性能计数器是Windows的功能,而不仅仅是.NET中的类,我猜吗? I am developing on Windows. 我正在Windows上进行开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM