JAVA (1)

Source: Internet
Author: User
Tags java se

Java Development The first step is to learn the relevant knowledge, to lay the foundation is the key, the following and small together I learn from the Java Foundation, together refueling!

The Java direction consists of three main blocks:

Java SE Desktop Development

Java EE Web Development

Java Me phone development

Java Development tools include:

Notepad

JCreator

JBuilder

Netbean

Eclipse (max)

Jdk:

JRE (Java Runtime Environment)

Java tool, Java compiler: Javac.exe java interpreter executor: Java.exe

Java class Library (more than 3,600 classes) commonly used 150

JDK API 1.6.0 (Help documentation)

Note: Public: Indicates that the class is common and there can be only one publicly class in a Java file

Class: Indicates that this is a category

Hello: Class name (the class name of the public class must be the same as the file name)

To compile a Java file:

Compiling Xx.java javac Xx.java

Execute Xx.java program Java XX

Java Virtual Machine (JVM): Bytecode files (. Class) are executed in the Java virtual machine

< simply give the. class file to someone else without having to hand over the. java File >

  

Java Basic data type:

Integer type (byte one byte 8bit-128~127,short two bytes, int four bytes, long eight bytes)

Decimal (floating-point) type (float, double)

Boolean type (True, false)

Character type (char is two bytes, can hold Chinese characters, one char can only receive one character)

< conclusion: In Java, the arithmetic of char is treated directly as an integer corresponding to the ASCII code >

accuracy : byte<short<int<long<float<double

ImportJava.io.*; Public classdemo1{ Public Static voidMain (String []args) {Try{     //input stream, number received from keyboardInputStreamReader (system.in); BufferedReader BR=NewBufferedReader (ISR); //give a hintSystem.out.println ("Please enter the first number"); //reading a row of data from the consoleString A1=Br.readline (); System.out.println ("Please enter a second number"); String A2=Br.readline (); //put String->float            floatnum1=Float.parsefloat (A1); floatNum2=Float.parsefloat (A2); if(num1>num2) {System.out.println ("The first big One"); }      if(num1==num2) {System.out.println (Equal); }      if(num1<num2) {System.out.println ("The second big One"); }     }Catch(Exception e) {e.printstacktrace (); }   }}

Java three major Process control:

Sequential control

Branch control: Single branch, dual branch, multi-branch

(The conditional expression data type should be the same as the constant type after the case)

The available data types in switch are: Allow Byte,short,int,char,enum (enumeration), etc.

Loop control: For Loop, while loop, do While loop

Half Pyramid:

 Public classdemo3{ Public Static voidMain (String []args) {intLay=4;  for(inti=1;i<=lay;i++)      {        //Print *         for(intj=1;j<=i;j++) {System.out.print ("*"); }         //Play a line breakSystem.out.println (); }    }} 

Pyramid:

 Public classdemo3{ Public Static voidMain (String []args) {intLay=4;  for(inti=1;i<=lay;i++)     {       //Find out the law of space//1->3 2->2 3->1 4->0        for(intk=1;k<=i;k++) {System.out.print (" "); }       //Print *//1->1 2->2 3->5 4->7        for(intj=1;j<= (i-1) *2+1;j++) {System.out.print ("*"); }        //Play a line breakSystem.out.println (); }       }  }

Java object-oriented programming-classes and objects

Class name first Letter capital

The class is abstract and the object is concrete. A class is a template for an object that is an individual, instance of a class

Definition of the class:

Package name;

Class name extends parent class implements

Interface Name {

member variables;

Construction method;

Member methods;

}

Class-Class

Member method of the class-declaration

public int test (int a);/* Method declaration */

(Access modifier + data type + function name + (parameter list);)

Member methods (functions) of a class-special instructions

1. The parameter list of a method can be multiple

Class construction method: is a special method of the class, the main function is to complete the initialization of the new object

Characteristics:

1. Method name and class name are the same

2. No return value

3. When you create a new object of a class, the system automatically calls the constructor of the class to complete the initialization of the new object

A summary of the constructor methods of the class:

The constructor method name is the same as the class name

Construction method does not return a value

The main function is to complete the initialization of the new object

When you create a new object, the system automatically calls the class's construction method

A class can have more than one construction method

Each class has a default construction method

The importance of this:

 Public classdemo3_1{ Public Static voidMain (String []args) {person P=NewPerson (dog,23, "Wang");    P.showinfo (); }}//Define a humanclassperson{intAge ;     String name;  PublicPerson (intage,string name) {     //Poor readability        This. age=Age ;  This. name=name; }     //Show person Name      Public voidShowinfo () {System.out.println ("Name is:" +name); }   }

class variables

Static variables:

 Public classdemo3_2{StaticInti=1; Static{System.out.println (A); //the static zone block executes only onceI++; }    PublicDemo3_2 () {System.out.println ("B"); I++; }      Public Static voidMain (String []args) {demo3_2 T1=NewDemo3_2 ();           System.out.println (T1.I); Demo3_2 T2=NewDemo3_2 ();     System.out.println (T2.I); }} class method://Studentclassstu{intAge ;   String name; intfee; Static intTotalfee;  PublicStu (intAge,string name,intfee) {      This. age=Age ;  This. name=name; Totalfee+=fee; }      //return total tuition fee [plus static indicates that this is a class method (static method)]//rules in Java: Class variables are in principle accessed using class methods     Public Static intGettotalfee () {returnTotalfee; }  }

Note: non-static variables (class variables) cannot be accessed in class methods

Use: Class name. class name method or object name. Class Method Name

Class variables differ from instance variables:

Add static called a class variable or static variable, otherwise called an instance variable

Class variables are class-dependent, public properties

Instance variables belong to each individual object's properties

Class variables can be accessed directly through the class name. Class variable Name

JAVA (1)

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.