CSDN博客

img kiOm

Java新手入门——整理的SCJP听课笔记

发表于2004/10/24 16:36:00  906人阅读

2004-7-30 12:07:00
  前言:  JAVA的魅力

  一、                                                                          
  1、强大的移植能力:虚拟机的存在,不同的平台存在不同的虚拟机。                
  2、面向对象;                                                                
  3、良好的安全性:虚拟机的安全设置,应用服务器的安全性。                      
  4、联网能力。                                                                

  二、                                                                          
  中间件技术:EJB                                                            
  很好解决了和数据库连接的问题。                                                

  三、                                                                          
  设计模式                                                                      
  MVC                                                                        

  M        V          C                                   
  Model      View        Control                  
  JavaBean     Jsp        Servlet               
  Taglib      Applet       控制页面流转                
  EJB                                                                        
  业务逻辑                                                                      

  IE -------------->Webserver-------------->Appliation Server-------->DB

           Jsp  Applet      EJB                    
       JavaBean        WebSerice                 
       Servlet                                                     

  EJB不能在internet上面部署,RI协议不能通过防火墙。                
  无状态的会话Bean可以发布为Webserice.                            

  四、配置Java的环境:                                                      
  安装了jdk1.4之后,在环境变量里面增加classpath 修改path。  
  1、classpath                                                       
  .;c:/j2sdk1.4/lib/tools.jar                        
  “.”表示虚拟机寻找类的路径是从当前路径开始。                                
  2.path                                                                  
  c:/j2sdk1.4/bin                                                

  editplus 增加编译和运行java的工具。                              
  编译java的工具设置                                                        
  命令 c:/j2sdk1.4/bin/javac.exe                      
  参数 $(FileName)                                                  
  初始目录$(FileDir)                                                  
  运行java的工具设置                                                        
  命令 c:/j2sdk1.4/bin/javac.exe                      
  参数 $(FileName) Without Extension              
  初始目录$(FileDir)                                                  

  第一章

  一、JVM                                                                    
  1、Java 存盘文件名必须是以公共类名(包含主方法的类名)                  
  2、Java 程序以.java结尾的后缀名。                                  
  java区分大小写,一般的代码习俗。                                          
  类名的首字符大写,方法、变量的首字符小写,常量全部大写。                      

  二、垃圾回收机制 garbage collection                        
  内存区中的变量没有被任何程序引用时,自动丢弃。                                

  补充实例??                                                                  

  三、源文件布局                                                                

  package abc.def  (
“.”表示子目录路径,以当前
目录为起点的相对路径)
  public class A { }                                          
  class B { }                                                        
  class C { }                                                        

  包:组织目录的一种形式                                                        

  |                                                                            
  |----# abc                                                          
     |                                                                      
     |# def                                                            
     |                                                                      
     |----A.class                                                
     |----B.class                                                
     |----C.class                                                

  package/make 机制                                                
  javac -d . 文件名                                                 
  说明只需要对主调用程序进行编译即可,类文件的输出路径,在当前目录下生成包路径。

  类文件放在包路径里面,运行程序时在包的上一级目录下面进行。                    

  打包方法:jar cvf ab
c.jar abc (说明:abc.jar是目
标文件 ,abc源文件)
  打包也是在包的上一级目录中来打包。                                            

  打包之后可以将.jar放到classpath环境变量中来测试。                

  v第二章 标识符 关键字 类型

  1、数字不能做标识符的首字符。                                                

  2、Java中的注释:                                                        
  int x; // a comment
         一行中"//"
后的部分为注释内容
  /*                                                                          
  The variable x is an integer:                    
  */int x;            
编译器对此注释内容不做处理 
  “/*” 和 “*/”之间的所有内容为注释内容,

  /**                                                                        
  x -- an integer representing the
x coordinate
  */                                                                          
  int x;      “/
做处理,此种注释为文档工
**”和“*/”之间的所有内容为
具 javadoc 生成文档时所用 
注释内容,编译器对此注释内容不


  3、关键字                                                                    
  共有52个,其中goto ,const没有实际作用。                          

  4、type 类型                                                            
  基本类型8种:boolean, char,byte,
short,long,int,float,double
  与C/C++语言中不同的
们声明一个变量时,
是,在Java语言中,所有的基本

数据类型都有预设值,就是说当我

  即使我们没有对它赋值
个类型的预设值见下表:
,它的值也是一定的,而不像在

C/C++中那样是不可预测的。具体


  基本数据类型 预设值                                                         
  Boolean false                                                   
  Char '/u000'                                                     
  Byte (byte)0                                                     
  Short (short)0                                                 
  Int 0                                                                   
  Long 0L                                                               
  Float 0.0L                                                         
  Double 0.0d                                                       

  在Java语言中,整型常量有三种形式,它们分别是:十进制、八进制、十六进制。  
  需要注意的是十进制数
以0x或0X开头。
不能以0开头,这是因为八进制

