本文目錄一覽:
- 1、北大青鳥設計培訓:關於Java語言的基礎特性分析?
- 2、談談Java中多態的意義;簡述多態的實現機制,並舉例分析
- 3、求詞法分析器java語言實現的代碼,求解
- 4、java分析以下需求,並用代碼實現:
北大青鳥設計培訓:關於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”));
}
}
原創文章,作者:WVVFU,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/330109.html