Learning java (1) Basic java syntax from scratch

Source: Internet
Author: User

Learning java (1) Basic java syntax from scratch

I have been working in VB for a month from the company, but now I want to work in java. When I am looking for a job, I always need some project experience and experience, which is somewhat uncomfortable. All languages have a total

I don't believe that java is so difficult? Give yourself some time to learn. Stick to one month of self-study and check whether your efforts are useful. This course is based on java core technology.

At the beginning of version 9th, I wrote an article for each chapter. If not, please advise.

"Most of the powerful languages such as Java are not easy to learn." at the beginning of chapter 1, I will give you an example... If you say this, I will show it to you! Chapter 1 and Chapter 2

Let's talk about the concept and development of java. skip this step!

1. helloworld

By convention, a simple program is used to start learning a language: hellowrold; a java class name starts with an uppercase letter, and multiple letters start with an uppercase letter. Class represents a class, java

The base is composed of classes, which contain attributes and methods. The main method is the same as the main method in C language. It is the entrance to each program running. Each class can have only one class

Public. In addition, each sentence of java code ends with a semicolon;

1 public class HelloWorld {2     3     public static void main(String[] args) {4          5         System.out.println("HelloWorld");6     }
View Code

2. Data Type

Integer: byte: 1 byte; (1 byte 8 binary 00000000, range:-2 ^ 8 to 2 ^ 8-1) short: 2 byte int: 4 byte; long 8 bytes;

Floating point type: indicates the type with a decimal point; float: 4 bytes; double: 8 bytes;

Char: Single-character type, "A", "a", and other escape characters "/n;

Boolean Type: FALSE true; true or FALSE!

3. Variables

In java, each variable belongs to a type before the variable. For example, int I. At the same time, each variable must be assigned an initial value. Otherwise

An error is reported;

4. Operators

+-*/%: Addition, subtraction, multiplication, division, and remainder; ++, -- auto-increment, auto-subtraction operator; & and, | or ,~ Non, ^ exclusive or; &, | or;

5. Forced type conversion

For example, if the double type is converted to the int type, the following decimal places may be absent, and the compiler considers it wrong. In this case, the forced conversion is required, for example: int I = (int) 4.3;

6. String class

  

@ Test/*** common methods for testing String. String is implemented by arrays. Therefore, modifying a String is equivalent to creating a new String */public void testString () {String s = "hello"; // determines whether the System is empty. out. println (s. isEmpty (); // determines whether the string is equal to System. out. println (s. equals ("Hello"); // judge whether the string is equal, case-insensitive System. out. println (s. equalsIgnoreCase ("Hello"); // returns the System string with the subscript of 1. out. println (s. charAt (1); // returns the length of the string System. out. println (s. length (); // all uppercase letters: System. out. println (s. toUpperCase (); // all lowercase letters: System. out. println (s. toLowerCase (); // removes the System string at the beginning or end. out. println (s. trim (); // captures the System from the beginning to the end of the subscript-1. out. println (s. substring (1, 3 ));}

    

7. Control statement

  

@ Test public void testControl () {int I = 0; for (; I <10; I ++) {System. out. println (I);} while (I> 0) {System. out. println (I --);} if (I> 0) {System. out. println ("I> 0");} else {System. out. println ("I <= 0");} switch (I) {case 0: System. out. println ("switch:" + I); break; // if no break is added, the sequence is executed. case 1: System. out. println ("switch:" + I); break; default: System. out. println (I); break ;}}
View Code

 

8. Array

@ Test public void testArray () {int a [] = {6, 7, 6, 3, 8, 9}; // foreach loop for (int j: a) {System. out. println (j);} Arrays. sort (a); // array sorting, using the fast sorting method int B [] = Arrays. copyOf (a,. length); for (int j: B) {System. out. println ("copy" + j );}}
View Code

 

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.