|
| 20 Feb 2012 04:04 PM |
How do you do java ternaries again? I think it's like:
var = conditionIsTrue ! This : That
But I can't remember exactly. |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:06 PM |
| var = condition ? ifTrue : ifFalse; |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:07 PM |
| Oh, so it's the question mark character! Well I almost got it |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:10 PM |
What are you working on? :3
|
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:11 PM |
Still working on learning the dang language :P I know most of the very basics but haven't dived into anything complex yet at all. |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:11 PM |
| Jave is fun! ^^ Yeah, What are you working on =3 |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 20 Feb 2012 04:18 PM |
I've never needed the ternary operator. If the if statement is only one line, you don't need braces. This goes for for loops too.
if (1 + 1 == 2) System.out.println("Your computer works"); else System.out.println("Your computer is broken. You should do something about that..."); // will never be run.
Anything after that first line will be executed regardless of the condition.
---------- ~pwnedu46, wiki writer~ |
|
|
| Report Abuse |
|
|
nightname
|
  |
| Joined: 10 Jun 2008 |
| Total Posts: 8960 |
|
|
| 20 Feb 2012 04:19 PM |
Great, Crazyman32 you are following the same route I took. Java is an excellent choice, nice to see you joining the gang!
|
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 20 Feb 2012 04:20 PM |
| Any of you Java programmers have an idea for a project I could use to practice swing? |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:24 PM |
| Go on the mojang website, there is a game with source. they are saying things you could do with it to practice Java |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:24 PM |
I should start using Java again... I learned it last summer and haven't really done anything with it. My dad got me a book on how to make Android Apps, maybe I should get into that...
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:27 PM |
"Any of you Java programmers have an idea for a project I could use to practice swing?"
Make a Battleship game. I just talked with my professor today and he said I could use GUIs instead of the noob console. :) |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:28 PM |
I know how to type things into the console and make it print it back out. As you can see, I'm in the boring stages of figuring out the dang thing. |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:35 PM |
Nothing is boring in Java!
Java > Lua < Java
:)
There's so much to explore in Java. :P |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:37 PM |
@AFF
"There's so much to explore in Java. :P"
And that's the difficult part about languages like Java and C++, there's like 1039600 different libraries you can import. Going from RBX.Lua, which has 0 libraries, to Java with 1039600 libraries can be kinda scary D:
GAWD DANG IT ROBLOX, NOT ALL LONG NUMBERS ARE PHONE NUMBERS
-[::ƧѡÎḾḠΰῩ::]-[::Maker of stuff and Helper of Scripting::]-
|
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 04:38 PM |
@swmaniac
Make a FileSystem class (if there isn't one already). Make sure this FileSystem has the ability to return files. Also, make a writeTo, appendAfter, appendBefore, and exists methods for the FileSystem class. :P |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 20 Feb 2012 05:04 PM |
Once you learn enough, start making Android apps. You'll need the AVD (Android Virtual Device), which works best in Eclipse. After you get that down, you can start making real money through the android app store.
---------- ~pwnedu46, wiki writer~ |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 05:05 PM |
| @pwn - That's what I was hoping to do this summer. I've got a ton to learn though and not much time. |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 05:10 PM |
I haven't cared about making apps yet. But I may be getting an Android phone (I don't like iPhones) soon, and a few custom apps would be nice. :P |
|
|
| Report Abuse |
|
|
Rukiryo
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 1490 |
|
|
| 20 Feb 2012 05:14 PM |
Java is nice because it is object oriented. Unlike other languages that require you call a draw method or draw function on objects to be drawn, it's much simpler in java. Go on youtube and watch tutorials. One guy shows you howto make a tower defense. However, practice making classes, and subclasses. Subclasses basically copy a class and addon. An example of a subclass would be:
class Bike {
And then subclasses can be more specific
class BMX extends Bike {
So any variables in bike, or anything really, will be transfered, and added onto that. So, it's easy to make a general object, then make more specific classes to fit your needs. Read the official java tutorials. They are VERY dry at the beginning, but worth it. |
|
|
| Report Abuse |
|
|
Rukiryo
|
  |
| Joined: 04 Sep 2009 |
| Total Posts: 1490 |
|
|
| 20 Feb 2012 05:17 PM |
Btw, don't JUST learn off of youtube tutorials. I worded that badly in my last post. Use them to learn specific examples. Make sure you know the basics, but those tutorials are good to get hard code examples. And ROBLOX lua is the easiest to learn, as we have a 3D space, properties stored for us, and TONS of examples.
-[ I don't have an automatic quote poster, but you just thought I did. ]- |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 06:51 PM |
"So any variables in bike, or anything really, will be transfered,"
Not quite. When you extend from an object (inheritance), you're basically creating a tiny object inside your subclass that references to the superclass.
For example, ALL objects inherit from the Object class. When you write this:
public class MyClass {
}
You're ACTUALLY doing this:
public class MyClass extends Object {
}
When you inherit, fields are NOT transferred to your class, but the class you make has a reference to the inherited class. For example ....
public class Toy { private String name; private double value;
public String getName() { return name; }
public double getValue() { return value; }
public String toString() { return name + " Value: " + value; }
public Toy(String name, double value) { this.name = name; this.value = value; } }
class Train extends Toy { private int numWheels; private int numCars; public String toString() { return super.toString() + " Number of wheels: " + numWheels + " Number of cars: " + numCars; }
public Train(String name, double value, int numWheels, int numCars) { super(name, value); this.numWheels = numWheels; this.numCars = numCars; } }
class TestClass { public static void main(String[] args) { Train theTrain = new Train("Locomotive", 25.99, 8, 3);
// Print the value alone of the train // Notice the getValue method is in the Toy class, not the Train class System.out.println( theTrain.getValue() );
// Now we print the toString of the train System.out.println( theTrain ); // println calls toString } }
Basically, the Train is an extension of the Toy class. Using inheritance, we can effectively "repeat" fields without having to declare the same fields in different classes. Also, notice the relationship between the Toy and the Train. The train "is a" Toy because we "extend" the use of the Toy class.
Thing of the superclass (in this case, Toy) as a broad group of things. Each sub-class, then, is a specific part of that group (in this case, a Train). You can also extend the Train class if you so choose, enabling you to establish different types of trains (that are also toys).
When you call a method, the JVM looks through the subclass itself (in this case, the Train). If it does not find the method in the subclass, it searches through the superclass (the Toy) for the method, as shown with calling the getValue method on the Train.
Hope this helps. :) |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 06:55 PM |
If you want to look at it from a Lua perspective, we can use metatables to imitate this subclass/superclass relationship:
Super = { Field1 = "Hai", Field2 = "Boo", getField1 = function() return Super.Field1 end, tostring = function() return "Superclass!" end } Sub = { Field3 = "OMG", Field4 = "LOL!", tostring = function() return "Subclass!" end }
setmetatable(Sub, {__index = Super});
print( Sub.getField1() ) print( Sub.tostring() )
> Hai Subclass! |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 20 Feb 2012 07:14 PM |
What's nice about ternaries (at least in C++) is that they can be in almost any part of a statement:
pie ? cake : cheese = 2; cake = pie ? 2 : 3; cake = pie ? (cheese ? 1 : 2) : 3;
etc.
I'm not sure if this stands for Java, though. There are probably some more restrictions. |
|
|
| Report Abuse |
|
|
|
| 20 Feb 2012 07:38 PM |
| Do you have a nice tutorial where i could start learning Java? |
|
|
| Report Abuse |
|
|