Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-12-2008
Member
 
Join Date: Oct 2008
Posts: 62
How to Start programming in JAVA ?

Hello I am a novice in the programming, I just want install the Java software on my computer, I would like to know the steps of writing a program in its execution. thank you in advance
Reply With Quote
  #2  
Old 12-12-2008
Member
 
Join Date: May 2008
Posts: 115
Re: How to Start programming in JAVA ?

Hello

To write a java program when nothing is known we must first
write a minimalist source code in a text editor:


Code:
public class Program {
public static void main (String [] args) 
    {
         System.out.println ( "Hello world"); 
    }

}

This code must be placed in a file that is called Program.java
the same name as the class defined in the file.

Then if you have installed a tool to compile the .java file name in jdk file bin folder you typed the command in the command prompt.

"javac Program.java" in a command prompt.
This phase is called phase compilation.

If it does not work:
1) you make sure you have a javac.exe on your machine or install a jdk that goes well, this one is available from sun.
2) javac.exe is present, therefore you add to your PATH machine, and you restart the command prompt.

Now you see that a "Program.class was generated, so you can move to the execution of the program by typing.
"Java Program"
This phase is called phase of execution.

You should see in your command prompt: "Hello world"

With regard to learn java and make an application that meets
your desires and / or needs, I advise you to browse tutorials that does help.

Good luck,
Reply With Quote
  #3  
Old 12-12-2008
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: How to Start programming in JAVA ?

The simplest and most user-friendly is still using an integrated development environment Eclipse type:
http://www.eclipse.org/
Reply With Quote
  #4  
Old 12-12-2008
Member
 
Join Date: May 2008
Posts: 115
Re: How to Start programming in JAVA ?

Dont Forget there is Netbeans Also

NetBeans - Development Simplified

A free, open-source Integrated Development Environment for software developers. You get all the tools you need to create professional desktop, enterprise, web, and mobile applications with the Java language, C/C++, and even dynamic languages such as PHP, JavaScript, Groovy, and Ruby. NetBeans IDE is easy to install and use straight out of the box and runs on many platforms including Windows, Linux, Mac OS X and Solaris.

The NetBeans IDE 6.5 provides several new features and enhancements, such as rich PHP, JavaScript and Ajax editing features, improved support for using the Hibernate web framework and the Java Persistence API, and tighter GlassFish v3 and MySQL integration.
Reply With Quote
  #5  
Old 12-12-2008
Member
 
Join Date: May 2008
Posts: 2,383
Re: How to Start programming in JAVA ?

No, to begin, it is better not to use IDE, you must first understand how language works and tools before you try to provide facilities as FDI. Thus, once you have the experience, you can switch to Eclipse, NetBeans, JBuilder, BlueJ ... and when your IDE favorite dysfunctional, you're able to make a diagnosis and find a workaround, it makes you less dependent on its whims, for example if the SVN plugin does not work anymore, if you created JAR does not when you run outside your environment ... Good luck.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 12-12-2008
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: How to Start programming in JAVA ?

yup opaper is right. Nothing replaces a good understanding of what we do, even if initially it requires a lot of writing code. Unfortunately, this is an approach that is lost ...
Reply With Quote
  #7  
Old 16-12-2008
Member
 
Join Date: Dec 2008
Posts: 3
Re: How to Start programming in JAVA ?

Hello

Thanks for the post. It helps me to write the program in java language...

Thanks
Reply With Quote
  #8  
Old 22-12-2008
Member
 
Join Date: Dec 2008
Posts: 4
Re: How to Start programming in JAVA ?

hi! here is a sample program that you may think as a source ^_^

this is just a simple sample of a java program just for you dude hope this sample could help.

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;

