Simple Java Programming Application --- 1. HelloWorld (the source of HelloWorld); 2. Output Personal Information 3. Output special patterns and helloworld personal information
After setting up a Java development environment, many of our partners are eager to develop their first Java program.
Here, Niu Ge provides three simple Java applets. You can enjoy the pleasure of Java programming according to the four applets provided by Niu ge.
1. Output HelloWorld
(A little story about the sources of HelloWorld)Maybe many friends may have a question here, that is, why is the first program to be learned in every Programming Language Output helloworld? Niu ge had the same questions as you did before. Niu ge had contact with C, C ++, C #, and Python programming languages, the first Applet in the tutorial is to output helloworld. So Niu Ge couldn't help but look up the information. The reason for the incident was this. Let me explain it to my friends.
This is the most famous program. For every programmer, this program is almost the first sample program in every programming language. So where did this famous program come from?
In fact, the function of this program only tells the computer to display the Hello World sentence. Traditionally, programmers generally use this program to test a new system or programming language. For programmers, seeing these two words on the computer screen often means that their code can be compiled, loaded, and run properly. This output is to prove this.
This test program has a special symbolic significance to a certain extent. Over the past few decades, this program has gradually evolved into a prestigious tradition. Almost all programmers, whether before you or after you, after the first successful communication with the computer, to some extent, their adrenaline will rise sharply (EXCITED ). The following is the story of the birth of this famous program.
Hello, World was first created by Brian Kernighan. In 1978, Brian Kernighan wrote a programming book named "C programming language", which was widely used by programmers. The Hello World program he introduced for the first time in this book originated from a Programming Tutorial on B language written in 1973:
Main (){
Extrn a, B, c;
Putchar (a); putchar (B); putchar (c); putchar ('! * N ');
}
A 'hangel ';
B 'o, W ';
C 'orld ';
But unfortunately, when the magazine Forbes India interviewed him, he had a bit vague about some of his memories of the legend. When asked why he chose "Hello, World !』 He replied, "I only remember, I seem to have read a cartoon about an egg and a chicken. In that cartoon, the chick said "Hello World '』.
After explaining this story clearly, we will write the first Java program.
Public class HelloWorld {
Public static void main (String args []) {
System. out. println ("HelloWorld ");
}
}
Haha .... Is there a sense of accomplishment?
Ah? Do you know where to write the above lines of code? Next, I will take my friends to output this result step by step and say "HelloWorld" to the computer world ".
1. Create a new text file named helloworld.txt in the English directory of any disc.
2. Change the suffix of helloworld.txt to. java, so that the file becomes HelloWorld. java. A file suffixed with. java is the source file of the Java program. The essence of the code we usually call is to edit a file suffixed with. java.
3. Open HelloWorld. java as a text file and enter the code we want to enter.
4. Open the command line interface, go to the directory of the edited Java source file, and use the javac command to compile HelloWorld. java. Compile HelloWorld. java to generate the HelloWorld. class file .. Class files are bytecode files that can be executed by computers.
5. Use the Java command to execute the HelloWorld. class file and output HelloWorld.
Note the commands entered by your brother Niu in the command line. Press the Enter key to run the command. The subsequent Programs follow the above steps.
The output is Helloworld.
Ii. Output personal information
1 public class Message {2 public static void main (String args []) {3 4 System. out. println ("Name: James"); 5 System. out. println ("Gender: male"); 6 System. out. println ("Age: 30"); 7 System. out. println ("contact info: 1234456789"); 8} 9}
Output result:
Name: James
Gender: male
Age: 30 years old
Contact: 12345679
II,
Write a Java program and output the following shapes
*
**
***
****
*****
*****
*****
1 public class Demo{ 2 public static void main(String args[]){ 3 4 System.out.println("*"); 5 System.out.println("**"); 6 System.out.println("***"); 7 System.out.println("****"); 8 System.out.println(""); 9 System.out.println("*****");10 System.out.println("*****");11 System.out.println("*****");12 } 13 }
Output result:
*
**
***
****
*****
*****
*****