1JAVA-2
if,else,for
,,equalsUser ArrayList add(Objecto) HashMap put(Objectkey, Objectvalue) object
if, switch,for,whiledobreakcontinue
java .Java:1)2) 3)1. 2.:
4.,booleanfalse all reference types---null.
.1 +-*/%x%yxy++ -- (++ --)----class Test {public static void main(String[] args) { int i=0; System.out.println(i); System.out.println(i++); System.out.println(++i); System.out.println(i);}}
2
,>>>,&,|,^,~ >, 00,11>>>
.
3 >,>=,
1ifelse 2if ,else if ,else 3switchswitch(byte,short,int,char){ case 1: 1break case 2: 2break default: nbreak } long
.
Exercisepublic class IfElse{public static void main(String args[]){if(odd(5))System.out.println(odd);elseSystem.out.println(Even);}public static int odd(int x){return x%2;}}What is the result?A. The output is odd; B. The output is even;C.An error on line 3 causes compilation to fail D.An error on line 8 causes compilation to fail
1.for()// { }2.while() {}3.do{ }while();
. Point p[] char c[]
c=new char[5]( 5)
,. :
int a[]={12345} String s[]={abcdef} =>String s[]={new String(abc), new String(def)};
.(inheritance)1.A is a BB has a Aextendsis a class A extends B A(is a B
(,,)
override
1)
2)
3).
.this
class Dot{ private int x,y,z; public Dot (int xint yint z){ this.x=x; this.y=y; this.z=z; }}
java.io.File.public File(String path)---pathFile pathFile
261. java: Error () Exception(,,)2. 8-13 Throwable 1.f.createNewFile();2.catchException
27 3. 8-15NullPointerException ArrayIndexOutOfBoundsExceptionIOException. File
28.try-catch-finally : try{ unsafe;() }catch( e) {//.; } finally{ ; }
29:try{unsafe(); T1;}catch(IOException e) { T2;}finally {T3;} T4;
31 trycatchmain
.
--,,1..2.:String userName;3..:public void getUserName(){}4.settergetter.
-- equalsequalsStringintboolean
3-- .String userName=defu;:.(.)//API
4--ArrayListHashMap
ArrayList
ArrayListimport java.util.*;class ArrayListTest {public static void main(String[] args) {ArrayList al=new ArrayList();al.add("FistElement");al.add("SecondElement");al.add("ThirdElement");for(int i=0;i
HashMapkeyvalueput(Object key, Object value)get(Object key) null
HashMappublic class FileTest {public static void main(String[] args) throws IOException {HashMap map = new HashMap();map.put("1","cheche");System.out.println(map.get("1"));}}
12345679131417242637382627282931