的数是以0开头的,而十六进制数


  浮点数默认的是double  整型默认的是int                              

  字符常量                                                                      
  字符型常量是一个单一的字符,其形式是由两个单引号引起来的一个字符。            
  但是两个单引号引起来的不能是单引号和反斜杠,即‘'’和‘/’是不正确的写法。  

  大家一定要记住,Java语言中的字符

是16位的Unicode字符,这与C/C++等语言是不一样的


  同C/C++语言一样,Java语言也有转
意序列。Java中的转意序列的功能见下表:

  转义序列 标准形式 功能描述                                                 
   /  继续                                                                 
   /n NL 回车换行                                                       
   /t HT 水平制表符                                                     
   /b BS 后退一格                                                       
   /r CR 回车不换行                                                     
   /f FF 换页                                                           
   /' ' 单引号                                                           
   // / 反斜杠                                                           
   /" " 双引号                                                           
   /ddd 0ddd 八进制模式                                             
   /xddd 0xddd 十六进制模式                                       
   /udddd 0xdddd Unicode双字节字符                       

  字符串常量                                                                    
  字符串常量是由双引号
符串不是
引起来的一系列字符,与C/C++

语言中不同的是,Java语言中的字

  通过字符数组来实现的,而是通过字符串类(即String类)来实现的。          

  数据类型转换问题:                                                            
  (1)小范围--》大范围  自动转换                                          
  (2)大范围--》小范围  强制转换                                          
  (3)在位数相同的情况下,低精度向高精度晋升(四舍五入的原则)                
    float f = 3.14f                                            
    int i = (int) 3.14                                      
  (4)short,byte 在参与运算时,先自动晋升为int ,再运算。      

  public class javatest1                                  
  {                                                                            

    public static vo
id main(String[] args)
    {                                                                        
      short a,b,c;                                              
      a=1;                                                              
      b=2;                                                              
      //c=a+b; //a+b结果为int,无法判定是否超过C的范围。  
      c=(short)(a+b);                                      
                                                                            
      System.out.println(c);                          
    }                                                                        
  }                                                                            

  引用类型                                                                      

  数组                                                                          
  对象                                                                         

  创建对象的过程:                                                              
  (1)定义一个类;                                                            
  (2)声明一个对象;                                                          
  (3)创建一个对象;                                                          

  new 关键字的作用:                                                        
  (1)为该对象分配内存空间;                                                  
  (2)返回该内存空间的引用,返回首地址;(引用是指指针的别名)                
  (3)调用构造函数,构造函数自动将成员函数赋初值。                            

  类实例等价于对象,都是保存在内存存储区的一块。                                

  输出类型                                                                      
  System.out.println();来自动调用 toString()    
  public String toString()                              

  5、按值传递(考点)                                                          
  在方法调用的时候,方法的传递原则:                                            
  基本类型数据的实参,传递的是实参的拷贝                                        
  引用类型的实参,传递的是引用首地址的拷贝                                      


  第三章 变量 操作符 流程控制

  1、变量以及作用域                                                            

  (1)成员变量,又称为属性、域;                                              
  整个类内可以使用,成员变量自动赋初值;                                        

  (2)方法变量。又称为自动变量,本地变量;                                    
  本方法内使用。                                                                
  方法变量执行的时候才赋初值,在使用之前必须赋初值。                            

  2、短路操作符                                                                
  &&,||具备短路作用                                                        

  a&&b当a为 false ,则不执行b,发生短路;                          
  a||b当a为 true , 则不执行b,发生短路。                          

  3、移位操作符                                                                
  << 左移,空位全部补0,左移
时)
值=2^n*原值(n移动位数,无溢出时成立,丢“0”

  >> 右移,空位补0或者1,如原数最高为1,则补1;如原数最高为0,则补0;  
  >>>右移,空位全部补0。                                                    

  4、流程控制                                                                  
  switch (){                                                          
  case 常量1 : 语句1;break;                                    
  case 常量2 : 语句2;break;                                    
  default : 语句;                                                    
  }                                                                            

  如果没有,程序会继续往下执行,执行下一个case.                            

  标号只允许出现在循环代码的前面。                                              

  第五章 数组                                                                  
  1、声明数组,不能指出数组的大小。                                            
  int [] i ;                                                          
  int i [] ;                                                          
  2、创建数组 数组成员自动化(相当于类的成员变量)                            
  int [] i = new int [3]                                  
  3、赋值                                                                      
  i[0]=1;                                                                
  int [] i ={1,2,3}                                            
  int [] i,j ;i = new int [3]; j=i;            
  int [] i = new int [] {1,2,3}                    

  2维数组                                                                      
  声明、创建                                                                    
  int i [][]= new int[2][3]                            
  int []i[] = new int[
2][ ] (必须指出第一维数组的
大小)
  int [][]i = new int[2][3]                            

  数组的维数不同,不能通过交换应用来赋值。                                      
  int []i,j[];                                                      
  i = new int [3];                                              
  j = new int [2][3];  
阅读全文
0 0

相关文章推荐

img
取 消
img