Advertising (This ad goes away for registered users. You can Login or Register)

Introduction to Java, one of the best language to learn OOP

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Post Reply
asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Introduction to Java, one of the best language to learn OOP

Post by asgard20032 » Wed Jul 11, 2012 5:56 am

Under construction


One of the good thing with Java, is its documentation. I don't have to write a full tutorial on learning Java, since the creator of Java already did it. So I will mostly describe why you should learn Java, and how to get started up either with Eclipse, or Netbean. I will also explain on how to compile Java to Java bytecode, from command line(Linux only, won't waste time explaining how to do it from windows, CMD not powerful enough, but its also possible to do it on windows, not hard). Its also its documentation that make it great to learn OOP, because its very complete. Most of C++ tutorial are really bad on the OOP part. C++ could be a good language to learn OOP if it could have an official documentation and tutorial. But once you learn Java, you are almost ready for C++.

I recommend before learning to learn Java to learn C. Java is a good second or third language. Java is a C like language, being one of its descendant. Curly brace, and very similar syntax. Another reason to learn C first, its because to learn OOP, we should know why OOP is actually useful, and why it was created, and the only way to know that, its by learning a language with no OOP. C is imperative.


One of the great thing about Java is portability. In fact, a Java program can run in any OS, without modification, as long as the Java virtual machine is installed. (Exception if it use a library that is OS specific, it can happen, but very rarely. One of the example(not a good example) is swt, a widget library. Although that library is available on all major OS, each OS got its native library. If we forgot to include the right library, the program could not run. The solution: Include the Linux's library, the Windows's library and mac library all at once in the package, or do a package specific for each platform. There are also library only available on one OS, but most of the time, everything is portable). Also, Java has a documentation maker, Javadoc, but if you prefer, you can also use doxygen. Java is not the fastest of available language, a compiled language will almost always be faster (there can be exception if the language is very slow...). Also, Java is a general purpose language, it can fit almost all our need: it can be a server-side language, with Apache, it can be a client-side language trough applet, it can desktop application (Minecraft is a good example), and it can also make command line program.

Some people don't like the idea to sort language either as low level or high level, but I will, to help to explain. Its always useful to learn a high level language. High level language usually have a framework around it(the Java's framework is called the Java platform), lot of function in its standard library, garbage collection, and lot other toy, helping accelerated development. Also, high level language are more secured, less vulnerability for buffer overflow(advantage of interpreter or virtual machine) and other. Most of the time, those language are interpreted, or run in a virtual machine like Java. On the other hand, low level language are faster, we have more freedom to do whatever we want, like writing an OS, but we also need to be more careful, because bug are more crucial. Low level language usually has a pointer notion. There is no extra security to help you(Interpreter usually have some feature to prevent the program from doing bad thing). And there is also machine language, either in readable format (assembly), or in raw binary (machine native code). If we use that vision to sort language, Java is a high level language, while C and C++ are more low level language. But how does Java denote itself from other major interpreted language?


Java VS other High level language

Java VS C#:
- C# faster
- Java more portable
- C# harder to decompile (Its possible to decompile Java byte code to almost the original source file, without any knowledge in programming, while with C#, we need more patience to decompile an application)
- Both have a great framework. By framework I mean the standard library around it. Lot of function available.
- Both have much the same toy available (like Garbage collection)
- Easier to compile Java, no hard time linking library. Creating and linking library with C# can be harder for newcomer.
- More IDE to work with Java
- C# can also work under GNU/Linux, trough Mono implementation, but a little buggy, not all feature available, mono tend to be outdated
- Java need only to be compiled once to be run anywhere where a Java virtual machine is available.

Java VS Python
- Python interpreted
- Java compiled to Java Bytecode
- Java is more mature
- Java is more friendly to those that come from C, Java is a descendant of C after all. Python can be a little weird when starting, because of its syntax. Python is not curly brace, but work with lot of indentation.
- Java is faster
- Both have good community behind it that can help you
- Python is like the programming language of the moment (very popular)
- Python can be used as a scripting language in another program
- Python is write once, run anywhere, no need to compile, while Java is write and compile once, and then run anywhere.
- Java more portable. Java virtual machine is on more OS and device than Python interpreter
- Python could be considered even higher level than Java and C#. We don't even have to specify the type of variable we want.
- Because python is higher level, it can lead to faster development.
- With python, can also play in the interpreter. No need to always write source in a file when we want to do test.
- With Java, we usually take latest version
- With python, 2 major version available. the 3.x and the 2.x Compatibility is not guaranteed between these two version.
- Java is targetting total portability, python is cross platform, but integrate better with OS, having some function specific to some OS. Python is a better choice when it come to write thing like plug in for your desktop, or some system program, where Java will be more suited for desktop program. For example, if you want to write a package manager, or a auto installation tool, or a screen saver, or a new toolbar, menu for your desktop, widget... Python is better suited, for its integration with the rest of the OS. Ubuntu is a perfect example for that, they use lot of python to make the system working.
- Python can also used for web development, like Java.

