COMPSCI 61B Lecture Notes - Lecture 2: Javac, Init
Document Summary
Running java programs javac [java program] : compiles and produces . class le java [class name] : runs program cat prints contents of les. class le has been type checked, so distributed code is safer. class les are simpler" for machines to interpret, so it runs faster protects ip (don"t need to give out source) Static: invoked using the class name ( dog. makenoise(cid:383)(cid:384); ) can not access my" instance variables bc there"s no me". Instance: invoked using an instance name ( maya. makenoise(cid:383)(cid:384); ) can use instance variables. Why static methods? x = math. round(cid:383)(cid:620). (cid:621)(cid:384); makes more sense that creating a particular math object. Example: comparing two dogs public static dog maxdog(cid:383)dog d(cid:616), dog d(cid:617)(cid:384){ if (cid:383)d(cid:616). weightinpounds > d(cid:616). weightinpounds(cid:384) return d(cid:616); return d(cid:617); public static void main(string[] args) $ java argsdemo hello some args args : [ hello", some", args"] Using libraries (stddraw, in) built-in libraries (math, string, integer, list, map)