Posts

Showing posts from March, 2022

How to generate java doc in MAC

Image
  How to generate JavaDoc? Method1: using IDEA Tools -> Generate JavaDocs Check the result in your browser Method 2: using terminal to generate javadoc open in Finder find the directory open terminal cd "the directory" typing the commond: javadoc -encoding UTF-8 -charset UTF-8 "java file" Then you can see your java document in the browser

Java operator

  Java operator arithmetic operators: +, -, *, /, %(surplus), ++, -- some tricky things between a++ and ++a: public class Demo01 {     public static void main ( String [] args ) {         int a = 3 ;         int b = a ++ ; //a = a + 1         int c = ++ a ;         System . out . println ( a ); // a = 5 due to added twice         System . out . println ( b ); // b = 3         System . out . println ( c ); // c = 5   } } a++ means assign first, add later ++a means add first, then assign exponentiation: double pow = Math . pow ( 3 , 2 ) // 2^3 2 to power of 3 logical operator and && or|| Negate !(a||b) shortcut cirtcuits operation : when first boolean is false, program will not process next boolean operation, e.g., int s1 = 5 ; boolean boo = ( s1 < 4 ) && ( s1 ++<= 5 ); System . out . printl...

Java variable

Java value conversion From low to high: Byte, short, char-> int -> long -> float -> double Cast: from high level to low one, e.g., int i = 128   byte b = ( byte ) i   //output b = -128 memory overflow Notes: boolean value is unconversionable cast may lead to memory overflow, e.g., int money = 10_0000_0000 ; // JDK new feature: numbers can be separted by "_" int year = 20 ; int total = money * year ; // memory overflow //solution: long total = money * (( long ) year ); Java variable While define a vairable: type name value String temp = "Java" Local variable Declaring and initializing values Instance variable Declaring in the class If there is no initilizing values, it will return defualt value ( boolean :false, basic types : 0, other type : null) Example for using instance variable public class Demo05 {     String i1 ;     int i2 ;     public static void main ( String [] args ) {     ...

Java data type - Java study notes

Java comments Line comments: // Block comments: /* */ JavaDoc: /** */ Java identifier All identifier should start with "A-Z", "a-z", "$" or "_" Java is case sensitive, e.g., "Man" is not equal to "man" Java data type [ Java is a strongly typed programming language because every variable must be declared with a data type. A variable cannot start off life without knowing the range of values it can hold, and once it is declared, the data type of the variable cannot change ] ( https://stackoverflow.com/questions/33958767/if-java-is-strongly-typed-then-why-does-this-code-compile#:~:text=Java%20is%20a%20strongly%20typed%20programming%20language%20because,the%20data%20type%20of%20the%20variable%20cannot%20change. ). Java has two data type Primitive type Integer: byte(1bits), short(2bits), int(4bits), long(8bits) Float: float(4bits), double(8bits) String: char(2bits) Boolean: true & false(1bit) public class demo02 {     publ...