给段最简单的java代码 让我新手看一下

Python022

给段最简单的java代码 让我新手看一下,第1张

最简单的java代码肯定就是这个了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world")

}

}

“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!

import java.security.InvalidKeyExceptionimport java.security.NoSuchAlgorithmExceptionimport javax.crypto.BadPaddingExceptionimport javax.crypto.Cipherimport javax.crypto.IllegalBlockSizeExceptionimport javax.crypto.KeyGeneratorimport javax.crypto.NoSuchPaddingExceptionimport javax.crypto.SecretKeypublic class JEncrytion{

public static void main(String[] argv) {

try{ KeyGenerator keygenerator = KeyGenerator.getInstance("DES") SecretKey myDesKey = keygenerator.generateKey()

Cipher desCipher // Create the cipher

desCipher = Cipher.getInstance("DES/ECB/PKCS5Padding")

// Initialize the cipher for encryption

desCipher.init(Cipher.ENCRYPT_MODE, myDesKey) //sensitive information

byte[] text = "No body can see me".getBytes()

System.out.println("Text [Byte Format] : " + text)

System.out.println("Text : " + new String(text))

// Encrypt the text

byte[] textEncrypted = desCipher.doFinal(text)

System.out.println("Text Encryted : " + textEncrypted)

// Initialize the same cipher for decryption

desCipher.init(Cipher.DECRYPT_MODE, myDesKey) // Decrypt the text

byte[] textDecrypted = desCipher.doFinal(textEncrypted)

System.out.println("Text Decryted : " + new String(textDecrypted))

}catch(NoSuchAlgorithmException e){

e.printStackTrace()

}catch(NoSuchPaddingException e){

e.printStackTrace()

}catch(InvalidKeyException e){

e.printStackTrace()

}catch(IllegalBlockSizeException e){

e.printStackTrace()

}catch(BadPaddingException e){

e.printStackTrace()

}

}

}