The different type of variables are use to store data in different format.and they get different memory size to store data.as a example the int data type is made up with 4 bytes.and others get different sizes.
before the use a variable in java, you should declare it,
e.g. :-
type name [=value1], name [=value2] ...;
this example showing you how to declare int type variable in java,
public class A
{
public static void main(String args[])
{
int marks;
float balance;
String name;
}
}
after declare the variable you can assign value for that,
public class A
{
public static void main(String args[])
{
int marks;
float balance;
String name;
marks=80;
balance=4555.75;
name="madura";
}
}
you can declare variable and assign a value as follow,
public class A
{
public static void main(String args[])
{
int marks=80;
float balance=4555.75;
String name="madura";
}
}
Sunday, October 25, 2009
Sunday, June 14, 2009
Your first Java application
Creating a Source File HelloWorld
• Any text editor can be used to create a Source file
– E.g. Notepad,word pad
• Type the following on your text editor
class HelloWorld
{
public static void main (String[] arguments)
{
System.out.println (“Hello World!!!”);
}
}
• Save the file as “HelloWorld.java” in a convenient folder (E.g.
“C:\MyJava”).
• Source Files should be saved with a .java extension. The Java
compiler will only handle source files with this file extension.
Compiling your Source File
• I assume that you have saved your source file as
“C:\MyJava\HelloWorld.java”, and you have correctly set the PATH variable.
• In the command prompt and set “C:\MyJava” as the current directory.
– You can do this by typing: cd C:\MyJava on the command prompt.
• Type: javac HelloWorld.java on the command prompt.
• If you have followed the steps correctly and all is well, you should see no
output. If not, you might see some error messages. If so, go back and recheck
your work.
• As we mentioned, javac.exe is a compiler, which converts java source code
into Java bytecode. Here, it complies the java source code in
“HelloWorld.java” and saves the resulting java bytecode as
“HelloWorld.class” in the same directory (E.g.
“C:\MyJava\HelloWorld.class”).
Executing your Java Bytecode File
• Type: java HelloWorld on the command prompt.
• You should see “HelloWorld!!!” displayed.
• As we mentioned, java.exe is an interpreter, that plays the role of the Java Virtual Machine converting the java bytecode into the machine code of the host computer and executing it.
Here, it takes the java bytecode in “HelloWorld.class” and interprets it.
• Any text editor can be used to create a Source file
– E.g. Notepad,word pad
• Type the following on your text editor
class HelloWorld
{
public static void main (String[] arguments)
{
System.out.println (“Hello World!!!”);
}
}
• Save the file as “HelloWorld.java” in a convenient folder (E.g.
“C:\MyJava”).
• Source Files should be saved with a .java extension. The Java
compiler will only handle source files with this file extension.
Compiling your Source File
• I assume that you have saved your source file as
“C:\MyJava\HelloWorld.java”, and you have correctly set the PATH variable.
• In the command prompt and set “C:\MyJava” as the current directory.
– You can do this by typing: cd C:\MyJava on the command prompt.
• Type: javac HelloWorld.java on the command prompt.
• If you have followed the steps correctly and all is well, you should see no
output. If not, you might see some error messages. If so, go back and recheck
your work.
• As we mentioned, javac.exe is a compiler, which converts java source code
into Java bytecode. Here, it complies the java source code in
“HelloWorld.java” and saves the resulting java bytecode as
“HelloWorld.class” in the same directory (E.g.
“C:\MyJava\HelloWorld.class”).
Executing your Java Bytecode File
• Type: java HelloWorld on the command prompt.
• You should see “HelloWorld!!!” displayed.
• As we mentioned, java.exe is an interpreter, that plays the role of the Java Virtual Machine converting the java bytecode into the machine code of the host computer and executing it.
Here, it takes the java bytecode in “HelloWorld.class” and interprets it.
An introduction to Java
This free tutorial series teaches the basics of Java programming. No previous Java experience is required, and its perfect for the beginner. Tutorials cover a wide range of topics, from applets and applications, to more advanced issues such as class design, event handling and networking. For best results, you should read tutorials in sequence - but feel free to skip over a few lessons if you've already been learning Java from a book or elsewhere.
Subscribe to:
Posts (Atom)
