Start to Write JAVA Source Code….Let’s use “TextPad”

We also can learn about our first Java source code at http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/compile.html

1. Downloaded A free, trial version of TextPad from www.textpad.com and install it.

2. To make easier when we write and compile our Source Code, it’s good idea to set up our Preference

Preferences

There no critical preferences that need changing, but they can be set by selecting the Configure > Preferences menu item. Some things you might wish to set:

Folders
Set the Startup directory to where your files are normally located.
Document Classes > Java > Tabulation
Set the default tab spacing to 4, indent size to 4, and check both the Convert new tabs to spaces and Convert existing tabs to spaces when saving files. Tabs should generally not be used in programming because the size of tabs is not universal so someone else looking at your program will often see a mess

You Can WRITE …. COMPILE ……ans RUN….your Java Program in Texpad !

  1. Type or paste your Java program source code into the large text panel.
  2. Putting the programs directly on your desktop is not a good idea. Create a folder / directory for all of your cmis102a work in it, and a separate directory for each program. The little bit of extra work to create separate directories prevents unwanted interactions between old and new programs. It can save endless hours of frustration. This is not just an academic neatness obsession – it comes from seeing students who were unable to complete their assigments because of old-file pollution.
  3. Save it in a file with EXACTLY the same name as the “class” with an extension of “.java”. The “class” name is not the name of the course you’re taking, but the name following the word “class” in the Java source code) If the program has this class in it
        class InitialTest {
    . . .

    It must be saved in a file called InitialTest.java .Save the file in a directory for this program.

  4. Compile (perform the translation process from source code to machine code) by selecting the Tools > Compile Java menu item. If there are errors (there usually will be at first), you can go back and forth between the “Command Results” and the source code by clicking on each of them in the top left pane. Continue with this process until it compiles correctly.
  5. Run the program by choosing Tools > Run Java Application menu item. You will be using one of these to styles of interaction (Input-Output) at the beginning.
    • Console Ouput (System.out.println(…)). This will open a DOS Command Window and you will see your text output, followed by “Press any key to continue . . .”. Your program is done!
    • Dialogbox Output (JOptionPane.showMessageDialog). A dialog box will appear in the middle of your window. Click OK to close it.

TextPad FAQ

  1. Q: TextPad can’t find the Java compiler. What’s wrong?A: When TextPad can’t find the Java compiler, there are two common causes.
    1. You installed TextPad before the Java compiler. You MUST install Java first. Uninstall TextPad (from the System control panel) and reinstall it.
    2. You didn’t install the Java JDK, maybe you only have the Java JRE. If you installed Java 5 is should install by default in
      C:Program FilesJavajdk1.5.0_01

      There will also be a “jre” (Java Runtime Environment), which is appropriate, but be sure there is a “jdk” (Java Development Kit).

  2. Q: Can I run my Java program like a normal application?A: No. TextPad translates the .java files into .class files which can not be run by double-clicking them. Some IDE’s (eg, NetBeans) will produce double-clickable .jar files, and there are programs which will package your Java files into a .exe file.

Source from http://www.javafaq.nu/java-article785.html

One Response

  1. mau tnya nih bagai mana cara nya mandingin array???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: