Programming in JAVA

BloodWolfJW

Marotheit
OP
Member
Joined
Feb 11, 2011
Messages
220
Trophies
0
Location
Colorado Springs
XP
222
Country
United States
So, I'm taking programming class in high school. To my unfortunate knowledge, we are three weeks into coding in JAVA. I expected C++, but you can't win 'em all, right? Anyway, I was wondering what are the pros and cons of programming in JAVA?
 

bowser

Mwa ha ha ha!
Member
Joined
Sep 1, 2008
Messages
2,377
Trophies
1
Age
37
Location
GBAtemp ↑↑↓↓← → ← →BA
XP
2,589
Country
India
Well one of the main pros is there are no pointers in Java
biggrin.gif

(always found it hard to understand pointers)

And I personally find it easier to program in Java than in C++

Cons are you can't write homebrew in Java
ohnoes.png
(I think)
 

SifJar

Not a pirate
Member
Joined
Apr 4, 2009
Messages
6,022
Trophies
0
Website
Visit site
XP
1,175
Country
As a point of interest, Android apps are written in Java. You could potentially look into Android development if you become competent in Java. But no, you cannot write homebrew for any of the popular consoles (Wii, DS, PSP, PS3, 360) in Java AFAIK. However, as JoostinOnline said, learning Java (or any fairly standard programming language) should help to familiarise you with a lot of the basic concepts of general programming, which will make it easier to learn other languages, such as C(++).
 

ronfar23x

Member
Newcomer
Joined
May 13, 2010
Messages
17
Trophies
0
XP
35
Country
United States
Having learned Java in college and keeping up with the changes in the specs, I can offer several pros and cons.

Pros:
Cross platform. Will work on any system with a native JRE (Java Runtime Environment) written for it.
NO POINTERS! (as bowser stated above)
Handles its own garbage collection to prevent memory leaks. Although you can introduce leaks if you feel like doing tricky stuff...
Excellent entry language for anyone wanting to learn C/C++ later.

Cons:
Cross platform. No JRE, no Java programs. AFAIK the PSP is the only system that currently has a JRE, a homebrew called PSPKVM.
Resource intensive. The virtual machine must first convert the Java bytecode into native code that your machine can execute, or alternatively run it as an interpreted language similiar to Pascal or BASIC.
Always being updated. Sun/Oracle is always changing the language specifications.

I would actually recommend that you try your hand at game programming with Java for PC or web though. It is an excellent way to learn the programming structures needed for games.
 

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,565
Country
Chile
Java is much like C but OO (Object Oriented), with their own classes and stuff. Personally, I don't like it that much, just because it's a language that requires the client compiling all the code, which isn't light when you consider a lot of visuals, gfx, etc, plus slowing down the system overall.
 

Mazor

Z80 master arch
Member
Joined
Feb 14, 2008
Messages
547
Trophies
0
Age
16
Website
Visit site
XP
245
Country
bowser said:
Well one of the main pros is there are no pointers in Java
biggrin.gif

(always found it hard to understand pointers)
QUOTE(ronfar23x @ Sep 4 2011, 02:05 PM) NO POINTERS! (as bowser stated above)
What kind of argument is that? How can the lack of a language feature of this crucial kind be beneficial?

Speaking of pointers specifically, the lack of them in Java can actually make achieving what you in C and C++ would do with pointers harder. For instance you would in Java instead of simply using a pointer to a variables adress, as in C and C++, have to copy the value of the variable to a field wrapper object and then use a reference to point to it.



I could also list some pros and cons, but ronfar23x already did a pretty good job in listing the main concerns and this wikipedia article covers the rest you need to know for the basic differences between the languages.

The thing is, for a introductory high school programming course it should be almost entirely irrelevant if you are coding in Java or C++. As far as you're concerned when learning the basics, Java takes its syntax straight from C++ using object orientation. While you're still learning the basics, you'll mostly be writing the exact same code you could be writing in C++ with only a few minor differences (mainly in the very few lines of code that define the entry point of the program) .
 

Mazor

Z80 master arch
Member
Joined
Feb 14, 2008
Messages
547
Trophies
0
Age
16
Website
Visit site
XP
245
Country
bowser said:
Mazor said:
What kind of argument is that? How can the lack of a language feature of this crucial kind be beneficial?
Makes it harder to write viruses.
With your logic, a language that has as little features as possible is top tier.

We might as well just make a language that compiles as an empty file into an empty binary.
 

bowser

Mwa ha ha ha!
Member
Joined
Sep 1, 2008
Messages
2,377
Trophies
1
Age
37
Location
GBAtemp ↑↑↓↓← → ← →BA
XP
2,589
Country
India
Java lacking pointers doesn't make it a language of few features. It has a lot of other great features that C++ doesn't have. At the same time, it also lacks some features of C++. Forget about just C++, on a broader scale there are so many other languages out there like PHP, Ada, etc. to name a few. Each one has its own pros and cons. Each one is best suited for particular applications.

Applications that require a high degree of control by the programmer on memory management are better off written in C++. It's easier to write complicated programs in Java because of the availability of a large number of built-in and 3rd party libraries, not to mention its high portability to different environments. I think Ada is used a lot in defense/military applications (I may be wrong about this one).

Pointing back to your original point (pun intended
tongue.gif
), lack of pointers can be beneficial because it simplifies programming and also provides security to a certain extent.
 

Mazor

