简体   繁体   English

在C ++之后学习Java的最佳方法是什么?

[英]Best approach for learning Java after C++?

I've been using C++ for about 6 or 7 years now, and I consider myself fluent in it. 我已经使用C ++大约6或7年了,我认为自己能流利。 I've never bothered with Java until now, but I find myself out of the job (company went under) and I need to expand my skill set. 到目前为止,我从未对Java感到困扰,但我发现自己失去了工作(公司陷入困境),我需要扩展我的技能。 Someone recommended Java, so I am wondering if there is any advice for where somebody like me might start. 有人推荐Java,所以我想知道是否有任何关于像我这样的人可能会开始的建议。 I am also interested to know what the key aspects of Java are that are most likely to come up in an interview. 我也很想知道Java在访谈中最有可能出现的关键方面。

There are some popular areas that I think of when we talk about Java 当我们谈论Java时,我会想到一些流行的领域

  • Concepts of OOP : I'm sure this will not be much different from C++: Class, Abstract Class, Interface, Polymorphism, Overriding, Overloading, Inheritance, Static member, ... Interface will likely be area that you might want to focus. OOP的概念 :我确信这与C ++没有太大区别:类,抽象类,接口,多态,覆盖,重载,继承,静态成员,......接口可能是您可能想要关注的区域。 Since this is not directly available in C++, I don't know. 由于这不是C ++中直接提供的,我不知道。
  • Core Java : Such as the basic syntax and the common classes such as Math, String, System.out, Scanner, Basic file I/O, Stream. 核心Java :如基本语法和公共类,如Math,String,System.out,Scanner,Basic file I / O,Stream。 Know the concept of Garbage Collection, Reference Type (since pointers are not available here.) Know the Java platform/technologies, J2SE, J2EE. 了解垃圾收集,引用类型的概念(因为指针在这里不可用。)了解Java平台/技术,J2SE,J2EE。 Basic GUI with Swing and its layout managers. Swing的基本GUI及其布局管理器。 Web Applications with Servlet/JSP. 使用Servlet / JSP的Web应用程序。
  • Popular tools, frameworks, and libraries : This may not as important as above bullets. 流行的工具,框架和库 :这可能不如上面的子弹那么重要。 But maybe you should know what Eclipse, Netbeans, Spring, Struts, Hibernate, EJB, Ant, JUnit, JavaDoc, are for. 但也许你应该知道Eclipse,Netbeans,Spring,Struts,Hibernate,EJB,Ant,JUnit,JavaDoc是什么。

You can always search for "C++ to Java" in Google. 您始终可以在Google中搜索“C ++ to Java”。 I'm sure there will plenty of good start points. 我相信会有很多好的起点。 Don't forget not to put * in front of var name next time you code Java :) 不要忘记下次编写Java时不要将*放在var名称前面:)

I recommend you read the book Effective Java cover to cover. 我建议你阅读有效的Java封面书。 Not only will you learn lots of good programming practices, but you will also learn more about Java than you otherwise would. 您不仅会学到很多优秀的编程习惯,而且还会学到更多关于Java的知识。 Highly recommended. 强烈推荐。 :-) :-)

As a simple example, in Java, rather than rolling bitfields by hand (which is rather painful to do in Java, and for good reason), you use an EnumSet instead. 作为一个简单的例子,在Java中,不是手动滚动位域(这在Java中是非常痛苦的,并且有充分的理由),而是使用EnumSet This is documented in Item 32. 这在第32项中有记录。

BTW, if you don't mind reading a PDF (no DRM) version, it's cheaper than hardcopy too: http://www.informit.com/title/0132345285 顺便说一句,如果你不介意阅读PDF(无DRM)版本,它也比硬拷贝便宜: http//www.informit.com/title/0132345285

There are a number of great "in depth" Java books that will teach you not only Java, but also best programming practices. 有许多非常“深入”的Java书籍不仅可以教你Java,还可以教你最好的编程实践。

If you're just interested in syntax and an introduction to the Class Hierarchy, Java in 24 hours is pretty good. 如果您只是对语法和类层次结构的介绍感兴趣,那么24小时内的Java就相当不错了。 From there, you will know enough to go and explore more on your own. 从那里,您将了解足够自己去探索更多。

