Chapter 3 fundamental programming structures in Java

Source: Internet
Author: User

1. A Simple Java Program

2. Comments

3. Data Types

4. Variables

5. Operators

6. String

7. Input and Output

8. Control Flow

9. Big Numbers

Ten. Arrays

1. A Simple Java Program

1  Public class simple_java{2      Public Static void Main (string[] args) {3         System.out.println ("Hello world!" ); 4     }5

Java is case sensitive (casing-sensitive). If you made any mistake in capitalization (such as typing main instead of main), the program would not run.

The keyword public was called an access modifier (access control modifier). These modifiers control the level of access other parts's program has to this code

The keyword class reminds you, everything in a Java program lives inside a class.

Following the keyword class is the name of the class.

You need to make the file name for the source code the same as the name of the "public class" with the extension. Java AppE nded.

We is using the System.out object and calling its Println method. Java uses the general Syntax:Object.method (parameters)

When you compile this source code, you end up with a file containing the bytecodes for this class. The Java compiler automatically name

The bytecode file Simple_java.class and stores it in the same directory as the source file. Finally, launch the program by issuing the following command:

Java firstsample

To run a compiled program, the Java Vsan always starts execution and the code in the main method in the class you indicate.

2. Comments

3. Data Types

In Java, your use of the keyword final to denote a constant.

' A ' is a char Type with value 65.It is differnet from "a", astring containing a signle character.

Java strings is sequences (sequence) of the Unicode characters.

3.1 Substrings

You can extract a substring from a larger string with the substring method of the string class.

1 1 string greeting = "Hello"; 2 string s = greeting. Substring (0,3);

Creates s string consisting of the characters "Hel"

  

  

Chapter 3 fundamental programming structures in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.