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