首页 > 编程知识 正文

分析和java简单实现(JAVA代码分析)

时间:2023-12-24 12:05:46 阅读:320892 作者:AOYG

本文目录一览:

北大青鸟设计培训:关于Java语言的基础特性分析?

Java语言的作者编写了一篇影响广泛的Java白皮书,详细阐述了他们的设计目标和成果,并简要介绍了Java语言的特点。

下面青岛北大青鸟为大家介绍Java语言的基础特性。

1、简单Java语言语法简单,易于掌握,是一种纯粹的面向对象语言。

并且青岛青岛电脑培训发现语法规则类似于C语言,Java语言在某种意义上是从C语言和C++语言转化而来的,因此C程序员可以很容易地掌握语言的语法。

2、面向对象面向对象是Java语言的基础,是Java语言的一个重要特征。

它本身就是一种纯面向对象的编程语言。

青岛计算机学校发现Java主张所有事物都是对象,语法不能在类之外定义单独的数据和函数,即Java语言最外部的数据类型是对象,所有元素都必须通过类和对象访问。

3、可移植性Java程序具有与体系结构无关的特点,可以很容易地移植到网络上的不同计算机上。

同时,青岛计算机学习发现Java类库也可以针对不同的平台实现接口,从而可以移植这些类库上。

谈谈Java中多态的意义;简述多态的实现机制,并举例分析

1、JAVA是区分类型的。算加法,这个方法名叫add,但是事实并不知道这个方法计算的是什么类型的:add(int a,int b)、add(float a, float b)、混合的、double的、数组、集合等等,但是要计算的时候只要调用add方法,自动找类型匹配的。

2、参数个数不同。假如要计算3个整形参数的,调用2次add(int a,int b)太麻烦,直接调用add(int a,int b,int c)就好了。

3、重写父类的方法。美国人和中国人都是继承人这个父类,美国人吃饭用刀叉,中国人吃饭用筷子,子类自己定义吃饭怎么实现,反正吃饭的方法名是一样的,调用起来方便。

前两种是重载可以理解成智能,第三个是重写可以说是扩展性强。总之就是为了方便。

求词法分析器java语言实现的代码,求解

/*

 * 词法分析

 * 

 */

import java.io.File;

import java.io.FileReader;

public class Compiler {

private static String string;

private static String str;

private static char ch;

/*

 * 读取文件

 */

public static void getChar() throws Exception{

File f= new File("C:\","test.txt");

if(!f.exists()){

System.out.println("文件不存在,请输入正确的文件路径");

}

FileReader fr = new FileReader(f);

int rs = 0;

char []data = new char[256];

System.out.print("");

while((rs = fr.read(data))  0){

string = new String(data,0,rs).trim();

}

}

/*

 *  判断读入的字符是否为字母

 */

public static boolean isLetter(char c){

if((ch = 'a'  ch = 'z') || (ch + 'A'  ch = 'Z')){

return true;

}

else

return false;

}

/*

 * 判断读入的字符是否为数字

 */

public static boolean isDigit(char c){

if(ch ='0'  ch = '9'){

return true;

}

else

return false;

}

/*

 * 判断是否为关键字

 */

public static boolean isKey(String string) {

if(string.equals("void") || string.equals("if")|| string .equals("for")|| string.equals("while") 

|| string.equals("do")|| string.equals("return")|| string.equals("break")

|| string.equals("main"))

{

return true;

}

else return false;

}

/*

 * 判断输入的字符并输出单词符号

 */

public static void judgement() throws Exception {

Compiler.getChar();

int m = 0;

string +=' ';

for(int i = 0;i  string.length();i++){

switch (m)

{

case 0:

ch = string.charAt(i);

if(ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '='

|| ch == '' || ch == '')

{

m = 4;

}

else if(ch == ',' || ch == ';' || ch == '{' || ch == '}' || ch == '(' || ch == ')')

{

m = 5;

else if ( isDigit((ch =string.charAt(i)) ) )

{

str = "";

str += ch;

m = 3;

else if ( isLetter(ch =string.charAt(i)) )

{

str = "";

str += ch;

m = 2;

}else {}

break;

case 4:

i--;

System.out.println(("( 4 " + "“ " + ch + " ” )"));

m = 0;

break;

case 5:

i --;

System.out.println(("( 5 " + "“ " + ch + " ” )"));

m = 0;

break;

case 2:

if (isLetter(ch = string.charAt(i)))

{

str += ch;

}

else

{

if ( isKey(str) )

{

System.out.println("( 1 " + "“ " + str + " ” )");

}else {

System.out.println(("( 2 " + "“ " + str + " ” )"));

}

i--;

m = 0;

}

break;

case 3:

if (isDigit((ch =string.charAt(i)) ) )

{

str += ch;

}

else 

{

System.out.println(("( 3 " + "“ " + str + " ” )"));

i --;

m = 0;

}

break;

}

}

}

public static void main(String[] args) throws Exception{

Compiler.judgement();

// System.out.print(b)  

}

}

java分析以下需求,并用代码实现:

根据需求,代码大致如下

public class T2 {

public static String getPropertyGetMethodName(String property) {

if (property == null || property.trim().length() == 0)

return "";

return "get" + String.valueOf(property.charAt(0)).toUpperCase()

+ property.subSequence(1, property.length());

}

public static void main(String[] args) {

System.out.println(getPropertyGetMethodName("a"));

System.out.println(getPropertyGetMethodName("name"));

System.out.println(getPropertyGetMethodName("names"));

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。