techPowerUp! Forums

Go Back   techPowerUp! Forums > Software > Programming & Webmastering

Reply
 
Thread Tools
Old Jul 5, 2011, 02:59 PM   #1
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

Help a beginner with Java

<Original question answered>

Edit: I'll post more questions as I'm learning.
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron

Last edited by Tatty_One; Jul 5, 2011 at 08:16 PM. Reason: OP request
razaron is offline  
Reply With Quote
Old Jul 5, 2011, 04:47 PM   #2
streetfighter 2
1000 Posts
 
streetfighter 2's Avatar
 
Join Date: Jul 2010
Location: Philly
Posts: 1,599 (1.51/day)
Thanks: 1,004
Thanked 765 Times in 539 Posts

System Specs

If you already have it working for classes why doesn't it work for javac? Maybe you just need to use something like "javac .\myfile.java"?

All you should need to do is add the Java directory to the "path" system variable.
streetfighter 2 is offline  
Reply With Quote
Old Jul 5, 2011, 04:48 PM   #3
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,284 (4.27/day)
Thanks: 1,219
Thanked 2,789 Times in 1,801 Posts

System Specs

set the path for it i believe.
Easy Rhino is offline  
Reply With Quote
Old Jul 5, 2011, 05:05 PM   #4
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

How do you set the path for it? I've been reading around and am completely confused.
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Old Jul 5, 2011, 05:56 PM   #5
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

Another question.

Spoiler
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Old Jul 5, 2011, 06:56 PM   #6
streetfighter 2
1000 Posts
 
streetfighter 2's Avatar
 
Join Date: Jul 2010
Location: Philly
Posts: 1,599 (1.51/day)
Thanks: 1,004
Thanked 765 Times in 539 Posts

System Specs

Quote:
Originally Posted by razaron View Post
How do you set the path for it? I've been reading around and am completely confused.
Easiest way to do it is in System Properties (in Windows 7 you can use Start->Run->systempropertiesadvanced.exe).


Then select Environment Variables and you'll see this window.


Then click "Path" in the lower box and hit "Edit" and you'll get here:


Then just add a semicolon and the path to your Java directory (with javac).
Quote:
Originally Posted by razaron View Post
Another question.
I'm pretty sure that's correct, though my terminology is a bit rusty.

Last edited by streetfighter 2; Jul 5, 2011 at 07:13 PM.
streetfighter 2 is offline  
Reply With Quote
The Following User Says Thank You to streetfighter 2 For This Useful Post:
Old Jul 5, 2011, 07:17 PM   #7
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

I ignored path and thought I had to add SOURCEPATH

Edit: I've already done that what I meant was how do I set it (cmd) to know where my .java files are, not javac.
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron

Last edited by razaron; Jul 7, 2011 at 07:44 PM.
razaron is offline  
Reply With Quote
Old Jul 5, 2011, 07:25 PM   #8
streetfighter 2
1000 Posts
 
streetfighter 2's Avatar
 
Join Date: Jul 2010
Location: Philly
Posts: 1,599 (1.51/day)
Thanks: 1,004
Thanked 765 Times in 539 Posts

System Specs

Quote:
Originally Posted by razaron View Post
Edit: I've already done that what I meant was how do I set it (cmd) to now where my where my .java files are, not javac.
Well it doesn't really work that way as far as I know, but it does work the other way.

You have to type in the directory of your .java files at one time or another. The idea is usually to cd into the directory with your .java files and then all you need to do is type "javac myfile.java". You could also make a batch file which would simplify the process even further.
streetfighter 2 is offline  
Reply With Quote
Old Jul 5, 2011, 07:26 PM   #9
Easy Rhino
Linux Advocate
 
Easy Rhino's Avatar
 
Join Date: Nov 2006
Posts: 10,284 (4.27/day)
Thanks: 1,219
Thanked 2,789 Times in 1,801 Posts

System Specs

first off, not to be a dick, but you gotta correct your grammar. i had to read your question 3 times before i figured out what you were asking. better grammar means more people willing to help.

a .java file is the source code. you run javac on the .java file to compile it into a class file which you then execute running the java <your java class file>.

so you have to either be in the directory of your compiled java program or include the entire working directory.
Easy Rhino is offline  
Reply With Quote
Old Jul 5, 2011, 07:47 PM   #10
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

I just changed the default start directory for a shortcut of cmd. That solves that problem.

Quote:
Originally Posted by Easy Rhino View Post
first off, not to be a dick, but you gotta correct your grammar. i had to read your question 3 times before i figured out what you were asking. better grammar means more people willing to help.
I couldn't think of a better way to word it (otherwise I would've just googled it...)
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Old Jul 5, 2011, 11:32 PM   #11
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

I popped my programing cherry.
Spoiler


I'm going to practice with maths for now then do that archery thing Kreij mentioned in another thread.

PS. Is it bad to have to regularly look up syntax?
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Old Jul 5, 2011, 11:47 PM   #12
A Cheese Danish
1000 Posts
 
A Cheese Danish's Avatar
 
Join Date: Nov 2006
Location: At your local vending machine
Posts: 1,914 (0.80/day)
Thanks: 121
Thanked 419 Times in 368 Posts
Send a message via AIM to A Cheese Danish

System Specs

Quote:
Originally Posted by razaron View Post
PS. Is it bad to have to regularly look up syntax?
Not at all for a beginner!
I still have to look up syntax for some things. The more you do it, the easier it will become and the less you will have to reference
__________________
My FS/FT Thread
HEATWARE Xfire Steam ID
Certs: MCTS, MCITP, HP APS
Server: AMD Opteron 170 @2.95GHz | 4GB DDR 3-3-2-7 | 1x Samsung SPT 500GB, 2x WD Black 2TB, 2x 1.5TB Western Digital MyBook
A Cheese Danish is offline  
Reply With Quote
The Following User Says Thank You to A Cheese Danish For This Useful Post:
Old Jul 5, 2011, 11:52 PM   #13
Kreij
Hardcore Monkey Moderator
 
Kreij's Avatar
 
Join Date: Feb 2007
Location: Cheeseland (Wisconsin, USA)
Posts: 12,254 (5.27/day)
Thanks: 591
Thanked 5,510 Times in 2,948 Posts

System Specs

No raz, with 1000s of APIs and a jillion methods that are available in some of the modern programming languages, and the fact that with language revisions they will add/obsolete calls, you will be using references constantly.
__________________

Cloud (noun, singular): A dynamic arrangement of multiple potential single points of failure, with a user at one end and their data at the other.


Get more tech news on a wide variety of topics at NextPowerUp
Kreij is offline  
Reply With Quote
The Following User Says Thank You to Kreij For This Useful Post:
Old Jul 7, 2011, 10:27 AM   #14
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

I was looking for java keyword definitions and found them on Wikipedia. The definition of "void" has me confused.
Wikipedia defines void as, "The void keyword is used to declare that a method does not return any value.", if that's true how did the code I posted earlier return a value?

EDIT: Also, can any of you folks remember how long it took you to start using correct case letters (upper/lowercase) in code? That seems to be the commonest error I make.
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron

Last edited by razaron; Jul 7, 2011 at 10:33 AM.
razaron is offline  
Reply With Quote
Old Jul 7, 2011, 11:45 AM   #15
Jizzler
2000 Posts
 
Jizzler's Avatar
 
Join Date: Aug 2007
Location: Geneva, FL, USA
Posts: 3,010 (1.41/day)
Thanks: 567
Thanked 606 Times in 487 Posts

System Specs

That's because it didn't return anything, unlike this (poor) example:

Code:
public int getTheNumberTen() {
	return 10;
}
Jizzler is offline  
Reply With Quote
Old Jul 7, 2011, 12:13 PM   #16
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

Then would I be correct in assuming returning a value means "returning a value to the code"?



Another question:
The following code makes cmd say "Your target is x" where x is a value.
Quote:
System.out.println("Your target is " +x_target)
However I want cmd to say "Your target is x meters away" where x is a value. The code I'm using to make this happen is,
Quote:
System.out.println("Your target is " +x_target " meters away")
, which doesn't work/compile. What do I have to do to make it work/compile?
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron

Last edited by razaron; Jul 7, 2011 at 12:44 PM.
razaron is offline  
Reply With Quote
Old Jul 7, 2011, 02:00 PM   #17
Jizzler
2000 Posts
 
Jizzler's Avatar
 
Join Date: Aug 2007
Location: Geneva, FL, USA
Posts: 3,010 (1.41/day)
Thanks: 567
Thanked 606 Times in 487 Posts

System Specs

Seems like you're missing a "+" after the x_target variable. You need it to concatenate " meters away" with the beginning portion.


That's one way to describe it. It's going to return the result so you may do with it as you will.

Ex: Lets say you have a function that returns a value describing how close a user got to the the target based on the angle, meters away, and the bow pull. It's something that you want to print out, but also save in an array so that the user can see their last ten moves or something like that.

Code:
proximity = getProximity(angle, meters, power)
Now you can print out the variable proximity and store it.

