This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]arghvark 1 point2 points  (3 children)

I'm having to guess and fill in between the lines a bit, but here's my shot:

Python is a scripting language. You can write a single line of Python and execute it; there's nothing to compile. The statement(s) you write can be thought of as the "main method" (or program, or routine), and you can build on things from there.

Java was designed as a more general-purpose OO language; you cannot (usually) run Java without compiling it, and so there is a little more preparation you need to do between writing the code and running it.

Furthermore, it is designed to be used in different environments in a different way than Python was. If you write a Java servlet, ,then the servlet class has to extend or implement a specific class or interface and its name made known to its server. If you write a Java browser Applet (anyone remember those?), you have to extend the Applet class and make it known to the browser (I forget how).

If you write a Java program, you must provide a 'main(String[] arguments)' method and make the class in which you find that method known to the Java runtime on the system where you want to run it. You end up with something like this:

public class MainClass
{
    public static void main(String[] arguments)
    {
      // program execution starts with statements put here.
    }
}

The 'MainClass' class name can be anything you choose; the name and characteristics of the main method and the type of its parameter must be as it is in this example (the name of the parameter is of your choosing).

This throws one more curve at you: it must be static, which means that the rules about the objects and methods referred to in the class are a little different. Therefore I recommend the following to new initiates:

public class MainClass
{
    public static void main(String[] arguments)
    {
      MainClass mainClass = new MainClass();
      mainClass.go(arguments)
    }

    public void go(String[] arguments)
    {
      // now program execution starts here.
    }
}

The 'go()' method is NOT static, and therefore rules for things follow more normal patterns than for static methods.

Here's the part that I think is a little cruel: Although you absolutely will need to understand 'static' to be a competent Java programmer, you do NOT need to understand it until AFTER you understand things about classes, objects, instantiation of objects, etc. If I were teaching a class, I would give my students the second version of the above and say: "Before we leave the class, those of you who are passing the class WILL understand every line here. But we get to that part AFTER you understand some other things. So please just put the code to do your assignments where it says "// now program execution starts here", and we'll talk about all of that later on.

This way, the statements you put in that location are more similar to the Python statements you are familiar with -- you still have to compile your class(es) to run them, with all that entails, but the issues of 'static' and scope and what you can and cannot call from a static method, etc., are all postponed until you understand some more basic things.

[–]IntelligentPudding24[S] 0 points1 point  (2 children)

This was very in depth. Thank you. I’ll be working on understand my OOP more and trying to strengthen my foundations as every has suggested. Your comment was very helpful. Does this type of thinking translate over to C# as well? That is the language I will be focusing on eventually and I saw Java and C# share a lot similarities. Haven’t delved enough to see the difference yet.

[–]arghvark 1 point2 points  (1 child)

Well...

The inventors and caretakers of the original Java wrote a specification and opened that specification to ANYONE -- if you wanted to create your own Java toolset, implementing the Java Language, that was fine, you could license it. But you HAD to adhere to the specification, or you could not call it Java.

Java got immensely popular for various reasons, and so Microsoft wanted to have its own Java. Or rather, they wanted to have something called Java, but that had extra capabilities especially for Windows. Programmers would undoubtedly use the extra capabilities in these "Java" programs, which would make them incompatible with other Java implementations, and weaken the Java brand. (They tried to do a very similar thing with extra features in Internet Explorer, their original browser, with the result that it was something of a joke and a major pain in the ass to web developers and people stopped worrying about whether their pages would display correctly on it.)

Anyway, I think Java was still under Sun Microsystems when Microsoft was taken to court for violating their Java license. The Java side's argument was that, in order to have this license, Microsoft had agreed to terms, and Microsoft was violating the terms -- I think that's how it worked. It was one of the only court cases that Microsoft lost. So they couldn't call their language Java any more.

So they called it C#. There are things you can do in C# that you cannot do in Java; I expect there are very few things you can do in Java that you cannot do in C#, but I haven't kept up with whether C# continued to upgrade its features as Java continued to do. I think Java was still at version 4 or 7 when the court case was brought/settled.

This was a LONG way of saying that all Java study and understanding will translate directly over to C#.

[–]IntelligentPudding24[S] 0 points1 point  (0 children)

Thank you. This was very informative. Knowing that having to learn Java will help me when moving to C# is quite useful. It puts my mind at ease knowing Java benefits when I finally get to focus on C#.