public class Calculator implements ActionListener{


char o;
int ctr=0;
String value="", cv="", oBtn;
Double answer, v1, v2;
Double NumberConverted;
Double mem;

Frame f;
Panel p1, p2, p3, p4, p5, p6;
private TextField tField;
private Menu EditMenu;
private MenuBar menuBar;
private MenuItem fmi1, fmi2, fmi3;
private Button num0, num1, num2, num3, num4, num5, num6, num7, num8,num9;
private Button bAdd, bSub, bMul, bDiv, bPer, bSqrt, bFrac, bInt, bDot,bCE, equals, backspace, clear,bMC,bMR,bMS,bMp;
private Button empty;


Calculator(){
f = new Frame("Calculator");

menuBar = new MenuBar();
EditMenu = new Menu ("Edit");

fmi1 = new MenuItem(" Copy ");
fmi2 = new MenuItem(" Paste ");
fmi3 = new MenuItem(" Quit ");

EditMenu.add(fmi1);
EditMenu.add(fmi2);
EditMenu.addSeparator();
EditMenu.add(fmi3);

p1 = new Panel();
p2 = new Panel();
p3 = new Panel();
p4 = new Panel();
p5 = new Panel();
p6 = new Panel();

tField = new TextField(35);

num0 = new Button ("0");
num1 = new Button ("1");
num2 = new Button ("2");
num3 = new Button ("3");
num4 = new Button ("4");
num5 = new Button ("5");
num6 = new Button ("6");
num7 = new Button ("7");
num8 = new Button ("8");
num9 = new Button ("9");
bAdd = new Button ("+");
bSub = new Button ("-");
bMul = new Button ("x");
bDiv = new Button ("/");
bPer = new Button ("%");
bSqrt = new Button ("sqrt");
bFrac = new Button ("1/x");
bInt = new Button ("+/-");
bDot = new Button (".");
empty= new Button ("M");
empty.setEnabled(false);
bCE = new Button ("CE");
bMC = new Button ("MC");
bMR = new Button ("MR");
bMS = new Button ("MS");
bMp = new Button ("M+");
equals = new Button ("=");
backspace = new Button ("Backspace");
clear = new Button ("C");
}


public void launchFrame(){

tField.setText("0.");
tField.setEnabled(false);

menuBar.add(EditMenu);

p2.add(empty);
p2.add(backspace);
p2.add(bCE);
p2.add(clear);

p3.add(bMC);
p3.add(num7);
p3.add(num8);
p3.add(num9);
p3.add(bDiv);
p3.add(bSqrt);

p4.add(bMR);
p4.add(num4);
p4.add(num5);
p4.add(num6);
p4.add(bMul);
p4.add(bPer);

p5.add(bMS);
p5.add(num1);
p5.add(num2);
p5.add(num3);
p5.add(bSub);
p5.add(bFrac);

p6.add(bMp);
p6.add(num0);
p6.add(bInt);
p6.add(bDot);
p6.add(bAdd);
p6.add(equals);

p2.setLayout(new GridLayout (1, 3, 2, 2) );
p3.setLayout(new GridLayout (1, 3, 2, 2) );
p4.setLayout(new GridLayout (1, 3, 2, 2) );
p5.setLayout(new GridLayout (1, 3, 2, 2) );
p6.setLayout(new GridLayout (1, 3, 2, 2) );

f.setLayout(new GridLayout (6, 1) );
f.setResizable(false);
f.setSize(300,250);
f.add(tField);
f.add(p2);
f.add(p3);
f.add(p4);
f.add(p5);
f.add(p6);
f.setVisible(true);
f.setMenuBar(menuBar);
f.pack();

// ACTION LISTENERS
clear.addActionListener(this);
bCE.addActionListener(this);

num0.addActionListener(this);
num1.addActionListener(this);
num2.addActionListener(this);
num3.addActionListener(this);
num4.addActionListener(this);
num5.addActionListener(this);
num6.addActionListener(this);
num7.addActionListener(this);
num8.addActionListener(this);
num9.addActionListener(this);

bAdd.addActionListener(this);
bSub.addActionListener(this);
bMul.addActionListener(this);
bDiv.addActionListener(this);
bPer.addActionListener(this);

bInt.addActionListener(this);
bSqrt.addActionListener(this);
bFrac.addActionListener(this);
bDot.addActionListener(this);
bMC.addActionListener(this);
bMR.addActionListener(this);
bMS.addActionListener(this);
bMp.addActionListener(this);
empty.addActionListener(this);

equals.addActionListener(this);
backspace.addActionListener(this);

fmi1.addActionListener(this);
fmi2.addActionListener(this);
fmi3.addActionListener(this);
}



/* |------------ START OF ACTION EVENTS ------------| */


public void actionPerformed(ActionEvent a){


try{
/* |-------- Handling Exceptions ---------| */


if(a.getSource()==num0){
value+=0;
tField.setText(value);
}
if(a.getSource()==num1){
value+=1;
tField.setText(value);
}
if(a.getSource()==num2){
value+=2;
tField.setText(value);
}
if(a.getSource()==num3){
value+=3;
tField.setText(value);
}
if(a.getSource()==num4){
value+=4;
tField.setText(value);
}
if(a.getSource()==num5){
value+=5;
tField.setText(value);
}
if(a.getSource()==num6){
value+=6;
tField.setText(value);
}
if(a.getSource()==num7){
value+=7;
tField.setText(value);
}
if(a.getSource()==num8){
value+=8;
tField.setText(value);
}
if(a.getSource()==num9){
value+=9;
tField.setText(value);
}



if (a.getSource() == bAdd){
v1 = Double.parseDouble( tField.getText() );
ctr=0;
o = '+';
value="";
tField.setText("" +value);
}

if (a.getSource() == bSub){
v1 = Double.parseDouble( tField.getText() );
ctr=0;
o = '-';
value="";
tField.setText("" +value);
}

if (a.getSource() == bMul){
v1 = Double.parseDouble( tField.getText() );
ctr=0;
o = 'x';
value="";
tField.setText("" +value);
}

if (a.getSource() == bDiv){
v1 = Double.parseDouble( tField.getText() );
ctr=0;
o = '/';
value="";
tField.setText("" +value);
}

if (a.getSource() == bPer){
v1 = Double.parseDouble( tField.getText() );
ctr=0;
value="";
answer = (v1/100);
tField.setText("" +answer);
}




/* |-- EQUALS ACTION --| */

if(a.getSource()==equals){
value="";
v2 = Double.parseDouble(tField.getText());

if(o=='+'){
ctr=0;
answer = v1 + v2;
tField.setText("" +answer);
value=""; v1=null; v2=null;
}
else if(o=='-'){
ctr=0;
answer = v1 - v2;
tField.setText("" +answer);
value=""; v1=null; v2=null;
}
else if(o=='x'){
ctr=0;
answer = v1 * v2;
tField.setText("" +answer);
value=""; v1=null; v2=null;
}
else if(o=='/'){
ctr=0;
answer = v1 / v2;
tField.setText("" +answer);
value=""; v1=null; v2=null;
}
else if(o=='%'){
ctr=0;
answer = v1 % v2;
tField.setText("" +answer);
value=""; v1=null; v2=null;
}
else{}
}


/* |-- Memory --|*/
if (a.getSource () == bMp) {
empty.setEnabled(true);

}
if(a.getSource ()==bMS){
mem = Double.parseDouble(tField.getText());
}
if(a.getSource ()== bMR){
tField.setText("" +mem);
}
if(a.getSource ()== bMC){
tField.setText("0.");
mem=null;
empty.setEnabled(false);
}

/* |-- Clear --| */
if(a.getSource()==clear){
ctr=0;
v1=null;
v2=null;
value="";
answer=0.;
tField.setText("0.");

}

if(a.getSource()==bCE){
ctr=0;
value="";
tField.setText("0.");
}


/* |-- Point --| */
if(a.getSource() == bDot){
if(ctr==0){
value+=".";
ctr+=1;
tField.setText("" +value);
}
else{
System.out.print("");
}

}



/* |-- Back Space --| */
if(a.getSource() == backspace){
value = value.substring(0, value.length()-1 );
tField.setText("" +value);
}



/* |-- Square Root --| */
if(a.getSource() == bSqrt){
ctr=0;
value = "";
v1 = Math.sqrt( Double.parseDouble( tField.getText() ) );
tField.setText("" +v1);
}



/* |-- Integer --| */
if(a.getSource() == bInt){
ctr=0;
NumberConverted = ( Double.parseDouble(tField.getText()) * -1 );
value = "";
tField.setText("" +NumberConverted);
}



/* |-- Reciprocal --| */
if(a.getSource() == bFrac){
ctr=0;
value = "";
Double NumberContainer = ( 1 / Double.parseDouble(tField.getText() ) );
tField.setText("" +NumberContainer);
}


// ------------ Menu Item Actions ------------ //

if(a.getSource() == fmi1){
cv = tField.getText();
}

if(a.getSource() == fmi2){
tField.setText("" +cv);
}

if(a.getSource() == fmi3){
System.exit(0);
}

} // End of Try


/* |-------- Attempting To Catch Runtime Errors ---------| */

catch(StringIndexOutOfBoundsException str){}
catch(NumberFormatException nfe){}
catch(NullPointerException npe){}

} // END OF ACTION EVENTS


public static void main (String args[]){
Calculator s = new Calculator();
s.launchFrame();
}
}
^_^
Reply With Quote
  #9  