Note: Much more familiar with PHP, sorry if my Java syntax is off.
Jizzler is offline  
Reply With Quote
The Following User Says Thank You to Jizzler For This Useful Post:
Old Jul 7, 2011, 02:18 PM   #18
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

Is it better to have several small formulae,
Quote:
u = Math.sqrt((2 * P * t_bow) / m);

t = (u * Math.sin(Math.toRadians(theta))) / 4.9;

x = Math.round(t * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;

or one big formula,
Quote:
x = Math.round(((Math.sqrt((2 * P * t_bow) / m) * Math.sin(Math.toRadians(theta))) / 4.9) * u * Math.cos(Math.toRadians(theta)) * 100)/100.0d;
?
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Old Jul 7, 2011, 03:13 PM   #19
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

So far I have this for the archery game,
Spoiler


How do I make it return to the bit just after it's worked out "x_target" if "d_target" > 1?
Other than that it works, yay.

EDIT: I can advertise this game as using real Newtonian physics, lol.
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron

Last edited by razaron; Jul 7, 2011 at 03:18 PM.
razaron is offline  
Reply With Quote
Old Jul 7, 2011, 03:29 PM   #20
streetfighter 2
1000 Posts
 
streetfighter 2's Avatar
 
Join Date: Jul 2010
Location: Philly
Posts: 1,599 (1.51/day)
Thanks: 1,004
Thanked 765 Times in 539 Posts

System Specs

Is this what you want?
Spoiler
streetfighter 2 is offline  
Reply With Quote
The Following User Says Thank You to streetfighter 2 For This Useful Post:
Old Jul 7, 2011, 03:58 PM   #21
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

Quote:
Originally Posted by streetfighter 2 View Post
Is this what you want?
Spoiler
Couldn't get what you wrote to work. However that helped me learn the do-while thing, so thank you.

Here's my awesome game:
Spoiler
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
The Following User Says Thank You to razaron For This Useful Post:
Old Jul 7, 2011, 04:43 PM   #22
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

What would be a logical step up from the archery game? Preferably something that doesn't require much imagination (so no text adventure).
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Old Jul 7, 2011, 05:59 PM   #23
PopcornMachine
1000 Posts
 
PopcornMachine's Avatar
 
Join Date: Aug 2009
Location: Los Angeles/Orange County CA
Posts: 1,144 (0.82/day)
Thanks: 2,028
Thanked 383 Times in 308 Posts

System Specs

My advice is to learn Perl or Python or even C.

I hate Java. It's buggy as hell.
PopcornMachine is offline  
Reply With Quote
Old Jul 7, 2011, 07:18 PM   #24
streetfighter 2
1000 Posts
 
streetfighter 2's Avatar
 
Join Date: Jul 2010
Location: Philly
Posts: 1,599 (1.51/day)
Thanks: 1,004
Thanked 765 Times in 539 Posts

System Specs

Quote:
Originally Posted by razaron View Post
What would be a logical step up from the archery game? Preferably something that doesn't require much imagination (so no text adventure).
Seeing as how 99% of the world does not use console applications, I'd suggest making a GUI for your archery game. The structure of GUI code is fairly similar in most languages, meaning they're mostly event driven. Here's the (rather poorly written IMO) official tutorial.

I'd create a simple window with a couple edit controls (text boxes) for inputting theta/P and a button to start the simulation. Then I'd plot the arrows path and show the origin and target.

It sounds complicated but it's actually very easy.
streetfighter 2 is offline  
Reply With Quote
The Following User Says Thank You to streetfighter 2 For This Useful Post:
Old Sep 5, 2011, 02:10 PM   #25
razaron
500 Posts
 
razaron's Avatar
 
Join Date: Apr 2008
Location: london
Posts: 612 (0.33/day)
Thanks: 171
Thanked 187 Times in 142 Posts

System Specs

What am I doing wrong with this piece of code?
Spoiler

I'm trying to make a 25 places big vector with each place containing an integer with the same value as the place itself (hence the (i, i)). Then it should display the 5th int in the vector.
The errors:
Spoiler
__________________
My Anime List
BattleTag (EU): razaron#1882
Steam: Razaron
razaron is offline  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Very noobi question in Java Flash Programming & Webmastering 7 Apr 20, 2011 06:31 PM
C# question (java related) spy2520 Programming & Webmastering 33 Feb 28, 2010 12:32 PM
My First Programming Question (Java) spy2520 Programming & Webmastering 13 Oct 29, 2009 03:17 AM
Java partially filled arrays question wolf2009 Programming & Webmastering 1 Apr 14, 2009 01:09 AM
Java Question dcf-joe Programming & Webmastering 1 Dec 24, 2008 01:12 PM


All times are GMT. The time now is 05:12 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
no new posts