Z80 master arch
Member
Joined
Feb 14, 2008
Messages
547
Trophies
0
Age
16
Website
Visit site
XP
245
Country
bowser said:
Java lacking pointers doesn't make it a language of few features. It has a lot of other great features that C++ doesn't have. At the same time, it also lacks some features of C++. Forget about just C++, on a broader scale there are so many other languages out there like PHP, Ada, etc. to name a few. Each one has its own pros and cons. Each one is best suited for particular applications.
I have said nothing that contradicts any of what you're saying here in this thread, in fact you're mostly just reiterating my view which I have expressed on the forum before. However it would be very interesting to see you have a go at listing "a lot of great features that C++ doesn't have", go ahead.

bowser said:
Applications that require a high degree of control by the programmer on memory management are better off written in C++. It's easier to write complicated programs in Java because of the availability of a large number of built-in and 3rd party libraries, not to mention its high portability to different environments.
In which languages have you been programming? Your view of C++ really seems a bit twisted. For when memory management is one of the main concerns, assembly or most commonly C would be the optimal choice. C++ is for when you want something more high level that's faster to write and easier to maintain while still not bloated to infinity and running in a virtual fantasy land like Java does. As for portability, guess what the JVMs on platforms that can run Java are generally written in? C++. Virtually every platform that supports Java supports something lower level (that the JVMs are written in), so there's no benefit to Javas advantage in amount of platforms you can write for. The only advantage is that you have to make fewer platform-specific adjustments.

QUOTE(bowser @ Sep 4 2011, 09:42 PM)
I think Ada is used a lot in defense/military applications (I may be wrong about this one).
Pointing back to your original point (pun intended
tongue.gif
), lack of pointers can be beneficial because it simplifies programming and also provides security to a certain extent.
The "increased security" argument you're pulling is terrible. It's ridiculous to deliberately limit the power of a language by removing features, limiting the tools available to the developer just to prevent him from using them maliciously.

More importantly, you should read up on what's actually going on. If anything Java leads to less security at large as the many ways Java lets you go past system security make software written in Java a lot more vulnerable than C++ counterparts.

To make it clear, I'm no C++-fanboy. See my own post that I linked at the top of this post. For pointers, I won't further argue against the fact that a lack of them would be beneficial, the truth is that it can be hard to compare high level languages to lower level ones and the answer is very situational. On the whole though, understanding things like pointers will apart from letting you use a very powerful tool help you in pretty much any imperative programming language and is definitely something you should learn about if you want to become a good programmer.
 

Mangofett

GBAtemp Testing Area
Member
Joined
May 14, 2006
Messages
4,885
Trophies
1
Age
19
XP
1,059
Country
United States
there aren't pointers from the java programmer's perspective, only references. The java implementers are the ones dealing with pointers, since the vm and api are implemented in c/c++.

if you're actually interested in this, read the white papers on the java system.
http://java.sun.com/docs/white/index.html

of interest should be the Garbage Collection and the VM handling of references.

anyway java has it's own purposes compared to C++ or whatever... if there was only need for one language, there would only be one language
 

kevan

Imagination rules the world
Member
Joined
Dec 4, 2009
Messages
1,378
Trophies
0
Age
29
Location
Place
Website
Visit site
XP
496
Country
There is one another plus for Java

it is!

Once your fluent go learn C# and you will learn it within a few days since they are so similar.

And you can use C# for Xbox Indie Games.
 

purplesludge

anyone have any ideas for this space
Member
Joined
Mar 2, 2009
Messages
1,047
Trophies
0
Age
34
Location
wv
Website
Visit site
XP
260
Country
United States
Learning java helps create a better understanding of object oriented programming, well for me anyways. I like c/++/# better though.
Edit:My professor said that when they used to start with c/++ that more students would drop because of the initial difficulty. Now its mostly math classes that cause students to switch majors.
 

nano351

Well-Known Member
Member
Joined
Jun 6, 2009
Messages
259
Trophies
1
XP
248
Country
United States
The AP language switched from C++ to Java so that's why you are taught java in your high school classes. Java is actually quite a versatile language and not as slow and bloated as everyone makes it out to be (all remembering the early versions of java). It allows for rapid development of complicated applications. It can't be used for everything (specifically programming for embedded systems, etc) since it does compile to a special bytecode that is later dynamically recompiled to whatever assembly language the machine the VM is running on supports. It does however: allow for your code to take advantage cpu instructionse opcodes you don't even know exist (compile once, run everywhere), program from android platform (dalvik), and program for the web frontend (applets and gwt) and backend (servlets).
 

DiscostewSM

Well-Known Member
Member
Joined
Feb 10, 2009
Messages
5,484
Trophies
2
Location
Sacramento, California
Website
lazerlight.x10.mx
XP
5,488
Country
United States
Java has its uses. It is the primary language taught at Sac State (at least from what I've seen), and can use libraries like OpenGL (for which you require to use the library wrapper JOGL). This past semester, we were taught how to make a game using Java and JOGL in my game-architecture class. It was interesting experience. I still prefer C/C++, but Java isn't too bad.

Just to let people know who don't know yet, Minecraft is made in Java.

As far as pointers are concerned, Java doesn't allow you to handle them directly, but instead, it uses a lot of references (basically one copy of a set of data, and variables hold the reference to it). Anything not a primitive type is done this way, so when you have one non-primitive assigned to another non-primitive, it doesn't copy the contents, but just gives it the reference. When you want to make an actual duplicate, you use the general clone function that all objects have. Personally, I like pointers as it gives me direct access to what I want, and allows me to handle data the way I want.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: https://www.youtube.com/watch?v=BjK2lPBzGzo