Old 22-12-2008
Member
 
Join Date: Oct 2008
Posts: 62
Re: How to Start programming in JAVA ?

Thanks ayaboy for your reply,

I suppose you have given "Calculator" Program, but can you tell me that whether this will run in normal JAVA compiler coz I have 1.4 ver and you have used awt packages in the your programs.

Thanks again.
Reply With Quote
  #10  
Old 22-12-2008
Member
 
Join Date: Dec 2008
Posts: 4
Re: How to Start programming in JAVA ?

hi! ^_^ i think it will run just try it. as long that it is a java compiler you may try it and tell me what will happen.
Reply With Quote
  #11  
Old 22-12-2008
Member
 
Join Date: Oct 2008
Posts: 62
Re: How to Start programming in JAVA ?

hello ayaboy,

I tried out but the problem is that i have installed visual studio 2005 installed on my computer and whenever i try to run the calculator.java file it opens with the visual studio debugger window and gives me "calculator package is not properly setup", whats that error mean and where i have to put that package?

Thanks for your help..
Regards.
Reply With Quote
  #12  
Old 22-12-2008
Member
 
Join Date: Dec 2008
Posts: 4
Re: How to Start programming in JAVA ?

hi! keegan its hard for me to pin point the problem keegan i am sorry i want to help you maybe it is another version of java compiler you have. by the way i use the jcreator to run my java program.that's the one i use i don't know the problem why the visual studio 2005 will open if you will try to run the program. i am sorry
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Start programming in JAVA ?"
Thread Thread Starter Forum Replies Last Post
Help with java programming term cloud101 Software Development 1 06-02-2012 01:45 PM
Java programming overlord94 Software Development 1 07-10-2011 07:45 PM
Java Programming using Adventnet SNMP Java API ROCKING_Suhas Software Development 5 17-07-2010 06:52 AM
What is RMI in java programming? Sonam Goenka Software Development 5 12-03-2010 08:37 PM
Where to start programming from Balamani Software Development 5 27-11-2009 09:50 PM


All times are GMT +5.5. The time now is 05:05 PM.