# Quick java tutorials....

This topic is 4534 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So here's the thing, I am now in a Data Structures and Algorithms class it uses java. I need to re-learn java as it applies to the latest edition. I'll check sun-Microsystems web site obviously. I'd like to know if anyone knows of a way to quickly re-learn the basics, I learned java 2.1 or something quite a few years ago. Now its like what 5? Any ways that would be great any links or what not would be wonderful.

##### Share on other sites
The thing is that you dont need the GUI part right? You need I\O and the basic if else and stuff. I remember the 2.0 Java, you write classes you use the main and write methods basically the same way... You have a new class called the Scanner, with it you can do basic Input instead of System.in

import java.util.Scannerclass Test {    public static void main(String[] args) {        Scanner scan = new Scanner(System.in);                System.out.print("Enter a num: ");        int num = scan.nextInt();    }}

if, else and other stuff are the same, there is a thing about the for loop which uses a cool iteration system but i dont know it and i dont really care about it... I prefer the normal style... Becides this i dont know... Of course you have some classes for Vectors and Stack if im not mistaking and other usefull things aswell... I dont remember it all for im only learning intro to CS with Java... :)

EDIT: Scanner class is not only for input it can be applied to strings aswell if im not mistaking, but again, i suggest you check it out...

Anyway good luck! Spirit.

##### Share on other sites
The version numbering of Java is a bit messy. The current version is 1.5 (version 5.0 is just a synonyme!), and you've probably learned 1.2 or so. So the difference isn't that big that it may occur only due to version numbers.

However, the recent upgrade actually has added major changes, namely generics, boxing, and enumerations. In short: You may recall that formerly the container classes of Java were able to hold Object instances only, making it necessary to do casting and type checking. With generics you could force the compiler to do some type checking at compilation time, and to incorporate implicit castings, similarly (but noway identical) to C++ templates. Boxing means that the compiler is now able to do some conversions automatically, e.g. you could pass a double (primitive) value to a Double (object) argument. Enumerations are a special kind of class with unique instances one could say, that could be used similarly (but sometimes even better) than C++ enums. This should have given you some keywords to search for.

I don't remember the big changes of version 1.3 and 1.4, besides that the Java runtime libraries were grown, of course. Perhaps there were no language feature upgrades...

EDIT: The iterator thing Ancient Spirit mentioned is just a convenience.
// "old style" (no generics)Iterator iterator = aContainerHoldingContentType.iterator();while(iterator.hasNext()) {    ContentClass current = (ContentClass)iterator.next();   // do something ...}// "generics style" (notice the use of generics :)Iterator<ContentClass> iterator = aContainerHoldingContentType.iterator();while(iterator.hasNext()) {    ContentClass current = iterator.next();   // do something ...}// "convenient style"for(ContentClass current : aContainerHoldingContentType) {   // do something ...}

##### Share on other sites
How about say the command to import your own files like say Card.java? I know its import something but I can't remeber the specifics.

##### Share on other sites
Quote:
 Original post by GDKnightHow about say the command to import your own files like say Card.java? I know its import something but I can't remeber the specifics.

The compiler will search all directories and JARs (Java ARchives, the kinds of libraries Java uses) listed in its appropriate classpath for files you import. A Java source file is attached to a package if the package keyword is in top of the source file. Those package name together with the class name (say the qualified class name) is to be written for the import. Notice that the syntax denotes the _class_ of import, and not the _file_ (say, don't write the file suffix like .java behind).

As an example
package my.package; // declare this file's class to be part of my.packageimport from.a.package.AnyClass; // import one class from a packageimport from.another.package.*; // import all classes from another package/**This is MyClass, located in the package my.package (to be precise: located in thepackage "package" which is itself in the package "my").*/public class MyClass extends Object {   /**   imported classes could be used without writing the package in front   */   public AnyClass anyField;   /**   not imported classes could be used if qualified with package name   */   public from.a.package.AnotherClass anotherField;};

Notice that the file showing this class definition has to be saved with a relative file path as given by the package, and the file's name has to correspond with the class name. In the example above that means that the file has to be
my/package/MyClass.java
or in Win with backslashes, of course
my\package\MyClass.java
and the compiler generates the files
my/package/MyClass.class
respectively
my\package\MyClass.class

##### Share on other sites
Quote:
 Original post by haegarrI don't remember the big changes of version 1.3 and 1.4, besides that the Java runtime libraries were grown, of course. Perhaps there were no language feature upgrades...
I think assert was added in 1.4.

##### Share on other sites
Quote:
 Original post by GDKnightHow about say the command to import your own files like say Card.java? I know its import something but I can't remeber the specifics.

If the java file is in the same package or project no import is needed all is there, you can always make a package and then import it like he said :)

• 17
• 11
• 12
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999757
×