Java VS Perl
- Perl can be seen more like a scripting language by some people, like a way to replace the shell script. But it can also be used as a programming language, and its quite capable of producing some good program. Like python, better integration with the OS, so also perfect to write some plugin, and other for the OS.
- Java more popular
- Perl is less common on windows
- Perl is interpreted (But perl is really fast, because of its simple syntax easy to parse)
- Perl is one of the best language to make automated tool for GNU/Linux, has everything you need
- Perl is very good, just don't know how to describe it, too much to say, without the right word to explain it...
- Perl is more used on command line, than GUI program
- But Java may also be used from Command Line, don't worry

As you can see, Java compare well to other language, its not the best, some other may perform better at some task (like C# faster, but more specific to windows), but it can almost be used for anything. Its why I recommend learning Java, as it can almost always be usuful in almost any situation. Java + either Perl or Python is a good combo to do most of the thing, with C to do program that need more speed.

Example of program made using Java are Netbean and Eclipse, the best IDE available out there, Minecraft, the game of the moment, runescape... Java is also a lot used in industry.

Contrary to C++ and C#, you only need to compile Java once, and just copy the file on other OS, and it will work, if they have Java installed. Very ideal if you do like me, having your development environment in Linux, do all your programming under Linux, and just copy the result on windows. I try to install only game on windows, because installing something on windows do so much garbage in registry, appdata and other directory. So no IDE on windows, or maybe just 1 for C and C++. I really try to avoid bloating windows. Windows is so fragile. But everyone may have its reason to develop on a given system, and deploy on another. Maybe you just hate GNU/Linux, or you don't have it, and you want to write a program for your friend. Its when Java can be handy. No need to mess up with cross compiler, that can be hard to configure.

When combined with PHP and javascript(very easy to learn if you know java), it can make miracle, Applet allow very good interaction with people visiting your website. So if you mostly want to be a webmaster, Just learn Java, PHP, javascript, HTML, MySQL/PostgreSQL and CSS, and you can do almost anything. PHP with Javascript do the dynamic part, PHP on the server, java script on the client side. Java applet is like a program running inside the browser... Thus enabling you to do game, chat, program to do fractal, do calculation, form to log-in. Java applet is also secure. But sometime, it may also work not well enough. For example, minecraft don't always work in my browser.

Also Java is a big + on a CV. Many enterprise and business use it. So very good to find carer. In fact, C# is also good on a CV. But python... Not at the moment, maybe later, it will be more renowned in business and enterprise. But Java is not only a + on a CV, but also in almost every programmer toolbox.

Java actually come in several version. I recommend to read this: Difference between the different Java version. I recommend to learn JavaSE then after JavaEE. Other can be ignored, or learned if you want. To resume what is said in that link, JavaSE is for general purpose use, while JavaEE is more for web use, like professional applet. But its worth learning both. JavaFX is made to create easy interface for web and Micro Edition for platform limited on resource, like embedded system, like some cellular and router.

Tutorial & Documentation:

- JavaSE (Standard Edition)
- JavaEE (Enterprise Edition)
- JavaFX
-JavaME(Micro Edition)


Installing Java and/or OpenJDK
[spoiler][/spoiler]

A small Helloworld, and some remark to get started
[spoiler]First, before all, you must know that every program must contain the main method. Main is the entry of the application. If you forget it, you won't be able to compile. The main is generally either declared as public static void main(String[] args) or static public void main(String[] args), but we prefer to write public first. As like in any language, we need a hello world to test the installation. Copy and past that hello world (Hello world are one of the only thing I recommend to copy, instead of rewriting, as its for testing purpose, and not learning purpose. But generally, you must try to experiment, not just copy and past.)

Code: Select all

public class MyApplication {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }

}
Save this in MyApplication.java

In java, we can do comment in the same way as in C and C++, either after // or encapsulated between /* and */. I also recommend you to check out how javadoc work, a nice tool to generate high quality documentation page, without much effort.[/spoiler]

