ava要运行html代码,需要运行在服务器端,也就是servlet容器中,经过容器编译解析,返回html静态内容,示例如下:
在servlet里面写就可以了
引入一系列包
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
public class Servlet1 extends HttpServlet {
public void doGet(ServletRequest req,ServletResponse res)throws ServletException, IOException{try{PrintWriter pw=res.getWriter();//在浏览器输出需要
pw.println("scriptscript");}catch(exception e){="" e.printstacktrace();="" 为发现调试错误}}}=""
public class Demo{
public static void main(String[] args){
int result = 1;
for(int i = 1;i = a; i ++){
result *= a;
}
获取系统时间:
import java.util.*;
import java.text.*;
public class TestDate {
public static void main(String[] args) {
Calendar ca = Calendar.getInstance();
int year = ca.get(Calendar.YEAR);//获取年份
int month=ca.get(Calendar.MONTH);//获取月份
int day=ca.get(Calendar.DATE);//获取日
int minute=ca.get(Calendar.MINUTE);//分
int hour=ca.get(Calendar.HOUR);//小时
int second=ca.get(Calendar.SECOND);//秒
int WeekOfYear = ca.get(Calendar.DAY_OF_WEEK);
用系统时间跟生日比较就行了
NewPhone类
package?com.baidu.question;
public?class?NewPhone?extends?Phone?{
private?boolean?mute?=?true;
public?void?call()?{
if(mute){
super.call();
}else{
System.out.println("语音已关闭");
//这里是直接设置
public?void?setMute(boolean?mute){
this.mute=mute;
//担心你的题目是要求两种方法,写的第二种,下面两个方法负责开关
public?void?openMute(){
this.mute=true;
/*
*?也可以这样写
*?setMute(true);
*?下边的方法一样
*?*/
public?void?closeMute(){
this.mute?=?false;
Phone类
public?class?Phone?{
public?void?call(){
System.out.println("打电话");
测试类
public?class?PhoneTest?{
public?static?void?main(String[]?args)?{
Phone?phone?=?new?Phone();
phone.call();
NewPhone?newPhone?=?new?NewPhone();
newPhone.call();
newPhone.setMute(false);
newPhone.openMute();
newPhone.closeMute();
测试结果
打电话
语音已关闭
import java.security.InvalidKeyException;import java.security.NoSuchAlgorithmException;import javax.crypto.BadPaddingException;import javax.crypto.Cipher;import javax.crypto.IllegalBlockSizeException;import javax.crypto.KeyGenerator;import javax.crypto.NoSuchPaddingException;import javax.crypto.SecretKey;public class JEncrytion{
public static void main(String[] argv) {
try{ KeyGenerator keygenerator = KeyGenerator.getInstance("DES"); SecretKey myDesKey = keygenerator.generateKey();
Cipher desCipher; // Create the cipher
// 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){
}catch(InvalidKeyException e){
}catch(IllegalBlockSizeException e){
}catch(BadPaddingException e){
(1) 类名首字母应该大写.字段、方法以及对象(句柄)的首字母应小写.对于所有标识符,其中包含的所有单词都应紧靠在一起,而且大写中间单词的首字母.
例如:
ThisIsAClassName
thisIsMethodOrFieldName
若在定义中出现了常数初始化字符,则大写static final基本类型标识符中的所有字母.这样便可标 志出它们属于编译期的常数.
equals()
hashCode()
toString()
clone()(implement Cloneable)
implement Serializable
■一个复杂的开关语句:考虑采用"多形"机制
■数量众多的方法涉及到类型差别极大的操作:考虑用几个类来分别实现
■许多成员变量在特征上有很大的差别:考虑使用几个类
在多线程环境中,隐私是特别重要的一个因素--只有private字段才能在非同步使用的情况下受到保护.
(11) 尽可能细致地加上注释,并用javadoc注释文档语法生成自己的程序文档.
性能提升的隐含代价是自己的代码变得难于理解,而且难于维护.
以上就是土嘎嘎小编为大家整理的用java代码如何做春联相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!