First off, if you are in need of a good Java programming reference book, I suggest that you try Head First Java.
In this blog entry, basics in Strings in Java programming will be briefly discussed.
Assumption: You have already set up your Java development kit on your computer. (Environmental Variables, paths, etc…)
Hello World in Java
Let’s start off with a hello world. Save the following code as HelloWorld.java
class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
For Windows or Unix, go to Command Prompt, change to the Java directory, and type javac C:PathToFileHelloWorld.java
to compile the program. Then, type java HelloWorld
to run it. You should be able to see “Hello World” on your screen.
String in Java
This is a new file to compile and run. (For example, JavaStringTest.java)
class JavaStringTest{
public static void main(String[] args)
{
String MyName;
MyName = "Catzie";
System.out.println(MyName);
}
}
String Array in Java
This is how you create and loop through a String Array in Java.
class StringCharacter
{
static String[] FruitShake={"milk","sugar","strawberry","Banana","Apple"};
public static void main(String args[]){
for(int i=0;i<5;i++){
System.out.println(roseindia[i]);
}
}
}
Java Array Length
Now that you know how to create and print String array contents, let’s try to get the length of a Java array.
class StringCharacter
{
static String[] FruitShake={"milk","sugar","strawberry","Banana","Apple"};
public static void main(String args[]){
int arrayLength = FruitShake.length;
System.out.format("Number of FruitShake ingredients is %d", arrayLength);
}
}
*NOTE: Codes are not YET tested.
class StringCharacter
{
static String[] FruitShake={“milk”,”sugar”,”strawberry”,”Banana”,”Apple”};
public static void main(String args[]){
for(int i=0;i<5;i++){
System.out.println(roseindia[i]);
}
}
}
——————
you'll get an error here if you're trying to print a name of the array. you should have printed the name of the array instead..
System.out.println(FruitShake[i]);
—
nice blog way to go!:)