Java and command line(Linux and BSD only)
[spoiler]
Beware, GCJ is not a certified JVM. It is the GNU Classpath for Java project which has partial Java compatability under a GNU license. You should stay clear of it unless you are certain it meets your needs and you have a reason you cannot use another complete Java implementation. Shane on stackoverflow.
Its better to either use official Java implementation from oracle, or to use OpenJDK. Both are almost identical. OpenJDK can also considered official, since Oracle (Sun micro-system before oracle bought them) work on the project.
Both are stable, have the same function... But there could be bug on one implementation not here on the other. So up to you. You can also use both.
So stay away from GCJ and use java and javac, except if you know what you do. Its not dangerous, but just not as complete as the official utility.

To compile and run your program, its relatively easy, especially if java and javac are in your PATH environment variable. First, you need to compile your application to Java-byte code. This can be done easily by just opening a terminal, and do this:

Code: Select all

javac MyApplication.java
By doing this, javac, the java compiler, will produce MyApplication.class, that you can run after by simply using the Java interpreter with that file as argument:

Code: Select all

java MyApplication
The same can be done under Mac and FreeBSD. On windows, its a little harder, by the lack of auto-completion of the console. But its not that hard to do it in Windows as well from the command line.[/spoiler]

Eclipse and Java
[spoiler][/spoiler]

Netbean and Java
[spoiler][/spoiler]


Available good library:
[spoiler]Widget library (GUI library)
- swt
- swing (Widget library, the most portable one, work over awt. Its the standard library for widget, since its part of Java fundation class. Its like the native library for widget when using Java)
- awt
Multimedia and Game library
Other[/spoiler]
Advertising
Last edited by asgard20032 on Fri Jul 20, 2012 8:25 pm, edited 10 times in total.
Image

User avatar
Xian Nox
Retired Mod
Posts: 2749
Joined: Fri Nov 05, 2010 5:27 pm
Location: Over the hills and far away

Re: Introduction to Java, one of the best language to learn

Post by Xian Nox » Wed Jul 11, 2012 7:04 am

I don't want to sound too critical here, but please improve the following points:
  • Make your post easy to read. I read through this wall of text, but this doesn't mean anyone else will do so.
  • Make your explanations clear. Reading all of it, and I cannot point out what reasons you had to recommend Java.
  • Don't talk about things that have nothing to do with the topic at hand. Example, your Windows install. Nobody cares about someone else's bloated registry.
  • Okay, I got it that you didn't like Python so much, but you bash it too much. ;) Way too much.
  • GCJ?!... Why talk about gcj when you have not mentioned javac at all?
