Java:java Quick Start [Turn]__java

Source: Internet
Author: User
Tags arithmetic operators bitwise operators logical operators
Java:java Quick Start Hello, world. source Code organization method

Java program consists of Package+class, package corresponding directory relative path, class corresponding file, such as

E:\Workspaces\MyEclipse 10\javastudy\src\com\happyframework\javastudy\hello\hello.java

1 package Com.happyframework.javastudy.hello;
2 
3 Public final class Hello {
4 public     static void Hello () {
5         System.out.println ("hello!");
6     }
7}

There are several rules about class: the name of the file must be the same as the class name (the class name of the public level). The file must contain only one public Access Basic class (which can contain multiple non-public class classes). The package name must be the same as the directory. Entry Method

App.java

1 public class App. {
2 public     static void Main (string[] args) {
3         Com.happyframework.javastudy.hello.Hello.hello ();
4     }
5}
The final project structure

Data Type

8 Atomic type integer types: Byte, short, int, and long. Decimal type: float and double. Character type: char. Boolean type: BOOL.

In addition, interface, class, and array.

The constants of the decimal type are the double type, and constants declaring float types need to use f as a suffix.

1 public class Program {
 2 
 3     /**
 4      * @param args
 5      *
 /6 public     static void main ( String[] args {
 7             float age = 28.0F;
 8             System.out.println (age);
 9     } 
11}
operatorArithmetic operators: + 、-、 *,/and%, two integers, and the result is an integer. Assignment operators: =, + =, =, *=,/=,%=, &=, |=, ~=, ^=, <<=, >>=, >>>=, + +, and--。 Comparison operators: = =,!=, <, <=, >, and >=. Logical operators:&&, | | And!. Bitwise operators:&, |, ~, ^, <<, >>, and >>>. String return directory

A string is a reference type that has the value semantics, and the strings constant implements the "element mode" in which equals is compared by the content, = = by address.

1 public class Program {
 2 
 3     /**
 4      * @param args
 5      *
 /6 public     static void main ( String[] args {
 7         String x = "De Guangwei";
 8         String y = new String ("De Guangwei");
 9         System.out.println (x.equals (y));//True         System.out.println (x = = y);//False
12     } 
14}

StringBuffer was introduced to efficiently modify the string java.

1         {
2             stringbuffer sb = 
3                     new StringBuffer ()
4                     . Append ("segment")
5                     . Append ("Light")
6                     append ("Wei");
7             
8             System.out.println (sb.tostring ());
9         }
Array

declaration Syntax

Datatype[] Name or DataType name[].

Initializing Syntax

datatype[] name = new Datatype[length].

datatype[] name = new datatype[] {element1, Element2, ... elementn}.

Datatype[] name = {element1, Element2, ... elementn}.

1 public class Program {
 2 
 3     /**
 4      * @param args
 5      *
 /6 public     static void main ( String[] args {
 7         {
 8             string[] STRs = {"Paragraph", "Light", "Wei"};
 9 
for             (String item:strs) {One                 System.out.print (item);
{ 
16}

Multidimensional Arrays

Only unequal long multidimensional array datatype[][], no datatype[xxx, xxx]. control Structure conditions: If-else if-else, Switch-case-default, and ternary operators (?:). Loops: While, do-while, for, and foreach. Labeled Block.

1 public class Program {
 2 
 3     /**
 4      * @param args
 5      *
 /6 public     static void main ( String[] args {
 7         task: {
 8 int age             =;
 9             System.out.println ("start");
One             if (age <) {break                 task;             System.out.println ("End");
}
19}

Recently think label is a good thing, at least one more choice. Method

All the assignment and method calls in Java are handled "by value", the value of the reference type is the address of the object, and the value of the original type is itself.

Java supports variable-length method parameters.

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.