|
| | #1 (permalink) |
| Registered User Join Date: Aug 2006 Location: Raleigh, NC
Posts: 1,643
| Java/Coding people, please help? Okay, so I'm starting my first ever programming class this fall quarter and I decided to learn the basics of programming before because I know there'll be geeks in the class I'm going to take and I don't want to be left behind. Here's what I have thus far: Applet public class RootApplet extends java.applet.Applet { int number; public void init() { number = 225; } public void paint(java.awt.Graphics g) { g.drawString("The square root of " + number + " is " + Math.sqrt(number), 5, 50); } } and normal class NewRoot { public static void main(String[] arguments) { int number = 0; if (arguments.length > 0) number = Integer.parseInt( arguments[0] ); System.out.println("The square root of " + number + " is " + Math.sqrt(number) ); } } I basically used an online tutorial and it went through this. Do the functions (which I'm guessing are class NewRoot and public static void main) always need to come before the commands to the program? How do you know where to space the brackets and other commands? It seems that spacing is a BIG issue and that's something I've yet to figure out. The tutorial says nothing about the incredible important of spacing and blank lines. Please help. QQ
__________________ VOCA ME BENEDICTUM ! SANA MEAM ANIMAM ! |
| | |
| | #2 (permalink) |
| Registered User Join Date: Jan 2003
Posts: 600
| It's been awhile since I've even looked at Java code but I'm pretty sure this info is accurate. Java doesn't enforce style at all (only curlys) and some teachers/classes will have different preferences. I was taught using Sun's style and there's some nifty plugins ( Checkstyle - Checkstyle 4.3 ) that will check styles for you. If I remember right, the class NewRoot is just another class declaration. I don't know shit about applets though, so as far as what you mean by the 'commands to the program' I'm not sure. It seems like if this is your first attempt programming ever this tutorial's throwing a lot at you early on. |
| | |
| | #3 (permalink) |
| Registered User Join Date: Aug 2006 Location: Raleigh, NC
Posts: 1,643
| Yeah this is my first time programming at all and I wrote that shit. But, I don't know how to determine how many spaces are needed before a } or next command/line?
__________________ VOCA ME BENEDICTUM ! SANA MEAM ANIMAM ! |
| | |
| | #4 (permalink) | |
| Registered User Join Date: Nov 2003
Posts: 286
| Quote:
For starters, whitespaces / blanklines are generally used for programming preference. I, personally, don't put a blank space inbetween my zero argument methods. One of my coworkers does. Granted our place doesn't really have set standards. IE: mine looks like methodCall(); vs. methodCall( ); I will generally insert whitespace between "ideas" or related code. int myInt = 0; float myFloat = 0; double myDouble = 0; This would be a variable decleration relation. After I declare all my variables then I'll insert a blankspace. It is really a judgement call for when to insert them. Tabbing, however, is mandatory to learn. It makes your code 10x easier to read. As a rule of thumb, anytime you insert a "{" (or one is implied) that equates to tabbing in one. Anytime you insert a "}" (again, or it is implied) you go back one tab. Example of this below. Code:
Code:
>And to the programmers out there: #1 this is a work in progress, #2 its my first C++ program so don't make fun of it!< Code:
| |
| | |
| | #8 (permalink) |
| Registered User Join Date: Nov 2003
Posts: 286
| I have no personal experience with Zeus. I use Eclipse at work and love it. Notepad is a huge pain in the ass, but since nothing is done for you alot of classes like to teach you how to program first in Notepad then go onto other shells. I'd actually argue Eclipse is better than Visual Studios to program in. |
| | |
| | #12 (permalink) |
| So there's this plane on a treadmill... Join Date: Jan 2005 Location: Southern California
Posts: 2,858
| Eclipse might be a little too good for beginners. Its auto-pilot for alot of stuff. I'd say if your just learning, stick with the text-editor or any basic interface until you know whats going on. To answer your question (even though its already been answered, but I thought i'd contribute), spaces/tabs/blank lines is all preference and is not enforced in the code at all. The compiler completely ignores it all. The reason for spacing is readability. Generally, the /tab thing is the most important, and everything else is user preference, such as some people like putting the { directly after a method such as Code:
Code:
|
| | |
| | #13 (permalink) |
| euro scum Join Date: Aug 2002 Location: Sweden
Posts: 693
+1 Internets | Here are the official code conventions from SUN btw: Code Conventions for the Java(TM) Programming Language: Contents However, this will differ from workplace to workplace which you will notice pretty early. But at least that's the official code convention for java. Last edited by slitz : 09-04-2007 at 02:33 AM. |
| | |
| | #14 (permalink) | |
| Registered User Join Date: Nov 2003
Posts: 286
| Quote:
Code:
Seems like this thread is degenerating into "these are my programming conventions" now though | |
| | |
| | #15 (permalink) | |
| Registered User Join Date: Nov 2003
Posts: 286
| Quote:
The other includes are (of course enclosed in greater/less signs as per C++): -iostream -fstream -string -sstream -vector | |
| | |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
| |