asgard20032 wrote:I will also explain on how to compile Java to Java bytecode, from command line(Linux only, won't waste time explaining how to do it from windows, CMD not powerful enough, but its also possible to do it on windows, not hard).
99% of the readers give up because they use Windows. :lol: Also, what does the poor command prompt have to do with using the JDK? When if you install an IDE like eclipse, it will take it over? :roll:
Also, talking about documentation, from my experience, Qt has way better documentation than Java.
asgard20032 wrote:In fact, a Java program can run in any OS, without modification. (Exception if it use a library that is OS specific, it can happen, but very rarely. One of the example(not a good example) is swt, a widget library. Although that library is available on all major OS, each OS got its native library. If we forgot to include the right library, the program could not run. The solution: Include the Linux's library, the Windows's library and mac library all at once in the package, or do a package specific for each platform. There are also library only available on one OS, but most of the time, everything is portable).
First of all, Java bytecode can be run in any OS that has a compatible JVM, not on just about any OS because it's not native code.
And yes, this is a terrible example. Better example, lwjgl, or lightweight Java game library, the library used by Minecraft, uses native libraries as well.
Advertising

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Introduction to Java, one of the best language to learn

Post by m0skit0 » Thu Jul 19, 2012 9:54 am

Dude, IMHO you lack some understanding about Java at basic level, as Xian Nox points out. It sounds too pretentious trying to write a tutorial about it. Just my 2 cents. Btw, how long have you been programming in Java? Good luck with it anyway. Oh and btw, I was writing one as well ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Re: Introduction to Java, one of the best language to learn

Post by asgard20032 » Fri Jul 20, 2012 8:14 pm

Xian Nox wrote:Make your post easy to read. I read through this wall of text, but this doesn't mean anyone else will do so.
Make your explanations clear. Reading all of it, and I cannot point out what reasons you had to recommend Java.
I am working on this, already rewritted why Java is great by doing a little comparaison to show what feature it offer, and it can comparate with almost any language, without saying that other language is bad, just to show that Java is not worst than other language.
Xian Nox wrote:Don't talk about things that have nothing to do with the topic at hand. Example, your Windows install. Nobody cares about someone else's bloated registry.
Just wanted to give a little example how useful it can be to be able to compile one time, and run every where, like developing on another OS than the OS we use for most task.
Xian Nox wrote:Okay, I got it that you didn't like Python so much, but you bash it too much. ;) Way too much.


Didn't wanted to be rough with Python, already reworked that part. But you have to admit that Python can be a little weird for people that normally use language with C like syntax.
Xian Nox wrote:GCJ?!... Why talk about gcj when you have not mentioned javac at all?
Its under construction, I was about to mention javac and java.
Xian Nox wrote:Also, what does the poor command prompt have to do with using the JDK? When if you install an IDE like eclipse, it will take it over?
Its always good to know how to compile manually. Sometime I use an IDE, and sometime I do it from a terminal.
Xian Nox wrote:Also, talking about documentation, from my experience, Qt has way better documentation than Java.
Never said the contrary. I just said that the Java LANGUAGE has better official documentation than other programming language. If Qt was a programming language, maybe I wouldn't say this, but as far as I know, Qt is still a full featured API.
Xian Nox wrote:First of all, Java bytecode can be run in any OS that has a compatible JVM, not on just about any OS because it's not native code.
Didn't know I had to put so much precision... I know it has to be a JVM, but since almost every device has a JVM, I tough I could just not mention it, because anyway, just by logic we can guess that it need JVM, so no need to put so much precision.
m0skit0 wrote: Oh and btw, I was writing one as well ;)
If you want, do it. It doesn't bother me, as long as there is a Java introduction or a tutorial on Wololo.
Image

User avatar
Xian Nox
Retired Mod
Posts: 2749
Joined: Fri Nov 05, 2010 5:27 pm
Location: Over the hills and far away

Re: Introduction to Java, one of the best language to learn

Post by Xian Nox » Fri Jul 20, 2012 9:16 pm

asgard20032 wrote:
Xian Nox wrote:Don't talk about things that have nothing to do with the topic at hand. Example, your Windows install. Nobody cares about someone else's bloated registry.
Just wanted to give a little example how useful it can be to be able to compile one time, and run every where, like developing on another OS than the OS we use for most task.
I think a better example is needed then. The only thing that comes to mind right now is that testing Java applications on multiple platforms is a breeze compared to C/C++. Distributing the final product is a lot easier as well with Java.
Also, your Windows registry has nothing to do with compiling. You can have a gcc or even jdk install without touching it.
asgard20032 wrote:
Xian Nox wrote:Okay, I got it that you didn't like Python so much, but you bash it too much. ;) Way too much.


Didn't wanted to be rough with Python, already reworked that part. But you have to admit that Python can be a little weird for people that normally use language with C like syntax.
Newbies don't know any syntax, so it's all the same for them whether there will be curly braces or not. Also, the strict indentations can be useful in making people write human readable code.
asgard20032 wrote:
Xian Nox wrote:GCJ?!... Why talk about gcj when you have not mentioned javac at all?
Its under construction, I was about to mention javac and java.
I'd recommend you to leave out gcj completely. It doesn't offer the complete API afaik, and compiling Java to native code isn't really needed on an introduction imho.
asgard20032 wrote:
Xian Nox wrote:Also, what does the poor command prompt have to do with using the JDK? When if you install an IDE like eclipse, it will take it over?
Its always good to know how to compile manually. Sometime I use an IDE, and sometime I do it from a terminal.
Fair enough. Still, java and javac arguments are the same, so there is no need to write Linux/BSD-only.
asgard20032 wrote:
Xian Nox wrote:First of all, Java bytecode can be run in any OS that has a compatible JVM, not on just about any OS because it's not native code.
Didn't know I had to put so much precision... I know it has to be a JVM, but since almost every device has a JVM, I tough I could just not mention it, because anyway, just by logic we can guess that it need JVM, so no need to put so much precision.
The PSP doesn't have a JVM, but it has a Python interpreter for example. Also, it's important to be accurate because the target audience are people who don't have much knowledge on the matter, so anything they learn wrong or misunderstand will become a hindrance in the future.

