CS5303-Computer Science I (Java I)

What is Java ?

  • Java is a virtual machine programming language
  • A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode.
  • The virtual machine runs on different platforms(Apple, PC Desktop, Linux, etc.)
  • The Java class files then run on any version of the virtual machine.
  • This gives cross-platform performance.

Running a Java Application

  • Create a class with main.
  • Compile into a Java class file.

How to Write a Java Program

  • Method 1: Text Editing
  • EMACs, VI, TextEdit
  • Method 2:Using an IDE
    Netbeans/Eclipse/BlueJ

Data Types

在这里插入图片描述

The order of operation:

• Parenthesis first: ()
• Multipliers second: *,/,%
• Additive: +, -
• Relational: <,>,<=,>=
• Equality: ==,!=
• Assignment: =

System.*

  • System.in – is an InputStream which is typically connected to keyboard input of console programs.
  • System.out – is a PrintStream. System.out normally outputs the data you write to it to the console(used from command line tools&debug statements )
  • System.err – is a PrintStream. System.err works like System.out except it is normally only used to output error texts. Some programs(like Eclipse) will show the output to System.err in red text, to make it more obvious that it is error text.(System.out is buffered, and System.err is not)
  • System.in.available() – returns the number of bytes that can be read from this input stream without blocking by the next invocation of a method from this input stream.
  • System.in.read() – reads the next byte of the data from the the input stream and returns int in the range of 0 to 255. If no byte is available because the end of the stream has been reached, the returned value is -1.
  • System.in.read(byte b[]) – reads b.length number of bytes from the input stream to the buffer array b. The bytes read is returned as integer.
  • System.out.append(arg0) – appends a subsequence of the specified character sequence to this output stream.
  • System.out.flush() – flushes the console and forces any output to be written immediately.(write any data stored in the out buffer. Buffers store text up to a point and then write when full. If you terminate a program without flushing a buffer, you could potentially lose data.)
  • System.out.format(format, args) – writes a formatted string to this output stream using the specified format string and arguments.
String s = "Hello World";
PrintStream ps = new PrintStream(System.out);
ps.format("This is a %s  program", s);
ps.flush();

Result:
This is a Hello World program
  • System.out.print(b) – Refers to display a statement.
  • System.out.println() – Also refers to display a statement but at a new line, or we can say that println adds"\n" at the beginning and at the end of the statement.
 System.out.print("Hello");
 System.out.println("Hello");
 System.out.print("Hello");
 System.out.print("Hello");


Result:
Hello
Hello
HelloHello
  • System.out.printf(format, args)System.out.format() is equivalent to printf() and can also be used.

Notation:
Many developers also confuse between printf() and format(), they are exactly same, only different is one is declared in java.lang.String class and other is on java.io.PrintStream. Use String.format() method if you need a formatted String and use System.out.printf() if you need to display formatted String on the console.

This is a very good explanation about the formatting of JAVA, i think:
http://www.java67.com/2016/12/7-examples-of-stringformat-and-printf.html#ixzz5YkMorEGm
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

Character Stream Vs Byte Stream in Java

link(in Chinese):http://www.importnew.com/23963.html
在这里插入图片描述
When to use Character Stream over Byte Stream?
In Java, characters are stored using Unicode conventions. Character stream is useful when we want to process text files. These text files can be processed character by character. A character size is typically 16 bits.
When to use Byte Stream over Character Stream?
Byte oriented reads byte by byte. A byte stream is suitable for processing raw data like binary files.

Some Acronyms:

• OEM-Original Equipment Manufacter
• DK-Development Kit
• SDK-Software Development Kit
• DDK-Driver Development Kit
• DLL-Dynamic Link Library
• LIB-Library
• API-Application Programming Interface

Not the End
To be continue

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值