「java简单实现」java简单实现删除用户信息
今天给各位分享java简单实现的知识,其中也会对java简单实现删除用户信息进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、简单的JAVA字符串长度计算的实现
- 2、JAVA实现简单计算
- 3、Java实现简单的缓存机制原理
- 4、怎么用java实现一个简单的学生管理系统
- 5、Java进程怎么实现?
- 6、用Java实现一个简单功能
简单的JAVA字符串长度计算的实现
简单实现代码如下:
public
class
stringlength
{
/**
*
获取字符串的长度,如果有中文,则每个中文字符计为2位
*
@param
value
指定的字符串
*
@return
字符串的长度
*/
public
static
int
length(string
value)
{
int
valuelength
=
0;
string
chinese
=
"[\u0391-\uffe5]";
/*
获取字段值的长度,如果含中文字符,则每个中文字符长度为2,否则为1
*/
for
(int
i
=
0;
i
value.length();
i++)
{
/*
获取一个字符
*/
string
temp
=
value.substring(i,
i
+
1);
/*
判断是否为中文字符
*/
if
(temp.matches(chinese))
{
/*
中文字符长度为2
*/
valuelength
+=
2;
}
else
{
/*
其他字符长度为1
*/
valuelength
+=
1;
}
}
return
valuelength;
}
public
static
void
main(string
args[]){
string
str
=
"hello你好";
system.out.println(stringlength.length(str));
}
}
JAVA实现简单计算
public class Number {
private Integer n1;
private Integer n2;
/** 构造方法 */
public Number(Integer n1, Integer n2) {
super();
this.n1 = n1;
this.n2 = n2;
}
/** 加 */
public Integer addition() {
System.out.println(this.n1 + this.n2);
return this.n1 + this.n2;
}
/** 减 */
public Integer subtration() {
System.out.println(this.n1 - this.n2);
return this.n1 - this.n2;
}
/** 乘 */
public Integer multiplication() {
System.out.println(this.n1 * this.n2);
return this.n1 * this.n2;
}
/** 除 */
public Integer division() {
System.out.println(this.n1 / this.n2);
return this.n1 / this.n2;
}
public Integer getN1() {
return n1;
Java实现简单的缓存机制原理
package qinbo hui;
/*
设计思想来自-回钦波(qq: )
*/
public class CacheConfModel implements java io Serializable{
private long beginTime;
private boolean isForever = false;
private int durableTime;
public long getBeginTime() {
return beginTime;
}
public void setBeginTime(long beginTime) {
this beginTime = beginTime;
}
public boolean isForever() {
return isForever;
}
public void setForever(boolean isForever) {
this isForever = isForever;
}
public int getDurableTime() {
return durableTime;
}
public void setDurableTime(int durableTime) {
this durableTime = durableTime;
}
}
package qinbo hui;
import java util *;
import test CacheConfModel;
/*
设计思想来自-回钦波(qq: )
*/
public class CacheMgr {
private static Map cacheMap = new HashMap();
private static Map cacheConfMap = new HashMap();
private CacheMgr(){
}
private static CacheMgr cm = null;
public static CacheMgr getInstance(){
if(cm==null){
cm = new CacheMgr();
Thread t = new ClearCache();
t start();
}
return cm;
}
/**
* 增加缓存
* @param key
* @param value
* @param ccm 缓存对象
* @return
*/
public boolean addCache(Object key Object value CacheConfModel ccm){
boolean flag = false;
cacheMap put(key value);
cacheConfMap put(key ccm);
System out println( now addcache== +cacheMap size());
return true;
}
/**
* 删除缓存
* @param key
* @return
*/
public boolean removeCache(Object key){
cacheMap remove(key);
cacheConfMap remove(key);
System out println( now removeCache== +cacheMap size());
return true;
}
/**
* 清除缓存的类
* @author wanglj
* 继承Thread线程类
*/
private static class ClearCache extends Thread{
public void run(){
while(true){
Set tempSet = new HashSet();
Set set = cacheConfMap keySet();
Iterator it = erator();
while(it hasNext()){
Object key = it next();
CacheConfModel ccm = (CacheConfModel)cacheConfMap get(key);
//比较是否需要清除
if(!ccm isForever()){
if((new Date() getTime() ccm getBeginTime())= ccm getDurableTime()* * ){
//可以清除 先记录下来
tempSet add(key);
}
}
}
//真正清除
Iterator tempIt = erator();
while(tempIt hasNext()){
Object key = tempIt next();
cacheMap remove(key);
cacheConfMap remove(key);
}
System out println( now thread================ +cacheMap size());
//休息
try {
Thread sleep( * L);
} catch (InterruptedException e) {
// TODO Auto generated catch block
e printStackTrace();
}
}
}
}
lishixinzhi/Article/program/Java/hx/201311/25737
怎么用java实现一个简单的学生管理系统
用java写的话,可以用List来实现学生管理系统:
首先,管理系统是针对学生对象的,所以我们先把学生对象就写出来:
package bean;
public class Student {
String name;
String studentId;
String sex;
int grade;
public Student(String name,String studentId,String sex,int grade){
this.name= name;
this.studentId= studentId;
this.sex = sex;
this.grade = grade;
}
public int getGrade(){
return grade;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public void setGrade(int g){
this.grade = g;
}
public String getStudentId(){
return studentId;
}
}
这里面定义了一些得到当前学生对象数据的一些get方法,和成绩修改的set方法,代码很简单,就不做详细的解答。
就下来就是我们的正文了。
虽然我们暂时不用swing来做界面,但是总得要看的过去吧,所以,先做了一个比较简单的界面:
System.out.println("***************");
System.out.println("*欢迎来到学生管理系统 *");
System.out.println("*1:增加学生 *");
System.out.println("*2:删除学生 *");
System.out.println("*3:修改成绩 *");
System.out.println("*4:查询成绩 *");
System.out.println("***************");
System.out.println("您想选择的操作是:");
这里可以看到,我们的是用一个1234来选择项目,说以不得不讲一下Java如何获取到键盘所输入的数据---------Scanner ,要使用这个,首先需要import进来一个包:
例如这里:
import java.util.*;
之后的两行代码搞定输入:
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
接下来就是各个功能的实现:
package test;
import java.util.*;
import bean.Student;
public class Manager {
static ListStudent StudentList = new LinkedListStudent();
public static void main(String[] agrs){
select(StudentList);
}
private static void select(ListStudent StudentList ){
System.out.println("***************");
System.out.println("*欢迎来到学生管理系统 *");
System.out.println("*1:增加学生 *");
System.out.println("*2:删除学生 *");
System.out.println("*3:修改成绩 *");
System.out.println("*4:查询成绩 *");
System.out.println("***************");
System.out.println("您想选择的操作是:");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
switch(choice){
//增加学生
case 1:
System.out.print("请输入学生的姓名:");
Scanner Sname = new Scanner(System.in);
String name = Sname.nextLine();
System.out.print("请输入学生的性别:");
Scanner Ssex = new Scanner(System.in);
String sex = Ssex.nextLine();
System.out.print("请输入学生的学号:");
Scanner SId = new Scanner(System.in);
String studentId = SId.nextLine();
System.out.print("请输入学生的成绩:");
Scanner Sgrade = new Scanner(System.in);
int grade = Sgrade.nextInt();
StudentList.add(new Student(name,studentId,sex,grade));
System.out.println("添加成功!!!!!");
select(StudentList);
break;
//删除学生成绩
case 2:
System.out.print("请告诉我需要删除学生的学号:");
Scanner Sid = new Scanner(System.in);
String SstudentId = Sid.nextLine();
boolean isfindDelete = false;
for (int i = 0; i StudentList.size(); i++) {
if(SstudentId.equals(StudentList.get(i).getStudentId())){
System.out.println("发现了该学生,正在删除...");
StudentList.remove(i);
System.out.println("删除成功!!!");
isfindDelete =true;
}
}
if(!isfindDelete){
System.out.println("抱歉,没有找到");
}
select(StudentList);
break;
//修改学生成绩
case 3:
System.out.print("请告诉我需要修改成绩学生的学号:");
Scanner GId = new Scanner(System.in);
String GstudentId = GId.nextLine();
boolean isfindChange = false;
for (int j = 0; j StudentList.size(); j++) {
if(GstudentId.equals(StudentList.get(j).getStudentId())){
System.out.println("发现了该学生,正在修改...");
System.out.println("学生原成绩为"+StudentList.get(j).getGrade());
System.out.print("请输入修改后学生的成绩:");
Scanner Ggrade = new Scanner(System.in);
int grade2 = Ggrade.nextInt();
StudentList.get(j).setGrade(grade2);
System.out.println("修改成功!!!");
isfindChange =true;
}else{
}
}
if(!isfindChange){
System.out.println("抱歉,没有找到");
}
select(StudentList);
break;
//查看学生成绩
case 4:
System.out.print("请告诉我需要查询学生的学号:");
Scanner CId = new Scanner(System.in);
String CstudentId = CId.nextLine();
boolean isfindData = false;
for (int i = 0; i StudentList.size(); i++) {
if(CstudentId.equals(StudentList.get(i).getStudentId())){
System.out.println("名字:"+StudentList.get(i).getName());
System.out.println("性别:"+StudentList.get(i).getSex());
System.out.println("学号:"+StudentList.get(i).getStudentId());
System.out.println("成绩:"+StudentList.get(i).getGrade());
isfindData = true;
}
}
if(!isfindData){
System.out.println("抱歉,没有找到");
}
select(StudentList);
break;
default:
System.out.println("您输入的数字有误,请重新输入:");
break;
}
}
}
可以看见,我把所有的实现过程全部放在select();方法中了,这样可以避免我选择完了一个操作后不能继续其他操作。大部分的操作都是依靠for循环来遍历操作,方便快捷。
Java进程怎么实现?
Java中多进程编程的实现,和多线程一样,多进程同样是实现并发的一种方式,需要的朋友可以参考下
1.Java进程的创建
Java提供了两种方法用来启动进程或其它程序:
(1)使用Runtime的exec()方法
(2)使用ProcessBuilder的start()方法
1.1 ProcessBuilder
ProcessBuilder类是J2SE 1.5在java.lang中新添加的一个新类,此类用于创建操作系统进程,它提供一种启动和管理进程(也就是应用程序)的方法。在J2SE 1.5之前,都是由Process类处来实现进程的控制管理。
每个 ProcessBuilder 实例管理一个进程属性集。start() 方法利用这些属性创建一个新的 Process 实例。start() 方法可以从同一实例重复调用,以利用相同的或相关的属性创建新的子进程。
每个进程生成器管理这些进程属性:
命令 是一个字符串列表,它表示要调用的外部程序文件及其参数(如果有)。在此,表示有效的操作系统命令的字符串列表是依赖于系统的。例如,每一个总体变量,通常都要成为此列表中的元素,但有一些操作系统,希望程序能自己标记命令行字符串——在这种系统中,Java 实现可能需要命令确切地包含这两个元素。
环境 是从变量 到值 的依赖于系统的映射。初始值是当前进程环境的一个副本(请参阅 System.getenv())。
工作目录。默认值是当前进程的当前工作目录,通常根据系统属性 user.dir 来命名。
redirectErrorStream 属性。最初,此属性为 false,意思是子进程的标准输出和错误输出被发送给两个独立的流,这些流可以通过 Process.getInputStream() 和 Process.getErrorStream() 方法来访问。如果将值设置为 true,标准错误将与标准输出合并。这使得关联错误消息和相应的输出变得更容易。在此情况下,合并的数据可从 Process.getInputStream() 返回的流读取,而从 Process.getErrorStream() 返回的流读取将直接到达文件尾。
用Java实现一个简单功能
这个问题需要用到javax.swing包下的JFileChooser类。这个类就是弹出一个可以打开文件以及保存的窗口。我想楼主肯定是需要打开文件,并显示到一个文本区域中;保存文件就是保存文本区域中的文本,并写入到磁盘中。我给你写个例子你可以看看。
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame implements ActionListener
{
private JTextArea area;
private JButton button1;
private JButton button2;
public Test() throws Exception
{
area=new JTextArea();
button1=new JButton("保存");
button2=new JButton("打开");
button1.addActionListener(this);//注册按钮事件
button2.addActionListener(this);//注册按钮事件
this.setLayout(new GridLayout(3,1));//设置布局管理器
this.add(area);
this.add(button1);
this.add(button2);
this.setSize(300,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭事件
}
public void actionPerformed(ActionEvent e) //关键代码,事件处理
{
JFileChooser choose=new JFileChooser();//创建文件选择器
if(e.getActionCommand().equals("保存"))//当事件源是“保存”的时候发生如下事件:
{
int result=choose.showSaveDialog(this);//调用保存对话框,result是返回的参数
File file=choose.getSelectedFile();//返回选择的文件
if(result==0) {//当参数等于0是就证明你点的是保存,下面打开是同理的
try{
FileWriter fw=new FileWriter(file);//创建FileWriter流
area.write(fw);//JTextArea的方法write()可以直接将文件写入
}catch(Exception ee) {
ee.printStackTrace();
}
}
}
else//当事件源是“打开”的时候发生如下事件:
{
int result=choose.showOpenDialog(this);
System.out.println(result);
if(result==0) {
try{
File file=choose.getSelectedFile();
FileReader reader=new FileReader(file);
area.read(reader,"open");//JTextArea的方法read()方法可以直接读取文件,并将文本内容写入到JtextArea上,第二个参数不用管它
}catch(Exception ee)
{
ee.printStackTrace();
}
}
}
}
public static void main(String[] args) throws Exception
{
Test test=new Test();
test.setVisible(true);
}
}
总之如果楼主只想知道怎么弹出窗口,那么就用JFileChooser类的showOpenDialog和showSaveDialog方法就可以了
关于java简单实现和java简单实现删除用户信息的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-12-31,除非注明,否则均为
原创文章,转载请注明出处。