As for the good libraries part, I'm not sure what the idea behind it exactly is. If it's to list libraries they should look into when creating their own applications, feel free to add jorbis and JavaLayer for ogg and mp3 support respectively. Unfortunately, Java has rather poor media API that haven't been updated in some time, but these two work perfectly. Another library with good documentation and working out of the box is tiled-java (tile map support).

asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Re: Introduction to Java, one of the best language to learn

Post by asgard20032 » Fri Jul 20, 2012 9:46 pm

Xian Nox wrote:Newbies don't know any syntax, so it's all the same for them whether there will be curly braces or not. Also, the strict indentations can be useful in making people write human readable code.
I recommended to learn C first at the start of the topic, so people here should already be familiar with C.
Xian Nox wrote:I'd recommend you to leave out gcj completely. It doesn't offer the complete API afaik, and compiling Java to native code isn't really needed on an introduction imho.
If I put a quotation about GCJ bad, and I said to stay away, its because I won't explain it.
Xian Nox wrote:As for the good libraries part, I'm not sure what the idea behind it exactly is. If it's to list libraries they should look into when creating their own applications, feel free to add jorbis and JavaLayer for ogg and mp3 support respectively. Unfortunately, Java has rather poor media API that haven't been updated in some time, but these two work perfectly. Another library with good documentation and working out of the box is tiled-java (tile map support).
I will add them to the list soon, with some other useful library.

And about the registry, whenever we use an executable on windows, there are some bloat in registry, even with a simple hello world... Windows like to make an something similar to what a internet browser does with its historic, but with its registry. And I don't want to have lot of entry like eclipse version x, eclipse version x+1... whenever I update. Its not because there is no installer and Eclipse don't explicitly write in registry that windows don't do some bloat in registry.
Image

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Introduction to Java, one of the best language to learn

Post by Acid_Snake » Wed Jul 25, 2012 10:13 am

I have not learned a thing about Java, so far this post doesn't serve its goal. Oh and stop bashing other programming languages, a tutorial is about teaching from a neutral perspective, so it's the user who decides if they like what they are learning or not.

waratte
Posts: 1320
Joined: Wed Oct 20, 2010 12:03 am

Re: Introduction to Java, one of the best language to learn

Post by waratte » Wed Jul 25, 2012 2:21 pm

Acid_Snake wrote:I have not learned a thing about Java, so far this post doesn't serve its goal.
Well, it still reads "Under construction" at the top.

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Introduction to Java, one of the best language to learn

Post by Acid_Snake » Mon Aug 13, 2012 6:51 pm


User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: Introduction to Java, one of the best language to learn

Post by m0skit0 » Tue Aug 14, 2012 7:54 am

asgard20032 wrote:Java more portable [vs C#]
Wrong.
asgard20032 wrote:C# harder to decompile (Its possible to decompile Java byte code to almost the original source file, without any knowledge in programming, while with C#, we need more patience to decompile an application)
Wrong.
asgard20032 wrote:Java need only to be compiled once to be run anywhere where a Java virtual machine is available.
Same as C#.
asgard20032 wrote:Python interpreted
asgard20032 wrote:Perl is interpreted
Java is interpreted too.
asgard20032 wrote:Java is more friendly to those that come from C, Java is a descendant of C after all
Java is not a descendant of C. Its syntax is influenced by C, that's all.
asgard20032 wrote:Python could be considered even higher level than Java and C#. We don't even have to specify the type of variable we want.
Not having to declare variable types doesn't mean it's higher level. That simply means it's not strongly typed.
asgard20032 wrote:Perl is one of the best language to make automated tool for GNU/Linux, has everything you need
And for Windows. And for Mac. And for any OS. Perl probably has one of the biggest list of libraries and documentation of all programming languages (except C/C++ maybe).
asgard20032 wrote:Perl is more used on command line, than GUI program
Not really. Up to the developer.
asgard20032 wrote:javascript(very easy to learn if you know java)
Java and JavaScript have almost nothing in common, except syntax (which is C syntax anyway).
asgard20032 wrote:So if you mostly want to be a webmaster, Just learn Java, PHP, javascript, HTML, MySQL/PostgreSQL and CSS
You mean web developer, and not webmaster (webmaster is the web administrator). HTML5 and CSS3 to be concrete. And learning standard SQL is better so you can adapt to any DB server.
asgard20032 wrote:Java applet is also secure.
Well... no.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

Post Reply

Return to “Programming and Security”