tags:

views:

151

answers:

4

I'm a beginner at Java Programming. I have the experience that I used DX library for before in C++. The DX library worked with simple functions, but the library of the JAVA does not work with functions.

How can I understand Java Class libraries?

+2  A: 

I highly suggest going through the Sun Java Tutorial, and then asking specific questions about specific problems based upon that. The Java libraries are actually fairly simple to work with, but there are a lot of them.

Are you using an IDE to get started? They are strongly recommended for beginning Java programmers.

jsight
+2  A: 

Let us start with a simple example

class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

This uses the "out" member of java.lang.System; which is a PrintStream; it uses the PrintStream type's println method to print a string with a following line-feed.

Steve Gilham
+1  A: 

It sounds like your usage of C++ has been fairly limited and that you have not truly taken advantage of the OOP features of the C++ langauge, given this question. The Java API is a class library. There are no free-standing functions in Java (unless you count static functions as free-standing functions). Please familiarize yourself with OOP and the Java language, and then come back with specific API questions.

Michael Aaron Safyan
+2  A: 

Not functions, but methods of Objects. That's a big difference, and the key to OO.

Simple example:

String x = new String("abcdef");

String y = x.substring(2);

Note the idea you start by getting a reference to an object of a particular type, here x is a String.

You then can ask x to do lots of different things, such extract substrings. The full set of what you can do is documented in the String class.

So a way to approach things is to say

  1. What type of object do I need? A touch of googling tends to help here.
  2. How do I create it - sometimes it's just new Class(), sometimes another class makes them for you. The class documentation typically tells you how.
  3. Now what can I do with it? Read the method documentation.

As has been pointed out, the online tutorials will help. Take the time to work through some.

IDEs (Ecplise is free for example) will give you "help" offering menus of availble methods when you have an object.

Very often for each new thing you want to do there are useful code snippets.

djna