Some Basic stuff

xiaoxiao2021-03-06  68

Data and Object

Class Modifiers

Basic Types

Variable Modifier

BufferedReader

Package

Writing Pattern

EXCEPTIONS

Data and Object

Data of Java Objects Are Stored in Instance Variables (Also Called Fields) Instance Variables Must Have A Type, Either Be a base type or a reference

2. Class Modifiers

The abstract class modifier describes a class that has abstract methods. Abstract methods are declared with the abstract keyword and are empty (that is, they have no block defining a body of code for this method). An abstract class usually has a mixture of abstract Methods and actual methods.

The Final Class Modifier Describes a class thing..

.............. ..

IF The public class modifier is not used, The class is considered friendly. This means That it can be used and instantiated by all levels in the same package.

3. Basic Types

booleanBoolean value: true or falsechar16-bit Unicode characterbyte8-bit signed two's complement integershort16-bit signed two's complement integerint32-bit signed two's complement integerlong64-bit signed two's complement integerfloat32-bit floating-point numberdouble64-bit floating-point number

A Variable Decland to have one of these type simply stores a value of what type, rather tran a reason to some object. Therefore WHEN We create a number object, we do the full folowing:

BaseTypeClassNameCreation ExampleAccess ExamplebyteByten = new Byte ((byte) 34) n.byteValue () shortShortn = new Short ((short) 100) n.shortValue () intIntegern = new Integer (1045) n.intValue () longLongn = new Long (10849L ) n.longvalue () floatfloatn = new float (3.934f) n.floatvalue () doubledoublen = new double (3.934) n.doublevalue () 4. Variable Modifier

public: Anyone can access public instance variables protected:. Only methods of the same package or of subclasses can access protected instance variables private:.. Only methods of the same class (not methods of a subclass) can access private instance variables If none of the above modifiers are used, the instance variable is considered friendly Friendly variables can be accessed by any class in the same package static:.. A static variable is used to declare a variable that is associated with the class, not with individual instances of that . class Static variables are used to store "global" information about a class It can exist even if no instance of their class is created final:.. A final instance variable is one that must be assigned an initial value, and then can never be Assigned a new value attem tria. IT IS A Base Type, Then a constant. All Parameters in java area passed by value, tria is, any time we pass a parameter to a method, a copy of thing parameter is master for use with in the method body. So if we pass an int variable to a method, then that variable's integer value is copied. The method can change the copy but not the original. If we pass an object reference as a parameter to a method, then the Rememence is copied as well. Remember That We Can Have Many Different Variables That All Refer to the Same Object.

5. BufferedReader

java.io.BufferedReader stndin; // Standard input (buffered) stndin = new java.io.BufferedReader (new java.io.InputStreamReader (System.in)) using the "stndin.readLine ()" can be obtained input6 Package.

Usage: On the top of the file: package (package_name);

Import (package_name). *; you can import all files inside the subunit.

In the case where two packages have classes of the same name, we must specifically reference the package that contains a class Like this: Gnomes.Mushroom shroom = new Gnomes.Mushroom ( "purple"); Cooking.Mushroom topping = new Cooking.. Mushroom ();

7. Writing Pattern

Responsibility: Divide The Work Into Different Actors, Each with a Different Responsibility. Try to describe responibilities Using Action Verbs. The Program Will Form The Classes for the program.

Independence: Define The Work for Each Class To Be As Indempending from Other.

Behaviors: SO That The Consequences of Each Action Performed by A Class Will Be Well Undelf By Other Classes That Interact with it.

8. EXCEPTIONS

How to throw an exception object:

IF (InsertIndex> Size ()) {

Throw new

BoundaryviolationException ("No Element At Index" InsertErtIndex;

}

oral

Public void getreadyforclass () throws shopPingListtoosmallexception, outofmoneyException {

Goshopping ();

Makecookiesforta ();

}

EXCEPTION AND Error Are Subclasses of Throwable, Which Denotes Any Object That Can Be Thrown and Caught.

Catching Exceptions:

Try-catch block

Try

(block_of_statements_1)

Catch (exception_type) (Identifier)

(block_of_statements_2)

[Catch ((Exception_Type) (Identifier)

(block_of_statements_3)

...

[Finally "

(block_of_statements_n)]]

转载请注明原文地址:https://www.9cbs.com/read-119527.html

New Post(0)