I highly recommend thinking of a small project to help you learn. 我强烈建议您考虑一个小项目来帮助您学习。 In fact, think of a teeny tiny project -- it will turn out much bigger than you think! 事实上,想想一个小小的项目 - 它会比你想象的要大得多! ;) Maybe a simple shoot-em-up or a Daleks - or Asteroids -alike, or some such. ;)也许是一个简单的射击游戏或Daleks - 或类似小行星 ,或类似的。

The main thing being: for an expert-level programmer, don't try to learn Java from a book. 最重要的是:对于专家级程序员,不要试图从书中学习Java。 You can get introduced to Java via a book, but then you have to go learn on your own (or from another.) It's like learning to drive a car -- you can get the basics from a book, but you need to explore & try stuff, and someone who knows how can be very helpful. 你可以通过一本书来介绍Java,但是你必须自己学习(或者从另一本书学习)。这就像学习驾驶汽车一样 - 你可以从一本书中获得基础知识,但你需要探索和尝试一些东西,一个知道怎么会非常有帮助的人。

Some things that will help: 有些事情会有所帮助:

  • Download and bookmark the HTML Java docs. 下载HTML Java文档并为其添加书签。 You will reference them often. 你会经常参考它们。
  • Have a small project, a simple game or utility app that you estimate will take a couple of days to write. 有一个小项目,一个简单的游戏或实用程序应用程序,你估计将需要几天时间来编写。 Spend a couple of weeks writing it ;) 花几个星期写它;)
  • Note that "Java" is 3 things: 请注意,“Java”是3件事:
    • Java the programming language. Java编程语言。 Like C++ or Lisp or Perl. 像C ++或Lisp或Perl。
    • Java the Class Hierarchy. Java类层次结构。 Like STL or Cocoa. 像STL或Cocoa。
    • Java the run-time virtual machine, the JVM. Java是运行时虚拟机,JVM。

People use the word "Java" to mean all 3 things, and slip between them without much notice, so pay attention to that, when you start talking Java to people. 人们使用“Java”这个词来表示所有3个事物,并且在它们之间没有多少注意,所以当你开始与人们谈论Java时要注意这一点。

Good luck! 祝好运!

(And let us know when your game is available :) (当你的游戏可用时告诉我们:)

The biggest issue with the C++ to Java conversion is that they're so similar -- you'll find yourself doing C++-isms for a while. C ++到Java转换的最大问题是它们非常相似 - 你会发现自己在做C ++ - 一段时间了。 But it's no big deal: as suggested, read Josh Bloch's book, and run through the tutorials on java.sun.com and you'll do fine. 但这没什么大不了的:正如所建议的,阅读Josh Bloch的书,并浏览java.sun.com上的教程,你会做得很好。

In my opinion, Java sets itself apart from C++ in three ways: 在我看来,Java以三种方式将自己与C ++区分开来:

  1. Automated memory management 自动化内存管理
  2. Simplified syntax (and no preprocessor) 简化的语法(没有预处理器)
  3. The Java standard libraries Java标准库

As a former C++ guy, the first two shouldn't be a problem. 作为一名前C ++家伙,前两个应该不是问题。 (In fact, I would wager they will strike you as rather refreshing.) To get used to the libraries, I recommend Bruce Eckel's Thinking in Java - the 3rd edition is free to download. (事实上​​,我打赌它们会让你觉得相当令人耳目一新。)为了适应这些库,我推荐Bruce Eckel的Thinking in Java - 第3版可以免费下载。 Though the beginning chapters will probably be a little too basic, the sections about GUI programming, concurrency, and the various container classes will be very helpful. 虽然最初的章节可能有点过于基础,但有关GUI编程,并发和各种容器类的部分将非常有用。

Beyond that, the best way to learn any language is to read good code. 除此之外,学习任何语言的最佳方式是阅读优秀的代码。

I started by reading the Java Language Specification, version 2 at the time (2001). 我从阅读当时的版本2的Java语言规范(2001)开始。 In my view it is quite readable as specifications go. 在我看来,它的规格可读性很强。

Effective Java is good advice. 有效的Java是很好的建议。

Java Puzzlers is good to learn corner cases and possible pitfalls. Java Puzzlers非常适合学习角落案例和可能存在的陷阱。

Peter Norton的Java编程指南, “从C / C ++过渡到Java”

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

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