`
ericslegend
  • 浏览: 86532 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Some Java Points

    博客分类:
  • Java
阅读更多

1.      按空格区分:

l         String input = "1 fish 2 fish red fish blue fish";

Scanner s = new Scanner(input);

  while (s.hasNext()) System.out.println(s.next());

l         StringTokenizer st = new StringTokenizer("this is a test");
       while (st.hasMoreTokens())    System.out.println(st.nextToken());

l         Scanner sc = new Scanner(System.in);

int i = sc.nextInt();

System.out.println(i); 

2.         Java Application是一个完整的程序,它需要独立的解释器来解释执行。它和其他的Windows应用程序一样,可以居于窗体界面运行也可以在命令行运行。

Java Applet也成为小程序,适合在网络中传输,安全可靠,功能强大,特别适合用于开发Web的交互式界面。它是一种嵌入到Web页面的网络安全应用程序,由Web浏览器内部的Java解释器解释执行,它的主要功能是在浏览器实现某些特殊的效果。网络用户访问服务器的Applet时,这些浏览器可下载该程序,然后再浏览器运行它。

JSP是一种用于生成动态网页的技术,类似ASP,它基于Servlet技术,在传统的网页HTML文件中加入java程序片断和JSP标记,就构成了JSP网页。JSP程序同样可运行于Web服务器端,实现程序与页面格式控制的分离,网络上传送给客户端的仅是得到的结果。

JVM是软件模拟的虚拟计算机,可以在任何处理器上安全兼容地执行java程序。

3.         Applet生命周期示意图

4.         <HTML>

<APPLET CODE=appley程序名.class WIDTH=500 HEIGHT=100>

</APPLET>

</HTML>

appletviewer 文件名.html

5.         DecimalFormat

import java.text.DecimalFormat

DecimalFormat twoDigits = new DecimalFormat( "0.00" );

twoDigits.format( 变量 );

0

 

 

阿拉伯数字

0.00%  

  #

 

 

阿拉伯数字,如果不存在则显示为 0

'#'#0.00

 

 

0.###E0  将数字 1234 格式化为 "1.234E3,详见该类文档-科学计数法部分

-0.000

\u2030  乘以 1000 并显示为千分数

\u00A40.00   \u00A4货币符号

+0.00;-0.00

6.         NumberFormat 是所有数值格式的抽象基类。

Math.maxa,b  Math.mina,b  Math.random()

Math.toDegrees()角度到弧度 Math.toRadians()弧度到角度

Class Arrays 

例:Arrays ary;  ary.sort(数组名);  ary.binarySearch(数组名,元素);-返回元素索引,不详

7.         GC,finalize   

    use overridden methods

 

8.         StringBuffer待看11

substring(int start, int end) 

返回一个新的 String,它包含此序列当前所包含的字符子序列。

substring(int start)
          
返回一个新的 String,它包含此字符序列当前所包含的字符子序列

subSequence(int start, int end)
          
返回一个新的字符序列,该字符序列是此序列的子序列。

Character

StringTokenizer

Pattern正则表达式的编译表示形式

9.         Jlist   list; JscrollPane scp;

    list = new JList(fontlist);// fontlist为数组名

    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    list.setLayoutOrientation(JList.VERTICAL);

    scp = new JScrollPane(list);

    list.addListSelectionListener(this);

public void valueChanged(ListSelectionEvent e)

    {

        if (e.getSource() == list)

           string1=(String)list.getSelectedValue());

}

Choice choice=new Choice();

Choice.addItem(数组名);

choice.addItemListener(this);

public void itemStateChanged(ItemEvent e)[JcomboBox也是这个事件处理]

{if(e.getSource()==choice) {}}

 

JpopupMenu pop=new JpopupMenu();

pop.add(new JmenuItem(example);

pop.addMouseListener(this);

 public void mouseClicked(MouseEvent evt)

    {

        // 点击右键显示弹出菜单

        if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) != 0)

        {

            try{pop.show(this, evt.getX(), evt.getY());}catch(Exception e){}          }

}

 

Jtable待看

10.  addWindowListener(new WindowAdapter()

    {

        public void windowClosing(WindowEvent e)

        {setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);}

    });

11.     布局管理器

FlowLayout flo=new FlowLayout(FlowLayout.LEFT,20,60)

  左对齐,水平间隔20 ,垂直间隔60

BorderLayout bor=new BorderLayout(20,60)

水平间隔20 ,垂直间隔60

add(component, BorderLayout.EAST);

GridLayout gri=new GridLayout(rows,cols,20,60)

GridBagLayout  BoxLayout  CardLayout

12.     setOpaque(true)设置透明

13.     Synchronization

14.     sequential-access//顺序存取 and random-access//随机存取 file processing

15.  JFileChooser chooser = new JFileChooser();

    if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this))

        return chooser.getSelectedFile().getPath();

16.     URL统一资源定位符。资源类型(网络协议),主机域名,资源文件名和端口四部分组成。

SocketIP表示网络上的计算机,端口号表示正在计算机上运行的进程。端口号与IP的组合就得出一个网络套接字。Socket是通信端点的一种抽象,它提供了一种发送和接收数据的机制,网络上的用户可以通过它与其他用户进行通信。Socket是两台计算机上运行的两个程序之间的一个双向通信的联结点,每一端称为一个Scoket,它提供一种面向连接的可靠的数据传输方式,它能保证发送的数据按顺序无重复地到达目的地。它是TCP/IP的编程接口。

Datagrams

17.     JDBC

String drivername=”sun.jdbc.odbc.JdbcOdbcDriver”;

Class.forName(drivername);

 

Connection   con=null;

con=DriverManeger.getConnection(“jdbc:odbc:DatabaseDSN”,”sername”,”usernumber”);

Statement stmt=con..createStatement();

ResultSet  rs=stmt.executeQuery(“select * from DBTableName”);

//查询可用executeQuery(),插入删除可用executeUpdate()

rs.close();  stmt.close();  con.close(); //关闭连接

 

18.     CGI通用网关接口,Web技术发展的早期,动态页面的内容需要依靠传统语言与CGI技术的结合来完成,实现网上的数据管理。Servletjava技术对CGI的响应和超越。在传统CGI中,每个请求都会启动一个新的进程,如果CGI程序本身的执行时间较快,那么启动进程所需要的时间反而超过实际执行的时间。而在Servlet中,每个请求由一个轻量级的Java线程处理。在性能优化方面ServletCGI有更多的选择。Serlet能完成许多传统CGI不能完成的任务,比如直接和Web服务器通信交互,而普通CGI不能。

尽管CGI技术发展成熟且强大,但由于编程困难,效率低下,修改复杂而很难掌握。Servlet是一个java类,可视作java编写的CGI,但功能和性能更强大。

Servlet生命周期:

Public void init(ServletConfig con):仅有一个参数对象ServletConfig,他的主要功能是把ServletConfig对象储存起来。

Public void serviceServletReqllest req,ServletResponse,res 是真正需要处理请求的地方,对每个请求,servlet引擎将调用这个方法,并把请求对象和响应对象转为参数传递给它。

Public void destroy().

Servlet  API

 Servlet接口

 GenericServlet HttpServlet

 ServletRequestHttpServletRequest接口

 ServletResponseHttpServletResponse接口

19.     JSP标记:

<%程序块%>

<%!声明变量%>

<%=表达式%>

<%--注释语句--%>  <!--HTML注释语句-->

<%=表达式%>

分享到:
评论

相关推荐

    javacv-platform-1.3.3-src

    Simply put all the desired JAR files (opencv*.jar, ffmpeg*.jar, etc.), in addition to javacpp.jar and javacv.jar, somewhere in your class path. Here are some more specific instructions for common ...

    java 一手画方一手画圆 多线程

    Based on the given title, description, tags, and partial content, we can extract several important IT-related concepts and knowledge points regarding Java and multi-threading. Here’s a detailed ...

    test-driven-java-development-2nd2018

    Chapter 1, Why Should I Care for Test-Driven ...and some of the pain points are mitigated by the implementation of an effective development pipeline based on automated tests and continuous delivery.

    Java 80 道面试题及答案.docx

    Here are some key points related to volatile: 1. Volatile 数组: Java 中可以创建 volatile 数组,但是volatile 只是对数组引用有效,而不是整个数组。因此,如果改变数组的元素,volatile 不会提供保护。 2. ...

    JAVA小实验雷电(打飞机)

    重庆大学11级计算机学院JAVA小实验: Project 3:Raiden (雷電) Lite Overview Raiden (雷電,) is a 1990 scrolling shooter arcade ... The lesson ‘multithreading ’ maybe is useful to some advanced programmer.

    Android代码-Gank.io

    Java version : Java8 SDK Tool: 24.0.2 version jackOptions: true Points MVP dagger2 rxjava,rxAndroid,rxlife,rxbinding,rxbus retrofit,okhttp glide gson butterknife permissiondispatcher (权限管理工具) ...

    Android代码-javalin

    Javalin - A simple web framework for Java... Some key points: You don't need to extend anything There are no @Annotations There is no reflection There is no other magic; just code. General information:

    clustering

    Some common examples include: - **Customer segmentation** in marketing to identify distinct groups of customers with similar preferences. - **Document clustering** in information retrieval to ...

    Android通过Canvas手绘一个折线图

    private List&lt;Point&gt; dataPoints; private Paint linePaint; // 初始化数据和画笔 public LineChartView(Context context) { super(context); init(); } private void init() { dataPoints = new ...

    最新少儿python趣味课件.pdf

    Python是一种高级编程语言,它属于高级语言的范畴,包括Java、VB、Ruby、Python、C等多达上百种语言。计算机使用这些语言与人类进行交流,而编程语言是人类与计算机对话的特殊方式,是一种双方都能理解的指令集合。 ...

    Solr in Action 英文版完整版

    RETAIL SELLING POINTS Clearly-written comprehensive guide In-depth coverage of Solr 4 Uses real-world examples backed by years of experience AUDIENCE This book assumes some knowledge of Java and ...

    Gradle.Essentials.1783982365

    No prior knowledge of Gradle is required, but some familiarity with build-related terminologies and an understanding of the Java language would help. What You Will Learn Master the Gradle DSL by ...

    Delphi Cookbook Third Edition

    You will learn how to import Java and Objective C libraries in your app and how to use the SDK classes from your Object Pascal code. Chapter 10, Delphi and IoT, talks about how the two most popular ...

    camel-manual-2.0

    Endpoints are the starting and ending points of routes and represent external systems or services, such as databases, message brokers, or web services. Processors are responsible for transforming and ...

    Solr in Action最新完整版

    RETAIL SELLING POINTS Clearly-written comprehensive guide In-depth coverage of Solr 4 Uses real-world examples backed by years of experience AUDIENCE This book assumes some knowledge of Java and ...

    JSP Simple Examples

    This unit is discovered by Celsius in 1742, a Swedish astronomer and physicist, he has invented the centigrade, or Celsius thermometer divided between the freezing and boiling points of water into ...

    实验2、SQL的数据查询.doc

    - 子查询可以用于WHERE或HAVING子句中,根据不同的需求选择合适的谓词,如IN、NOT IN、比较运算符、SOME、ANY、ALL、EXISTS。 例如,查询所有选修了编号S26学生所选课程的学生编号: ```sql SELECT StudentID ...

    apktool documentation

    On some devices they might reside in /data/system-framework and even cleverly hidden in /system/app or /system/priv-app. They are usually named with the naming of "resources", "res" or "framework". ...

Global site tag (gtag.js) - Google Analytics