精华内容
下载资源
问答
  • 1.正则表达式的圆括号的作用是对字符进行分组,并保存匹配的文本。2.圆括号用法I:对字符或元字符进行分组,这样在圆括号内就可以对字符组合使用限定符。eg. 匹配A+一个数字+A+一个数字:(A\d){2}3.圆括号用法II:...

    1.正则表达式中的圆括号的作用是对字符进行分组,并保存匹配的文本。

    2.圆括号用法I:对字符或元字符进行分组,这样在圆括号内就可以对字符组合使用限定符。

    eg. 匹配A+一个数字+A+一个数字:(A\d){2}

    3.圆括号用法II:表示可选择性。

    3.1 从两个直接量中选择一个

    eg. gr(a|e)y匹配gray和grey,该例子还可以使用gr[ae]y,字符类效率更高。

    3.2 从多个直接量中选择

    eg. (Doctor|Dr\.?)匹配Doctor,Dr,Dr.三种情况

    3.3 错误匹配的交替行为,

    使用交替行为时,有时会出现意想不到的错误。

    eg. 用(a|ab)匹配ab时,只能匹配a,但是如果用(ab|a),则可以匹配ab

    4.捕获圆括号:正则表达式中,与位于圆括号之间的模式匹配的内容都会被捕获。

    4.1 当模式中有嵌套的圆括号时,变量的编号会按照圆开括号出现的位置一次进行。

    eg. ([A-Za-z](\d{2}))((-)\d{2})匹配”A22-33”时,匹配情况如下:

    Group 1:   A22

    Group 2:   22

    Group 3:   -33

    Group 4:   -

    4.2 .NET中,可以创建命名的组,语法为:

    (?模式)或(?’组名’模式)

    eg. (?\w(?'Num'\d{2}))((-)\d{2})匹配” A22-33”情况为:

    Group "FirstLetter": A22

    Group "Num":  22

    Group 1:   -33

    Group 2:   -

    4.3 非捕获的圆括号:.NET和JavaScript都提供了非捕获圆括号的功能,即圆括号的内容不作为捕获对象,当圆括号中的内容不是想捕获的对象时,采用非捕获圆括号可以提高匹配效率。语法为:

    (?:the-non-captured-content)

    eg. (\w(?:\d{2}))((?:-)\d{2})匹配” A22-33”情况如下:

    Group 1:   A22

    Group 2:   -33

    注:\d{2}匹配的”22”没有被捕获

    5.反向引用(backreferences)

    语法:.NET和javascript中,表示匹配第一组的变量被指定为”\1”

    能够体现反向引用的便利性的一种情况是找到句子中重复的单词。

    eg. 查找下列句子中重复的单词:

    I think that that is often overdone.

    This sentence contains contains a doubled word or two two.

    我们用([A-Za-z]+) +\1\b来匹配,红色部分为匹配的结果

    在这个匹配模式中([A-Za-z]+)为匹配的第一组变量,后面加一个或多个空格( +)表示单词间隔,

    然后用”\1”来表示第一组匹配的变量(即[A-Za-z]+匹配的内容),最后一个表示单词的结束(\b)

    展开全文
  • Java语言,变量的类型主要有3种:成员...局部变量的作用域与可见性为它所在的花括号内。类的成员变量的作用范围同类的实例化对象的作用范围相同。当类被实例化的时候,成员变量就会在内存分配空间,并初始化...

    在Java语言中,变量的类型主要有3种:成员变量、静态变量和局部变量

    01

    静态变量跟局部变量

    静态变量不依赖于特定的实例,而是被所有实例共享,也就是说,只要一个类被加载,JVM就会给类的静态变量分配存储空间。因此可以通过类名.变量名来访问静态变量。

    局部变量的作用域与可见性为它所在的花括号内。

    类的成员变量的作用范围同类的实例化对象的作用范围相同。当类被实例化的时候,成员变量就会在内存中分配空间,并初始化。

    直到类的实例化对象的生命周期结束时,成员变量的生命周期才结束。

    02

    protected和default

    protected:表名成员变量或方法对该类自身,与它在同一个包中的其他类,在其他包中的该类的子类都可见。

    defaul:表明该成员变量或方法只有自己和与其位于同一包内的类可见。

    若父类与子类处于同一包内,则子类对父类的default成员变量或方法都有访问权限;若父类与子类处于不同的package内,则没有访问权限。

    还有需要注意的是,这些修饰符只能修饰成员变量,不能修饰局部变量。

    private和protected不能用来修饰类。

    展开全文
  • 1、没有区分英文在JAVA语言(实际上其他语言诸如C也一样),起特殊作用的分号“;”、括号(包括圆括号“()”、中括号“[]”、大括号“{}”),以及双引号 “""”、单引号等,都必须是英文。若不小心输入为中文,...

    学习程序设计,最怕的事情可能就是遇到错误却找不到错在哪里。这里列举一下笔者发现的JAVA新人常犯的错误,供目前正在上笔者JAVA课程的学生参考,其他JAVA初学者亦可借鉴。

    1、没有区分中英文

    在JAVA语言中(实际上其他语言诸如C也一样),起特殊作用的分号“;”、括号(包括圆括号“()”、中括号“[]”、大括号“{}”),以及双引号 “""”、单引号等,都必须是英文的。若不小心输入为中文的,就会报语法错误。此类错误对于初学者来说非常隐蔽,常会耗费大量的时间和耐心。以分号为例, 可采用如下方法检测是不是误写为中文的了:按快捷键Ctrl+F,可打开搜索对话框,输入中文的分号,让它搜索,看搜索到的分号是不是应该写为英文的。为 保证能对整个程序文件进行搜索,可在搜索前预先把光标移动到程序的开始处。因为搜索默认情况下是从当前光标处搜索到文件尾,光标之前的内容不会搜索到。或 者使用某些搜索选项,让它搜索完整个文件。分别以EditPlus和Windows的记事本编辑器示例如下:

    Editplus,确认选中红框中的选项。

    133219268.png

    记事本:如下图,默认向下搜索。向下搜索完后,再点击“向上”,让它向上搜索。

    133256429.png

    2、括号、引号等不配对

    在程序中,圆括号(())、方括号([])、大括号({})以及双引号("")和单引号必须成对出现,否则报错。如以下的的错误“进行语法解析时已到达文 件结尾”,即是因为少了一个右大括号。为避免发生此类错误,可先把左右括号/引号写好,然后再往里面添加代码。

    3、缺少大括号

    对于if/else和循环,若只需执行一条语句,可以不用大括号。但是当需要添加语句时,就需要用大括号把多条语句包含起来。这一点容易被忽略,而一旦被 忽略,就是逻辑错误(程序能运行,但结果不对)。排查逻辑错误要比语法错误困难很多,因为编译器不会报错,所以常常会耗费大量时间和耐心。因此,为避免这 类错误,应养成习惯:即使只执行一条语句,也应用大括号包含。

    4、类名/变量名写错或没有区分大小写

    类名应保证正确,变量定义后,再使用此变量也应该保证与定义时的名字一致。 更容易出错的是,JAVA是区分大小写的语言,有人把String写成string,或者同一个变量名,前后使用时大小写不一致,都会报错。因此,当编译 器报“找不到符号”的错误时,就应该根据编译器的错误提示信息仔细检查相关类名/变量名是不是这两方面犯了错。例如,下图的错误分别是把类String写 成了string,以及定义了变量scan,但使用此变量时却写成了sscan。

    133409492.png

    5、公共类名应与文件名同名

    我们一般写的类都是公共的(public),JAVA要求保存公共类的文件的文件名必须与类同名,而且要注意大小写。否则会报错:类XX是公共的,应在名为XX.java的文件中声明。这里的“XX”指代某个类名,以下亦然。

    6、修改后未保存或未重新编译

    发现错误更改后未保存,这时修改并未生效,因此应该首先保存。保存后还应重新编译生成新的字节码文件(.class)文件,因为真正运行的是字节码文件。不重新编译的话,运行的还是旧的字节码文件。

    7、错误:仅当显式请求注释处理时才接受类名称“XX.JAVA”

    这个错误是前一段时间批改学生程序时遇到的,程序本身没有发现任何问题,只是文件名写成了XX.JAVA,一时我也不知道错在哪里。后来把文件后缀 名.JAVA改为.java,就好了。由于笔者写程序时一直把后缀名写为.java,因此一直未遇到这种问题(或者遇到了,但是忘记了)。看到大写的后缀 名后,潜意识里认为后缀名属于Windows的概念,而Windows是不区分大小写的,因此也未在意。但我当时显然忽略了一点,当我们用javac命令 编译程序时,javac是JAVA的东西,它对于将要编译的文件的文件名,是区分大小写的。因此,文件名XX.JAVA与XX.java对它来说,是不一 样的。正如上面的第三条所讲,公共类名应与文件名同名,而且要注意大小写。而如果我们把javac写成JAVAC,则没有问题。因为javac命令是 Windows帮我们调用的,它不区分大小写。

    8、设置classpath环境变量时忘了添加当前目录

    在不使用IDE的情况下,若要引用第三方jar包,需把这些jar包引入到classpath环境变量中。但若设置classpath时,没有包含当前目 录(.),那么即使是在字节码文件所在的目录使用java命令运行此字节码文件,也会报java.lang.NoClassDefFoundError。 这是因为若不设置classpath,则classpath自动包含当前目录;而若设置后,则不再自动包含当前目录,需要我们显式指定包含,这一点与 path环境变量不同。

    展开全文
  • 四、shell 的条件判断命令...在许多系统上,test 命令与 [ 命令的作用其实是一样的,使用 [ 命令的时候,一般在结尾加上 ] 符号,使代码更具可读性。另外,需要注意一点的是,在使用 [ 命令时,[ 符号与被检查的语...

    四、shell 中的条件判断命令 test 和 [

    test 命令可以处理 shell 脚本中的各类工作。它产生的不是一般的输出,而是可使用的退出状态。test 命令通过接受各种不同的参数,来控制要执行哪种测试。在许多系统上,test 命令与 [ 命令的作用其实是一样的,使用 [ 命令的时候,一般在结尾加上 ] 符号,使代码更具可读性。另外,需要注意一点的是,在使用 [ 命令时,[ 符号与被检查的语句之间应该留有空格。shell 中通常使用 test 命令来产生控制结构所需要的条件,根据 test 命令的退出码决定是否需要执行后面的代码。

    4140cb648fe57cd243aba62d04c99884.png

    bash-3.2# man test

    正在重新格式化页面。请等待... 完成

    User Commands test(1)

    NAME

    test - evaluate condition(s)

    SYNOPSIS

    /usr/bin/test [condition]

    [ [condition] ]

    sh

    test [condition]

    [ [condition] ]

    csh

    test [condition]

    [ [condition] ]

    ksh

    test [condition]

    [ [condition] ]

    DESCRIPTION

    The test utility evaluates the condition and indicates the

    result of the evaluation by its exit status. An exit status

    of zero indicates that the condition evaluated as true and

    an exit status of 1 indicates that the condition evaluated

    as false.

    In the first form of the utility shown using the SYNOPSIS:

    test [ condition ]

    the square brackets denote that condition is an optional

    operand and are not to be entered on the command line.

    In the second form of the utility shown using the SYNOPSIS:

    SunOS 5.10 Last change: 23 Aug 2002 1

    User Commands test(1)

    [ [ condition ] ]

    the first open square bracket, [, is the required utility

    name. condition is optional, as denoted by the inner pair of

    square brackets. The final close square bracket, ], is a

    required operand.

    See largefile(5) for the description of the behavior of test

    when encountering files greater than or equal to 2 Gbyte

    (2^31 bytes).

    The test and [ utilities evaluate the condition condition

    and, if its value is true, set exit status to 0. Otherwise,

    a non-zero (false) exit status is set. test and [ also set a

    non-zero exit status if there are no arguments. When permis-

    sions are tested, the effective user ID of the process is

    used.

    All operators, flags, and brackets (brackets used as shown

    in the last SYNOPSIS line) must be separate arguments to

    these commands. Normally these arguments are separated by

    spaces.

    OPERANDS

    The primaries listed below with two elements of the form:

    -primary_operator primary_operand

    are known as unary primaries. The primaries with three ele-

    ments in either of the two forms:

    primary_operand -primary_operator primary_operand

    primary_operand primary_operator primary_operand

    are known as binary primaries.

    If any file operands except for -h and -L primaries refer to

    symbolic links, the symbolic link is expanded and the test

    is performed on the resulting file.

    SunOS 5.10 Last change: 23 Aug 2002 2

    User Commands test(1)

    If you test a file you own (the -r -w or -x tests), but the

    permission tested does not have the owner bit set, a non-

    zero (false) exit status will be returned even though the

    file may have the group or other bit set for that permis-

    sion.

    The = and != primaries have a higher precedence than the

    unary primaries. The = and != primaries always expect argu-

    ments; therefore, = and != cannot be used as an argument to

    the unary primaries.

    The following primaries can be used to construct condition:

    -a file True if file exists. (Not avail-

    able in sh.)

    -b file True if file exists and is a

    block special file.

    -c file True if file exists and is a

    character special file.

    -d file True if file exists and is a

    directory.

    -e file True if file exists. (Not avail-

    able in sh.)

    -f file True if file exists and is a

    regular file. Alternatively, if

    /usr/bin/sh users specify

    /usr/ucb before /usr/bin in

    their PATH environment variable,

    then test will return true if

    file exists and is

    (not-a-directory). The csh test

    and [ built-ins always use this

    alternative behavior.

    -g file True if file exists and its set

    group ID flag is set.

    SunOS 5.10 Last change: 23 Aug 2002 3

    User Commands test(1)

    -G file True if file exists and its

    group matches the effective

    group ID of this process. (Not

    available in sh.)

    -h file True if file exists and is a

    symbolic link.

    -k file True if file exists and has its

    sticky bit set.

    -L file True if file exists and is a

    symbolic link.

    -n string True if the length of string is

    non-zero.

    -o option True if option named option is

    on. (Not available in csh or

    sh.)

    -O file True if file exists and is owned

    by the effective user ID of this

    process. (Not available in sh.)

    -p file True if file is a named pipe

    (FIFO).

    -r file True if file exists and is read-

    able.

    -s file True if file exists and has a

    size greater than zero.

    -S file True if file exists and is a

    socket. (Not available in sh.)

    -t [file_descriptor] True if the file whose file

    descriptor number is

    file_descriptor is open and is

    associated with a terminal. If

    SunOS 5.10 Last change: 23 Aug 2002 4

    User Commands test(1)

    file_descriptor is not speci-

    fied, 1 is used as a default

    value.

    -u file True if file exists and its

    set-user-ID flag is set.

    -w file True if file exists and is writ-

    able. True will indicate only

    that the write flag is on. The

    file will not be writable on a

    read-only file system even if

    this test indicates true.

    -x file True if file exists and is exe-

    cutable. True will indicate only

    that the execute flag is on. If

    file is a directory, true indi-

    cates that file can be searched.

    -z string True if the length of string

    string is zero.

    file1 -nt file2 True if file1 exists and is

    newer than file2. (Not available

    in sh.)

    file1 -ot file2 True if file1 exists and is

    older than file2. (Not available

    in sh.)

    file1 -ef file2 True if file1 and file2 exist

    and refer to the same file. (Not

    available in sh.)

    string True if the string string is not

    the null string.

    string1 = string2 True if the strings string1 and

    string2 are identical.

    SunOS 5.10 Last change: 23 Aug 2002 5

    User Commands test(1)

    string1 != string2 True if the strings string1 and

    string2 are not identical.

    n1 -eq n2 True if the integers n1 and n2

    are algebraically equal.

    n1 -ne n2 True if the integers n1 and n2

    are not algebraically equal.

    n1 -gt n2 True if the integer n1 is alge-

    braically greater than the

    integer n2.

    n1 -ge n2 True if the integer n1 is alge-

    braically greater than or equal

    to the integer n2.

    n1 -lt n2 True if the integer n1 is alge-

    braically less than the integer

    n2.

    n1 -le n2 True if the integer n1 is alge-

    braically less than or equal to

    the integer n2.

    condition1 -a condition2 True if both condition1 and con-

    dition2 are true. The -a binary

    primary is left associative and

    has higher precedence than the

    -o binary primary.

    condition1 -o condition2 True if either condition1 or

    condition2 is true. The -o

    binary primary is left associa-

    tive.

    These primaries can be combined with the following opera-

    tors:

    ! condition True if condition is false.

    SunOS 5.10 Last change: 23 Aug 2002 6

    User Commands test(1)

    ( condition ) True if condition is true. The parentheses

    ( ) can be used to alter the normal pre-

    cedence and associativity. Notice also that

    parentheses are meaningful to the shell

    and, therefore, must be quoted.

    The algorithm for determining the precedence of the opera-

    tors and the return value that will be generated is based on

    the number of arguments presented to test. (However, when

    using the [...] form, the right-bracket final argument will

    not be counted in this algorithm.)

    In the following list, $1, $2, $3 and $4 represent the argu-

    ments presented to test as a condition, condition1, or con-

    dition2.

    0 arguments: Exit false (1).

    1 argument: Exit true (0) if $1 is not null. Otherwise,

    exit false.

    2 arguments:

    o If $1 is !, exit true if $2 is

    null, false if $2 is not null.

    o If $1 is a unary primary, exit true

    if the unary test is true, false if

    the unary test is false.

    o Otherwise, produce unspecified

    results.

    3 arguments:

    o If $2 is a binary primary, perform

    the binary test of $1 and $3.

    o If $1 is !, negate the two-argument

    test of $2 and $3.

    o Otherwise, produce unspecified

    results.

    4 arguments:

    o If $1 is !, negate the three-

    argument test of $2, $3, and $4.

    SunOS 5.10 Last change: 23 Aug 2002 7

    User Commands test(1)

    o Otherwise, the results are unspeci-

    fied.

    USAGE

    Scripts should be careful when dealing with user-supplied

    input that could be confused with primaries and operators.

    Unless the application writer knows all the cases that pro-

    duce input to the script, invocations like test "$1" -a "$2"

    should be written as test "$1" && test "$2" to avoid prob-

    lems if a user supplied values such as $1 set to ! and $2

    set to the null string. That is, in cases where maximal por-

    tability is of concern, replace test expr1 -a expr2 with

    test expr1 && test expr2, and replace test expr1 -o expr2

    with test expr1 || test expr2. But notice that, in test, -a

    has higher precedence than -o, while && and || have equal

    precedence in the shell.

    Parentheses or braces can be used in the shell command

    language to effect grouping.

    Parentheses must be escaped when using sh. For example:

    test \( expr1 -a expr2 \) -o expr3

    This command is not always portable outside XSI-conformant

    systems. The following form can be used instead:

    ( test expr1 && test expr2 ) || test expr3

    The two commands:

    test "$1"

    test ! "$1"

    could not be used reliably on some historical systems. Unex-

    pected results would occur if such a string condition were

    used and $1 expanded to !, (, or a known unary primary.

    Better constructs are, respectively,

    test -n "$1"

    test -z "$1"

    SunOS 5.10 Last change: 23 Aug 2002 8

    User Commands test(1)

    Historical systems have also been unreliable given the com-

    mon construct:

    test "$response" = "expected string"

    One of the following is a more reliable form:

    test "X$response" = "Xexpected string"

    test "expected string" = "$response"

    Notice that the second form assumes that expected string

    could not be confused with any unary primary. If expected

    string starts with -, (, ! or even =, the first form should

    be used instead. Using the preceding rules without the

    marked extensions, any of the three comparison forms is

    reliable, given any input. (However, observe that the

    strings are quoted in all cases.)

    Because the string comparison binary primaries, = and !=,

    have a higher precedence than any unary primary in the >4

    argument case, unexpected results can occur if arguments are

    not properly prepared. For example, in

    test -d $1 -o -d $2

    If $1 evaluates to a possible directory name of =, the first

    three arguments are considered a string comparison, which

    causes a syntax error when the second -d is encountered. is

    encountered. One of the following forms prevents this; the

    second is preferred:

    test \( -d "$1" \) -o \( -d "$2" \)

    test -d "$1" || test -d "$2"

    Also in the >4 argument case:

    test "$1" = "bat" -a "$2" = "ball"

    Syntax errors will occur if $1 evaluates to ( or !. One of

    the following forms prevents this; the third is preferred:

    SunOS 5.10 Last change: 23 Aug 2002 9

    User Commands test(1)

    test "X$1" = "Xbat" -a "X$2" = "Xball"

    test "$1" = "bat" && test "$2" = "ball"

    test "X$1" = "Xbat" && test "X$2" = "Xball"

    EXAMPLES

    In the if command examples, three conditions are tested, and

    if all three evaluate as true or successful, then their

    validities are written to the screen. The three tests are:

    o if a variable set to 1 is greater than 0,

    o if a variable set to 2 is equal to 2, and

    o if the word root is included in the text file

    /etc/passwd.

    /usr/bin/test

    Example 1 Using /usr/bin/test

    Perform a mkdir if a directory does not exist:

    test ! -d tempdir && mkdir tempdir

    Wait for a file to become non-readable:

    while test -r thefile

    do

    sleep 30

    done

    echo'"thefile" is no longer readable'

    Perform a command if the argument is one of three strings

    (two variations), using the open bracket version [ of the

    test command:

    if [ "$1" = "pear" ] || [ "$1" = "grape" ] || [ "$1" = "apple" ]

    then

    command

    fi

    case "$1" in

    pear|grape|apple) command;;

    esac

    SunOS 5.10 Last change: 23 Aug 2002 10

    User Commands test(1)

    The test built-in

    The two forms of the test built-in follow the Bourne shell's

    if example.

    Example 2 Using the sh built-in

    ZERO=0 ONE=1 TWO=2 ROOT=root

    if [ $ONE -gt $ZERO ]

    [ $TWO -eq 2 ]

    grep $ROOT /etc/passwd >&1 > /dev/null # discard output

    then

    echo "$ONE is greater than 0, $TWO equals 2, and $ROOT is" \

    "a user-name in the password file"

    else

    echo "At least one of the three test conditions is false"

    fi

    Example 3 Using the test built-in

    Examples of the test built-in:

    test `grep $ROOT /etc/passwd >&1 /dev/null` # discard output

    echo $? # test for success

    [ `grep nosuchname /etc/passwd >&1 /dev/null` ]

    echo $? # test for failure

    csh

    Example 4 Using the csh built-in

    @ ZERO = 0; @ ONE = 1; @ TWO = 2; set ROOT = root

    grep $ROOT /etc/passwd >&1 /dev/null # discard output

    # $status must be tested for immediately following grep

    if ( "$status" == "0" && $ONE > $ZERO && $TWO == 2 ) then

    echo "$ONE is greater than 0, $TWO equals 2, and $ROOT is" \

    "a user-name in the password file"

    endif

    SunOS 5.10 Last change: 23 Aug 2002 11

    User Commands test(1)

    ksh

    Example 5 Using the ksh built-in

    ZERO=0 ONE=1 TWO=$((ONE+ONE)) ROOT=root

    if ((ONE > ZERO)) # arithmetical comparison

    [[ $TWO = 2 ]] # string comparison

    [ `grep $ROOT /etc/passwd >&1 /dev/null` ] # discard output

    then

    echo "$ONE is greater than 0, $TWO equals 2, and $ROOT is" \

    "a user-name in the password file"

    else

    echo "At least one of the three test conditions is false"

    fi

    Using -e option in sh

    Example 6 Using /usr/bin/test for the -e option

    If one really wants to use the -e option in sh, use

    /usr/bin/test, as in the following:

    if [ ! -h $PKG_INSTALL_ROOT$rLink ] && /usr/bin/test -e

    $PKG_INSTALL_ROOT/usr/bin/$rFile ; then

    ln -s $rFile $PKG_INSTALL_ROOT$rLink

    fi

    ENVIRONMENT VARIABLES

    See environ(5) for descriptions of the following environment

    variables that affect the execution of test: LANG, LC_ALL,

    LC_CTYPE, LC_MESSAGES, and NLSPATH.

    EXIT STATUS

    The following exit values are returned:

    0 condition evaluated to true.

    1 condition evaluated to false or condition was missing.

    >1 An error occurred.

    ATTRIBUTES

    See attributes(5) for descriptions of the following attri-

    butes:

    SunOS 5.10 Last change: 23 Aug 2002 12

    User Commands test(1)

    ____________________________________________________________

    | ATTRIBUTE TYPE | ATTRIBUTE VALUE |

    |_____________________________|_____________________________|

    | Availability | SUNWcsu |

    |_____________________________|_____________________________|

    | Interface Stability | Standard |

    |_____________________________|_____________________________|

    SEE ALSO

    csh(1), ksh(1), sh(1), test(1B), attributes(5), environ(5),

    largefile(5), standards(5)

    NOTES

    The not-a-directory alternative to the -f option is a tran-

    sition aid for BSD applications and may not be supported in

    future releases.

    SunOS 5.10 Last change: 23 Aug 2002 13

    展开全文
  • 1,在java中变量的作用域在花括号之内,用花括号表示,作用域用花括号的位置决定 2,对象的作用域 java对象不具备和基本类型一样的声明周期,但用new创建一个java对象时,它可以存活于作用域之外,所以假如你采用...
  • 4种Java代码块的作用讲解时间:2017-06-28来源:华清远见JAVA学院今天华清Java学院编要和大家分享的是Java代码块的作用,代码块是一种常见的代码形式,他用大括号“{}”将多行代码封装在一起,形成一个独立的代码...
  • Java中,synchronized关键字是用来控制线程同步,就是在多线程... 修饰一个代码块,被修饰代码块称为同步语句块,其作用的范围是大括号{}括起来代码,作用的对象是调用这个代码块对象; 2. 修饰一个方法,...
  • Java中,synchronized关键字是用来控制线程同步,就是在多线程... 修饰一个代码块,被修饰代码块称为同步语句块,其作用的范围是大括号{}括起来代码,作用的对象是调用这个代码块对象; 2. 修饰一个方法,...
  • flex中的括号

    千次阅读 2010-08-21 11:59:00
    <br />初学flex时,被里面四处乱飞括号弄得有点头晕,尤其是一些不同... 仔细翻了翻文档,总结一下,顺便测试下Easy Google Syntax Highlighter插件:小括号( ):nothing new,就两个作用:改变表达式运算
  • 你说的“cfor循环变量不能再表达式声明”并不完全正确。在新的 C99 及之后的标准,for 语句小括号的第一个部分可以是表达式...而且需要注意的是:循环体本身也有自己的作用域,和 for 语句小括号的作用域不...
  • 在Python语言中最常见括号有三种,分别是:小括号()、中括号[]、花括号{};其作用也不相同,分别用来代表不同Python基本内置数据类型。...这个类似java中的数组,定义后内容不可变 Python中中括号[]:list
  • 局部变量只在自己所属括号内有效,大括号结束,局部变量失去作用域。3:成员变量存在于堆内存,随着对象产生而存在,消失而消失。局部变量存在于栈内存,随着所属区域运行而存在,结束而释放。---------...
  • java中的变量总结

    2014-11-25 10:55:00
    局部变量只在自己所属括号内有效,大括号结束,局部变量失去作用域。 3:成员变量存在于堆内存,随着对象产生而存在,消失而消失。 局部变量存在于栈内存,随着所属区域运行而存在,结束而释放。 ---...
  • Java中,synchronized关键字是用来控制线程同步,就是在多线程... 修饰一个代码块,被修饰代码块称为同步语句块,其作用的范围是大括号{}括起来代码,作用的对象是调用这个代码块对象; 2. 修饰一个方法,...
  • Java中的知识点(二)

    2020-05-04 22:39:31
    Java小知识点(二) 一、字符串连接运算符 我们都知道,当+号两边都为整数型数据时它是作加法使用,当两边为字符串时它是做连接作用,请看以下例子 在这里它的位置不同,所起的作用也不同,在双引号之前的加号作...
  • 这个bug是在学习内部类的时候,在静态内部类调用静态资源,出现报错的异常,属于非常基础错误,原因是没有注意小括号的作用范围引起的错误, "犯罪现场截图"如下: 报错提示: Syntax error on token “play2”, ...
  • java编程中的构造方法

    2018-05-20 18:21:25
    构造方法结构:【权限访问修饰符】 类名(参数列表){ 函数体;}构造方法的特点:@1.在对象被创建时自动执行@2....跟在关键字super或this后加上一个小括号(),小括号内根据实际添加实参构造方法的作用:用于实例...
  • Java8Lambda用法

    2017-02-08 18:14:36
    如果只有个参数,可以去除小括号;如果多个参数,不可以去除小括号;如果没有参数,小括号不可去除 C:表示业务主体。如果只有一个语句,大括号可以去除。如果有多个语句,大括号不可以去除 2、参数作用域 只用...
  • java基础一点细节

    2017-10-26 19:50:03
     2、成员变量的有效期在这个类,局部变量有效期只在属于自己的一对大括号的作用域内  3、成员变量存在于堆内存,随着对象产生而存在,消失而消失。  局部变量存在于栈内存,随着所属区域的运行而存在,结束...
  • + 运算符在java语言当中有2个作用: 加法运算,求和 字符串的连接运算 当“+”运算符两边的数据都是数字的话,一定是进行加法运算 当“+”运算符两边的...一个表达式当中可以出现多个"+",在没有添加小括号的前...
  • 本文教程操作环境:windows7系统、JAVA SE,DELL G3电脑。根据条件往下执行的程序,不能满足判断的需求,所以又产生了分支控制。其中重要的一个就是if语句,if本身就是判断的作用,根据使用分为四种...}若满足小括号...
  • java学习总结

    2016-12-04 10:24:31
    写代码: 1,明确需求。要做什么 2,分析思路。要怎么做 3,确定步骤。每一步要用到哪些知识点 ...变量的作用域和生存期: ... 变量到达它所在的作用域的时候就在内存消失了 成员变量和局部变
  • java小

    2010-01-17 16:23:00
    1 作用域 java中作用范围由花括号标示。2关于static 垃圾收集器只知道搜集那些有new运算符分配内存,不知道如何释放特殊内存。 如果垃圾收集器准备回收对象内存,它首先调用finalize(),而且只有在下一次...
  • java语法学习

    2020-07-10 21:17:51
    变量到达它所在的作用域的时候就在内存消失了; 数据类型: 1):基本数据类型:byte、short、int、long、float、double、char、boolean 简单类型boolean byte char short intlongfloat double void
  • json简介及在Java中的应用

    千次阅读 2016-04-14 16:55:10
    作用和xml有点类似,但是 比 XML 更、更快,更易解析。JSON 解析器和 JSON 库支持许多不同编程语言。JSON 语法规则 JSON 对象在花括号中书写,对象可以包含多个名称/值对:如 var jsonObj = { "firstName":...
  • Java中方法重载与构造器重载 在学习方法重载和构造器重载之前我们需要先来了解一下参数。 参数 参数的作用:将数据动态传入方法体或者构造器中。 定义:定义在方法名或者构造器后的小括号里, 参数和局部变量一样,...
  • 一、变量 变量的概念: 变量指的是程序运行时可变的量,在内存开辟内存用来保存数据 变量的命名规则: ...变量的作用域: 也就是该变量能生效的范围, 一般是变量定义所在的代码块 (大括号) cla
  • Java day4

    2019-12-27 23:49:28
    Java day4 结 选择结构语句 一.if语句 [if嵌套] 分类:1>...1)针对格式1这种情况,语句中的括号可以省略,但是不建议,{}表示一个作用域 2)if后面不能有分号,有分号地方不能有{} 3)if语句后面如...
  • http://www.cnblogs.com/wupeiqi/p/5649402.html 五句话搞定JavaScript作用域从JavaScript == pyhon 作用域几乎一致 __ 详解:一、“JavaScript无块级作用域”在Java或C#存在块级作用域,即:大括号也是一个作用...
  • Java数据类型

    2020-12-28 16:02:03
    1.变量的作用域:变量能生效的范围,一般是变量定义所在的代码块(大括号) 2.变量的命名规则 a.一个变量名只能包含字母,数字,下划线 b.数字不能开头 c.英文大写敏感,Num和num是两个不同的变量 注:a.不推荐...

空空如也

空空如也

1 2 3 4 5 ... 9
收藏数 167
精华内容 66
关键字:

java中小括号的作用

java 订阅