| Line 3: |
Line 3: |
| | ===With apt=== | | ===With apt=== |
| | <nowiki>sudo apt-add-repository ppa:webupd8team/java | | <nowiki>sudo apt-add-repository ppa:webupd8team/java |
| − | sudo apt-get update
| + | sudo apt-get update |
| − | sudo apt-get install oracle-java8-installer</nowiki>
| + | sudo apt-get install oracle-java8-installer</nowiki> |
| | | | |
| | Also ensure your JAVA_HOME variable has been set to: | | Also ensure your JAVA_HOME variable has been set to: |
| Line 1,399: |
Line 1,399: |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | == Java tips == | + | ==Java tips== |
| | | | |
| − | === Static imports === | + | ===Static imports=== |
| | <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| | import static java.lang.System.out; | | import static java.lang.System.out; |
| Line 1,411: |
Line 1,411: |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | === Blocks === | + | ===Blocks=== |
| | <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| | pubublic class BlocksRunner { | | pubublic class BlocksRunner { |
| Line 1,424: |
Line 1,424: |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | === equals and hashCode methods from an object === | + | ===equals and hashCode methods from an object=== |
| | 2 objects only obj.equals if they are the same object, but equals can be overriden (generate hashcode and equals) | | 2 objects only obj.equals if they are the same object, but equals can be overriden (generate hashcode and equals) |
| | | | |
| | Hash function should return the same value if 2 objects are equal | | Hash function should return the same value if 2 objects are equal |
| | | | |
| − | === Access modifiers === | + | ===Access modifiers=== |
| | public: accessible every where. | | public: accessible every where. |
| | | | |
| Line 1,438: |
Line 1,438: |
| | private: only inside the class. | | private: only inside the class. |
| | | | |
| − | === non access modifier === | + | ===non access modifier=== |
| | | | |
| − | ==== final ==== | + | ====final==== |
| | final classes can not be extended. | | final classes can not be extended. |
| | | | |
| Line 1,449: |
Line 1,449: |
| | final argument can not be changed. | | final argument can not be changed. |
| | | | |
| − | ==== static ==== | + | ====static==== |
| | static class variables are common to all class instances. | | static class variables are common to all class instances. |
| | | | |
| | static methods can be called from class, no need for instance, inside static methods instance variables or methods are not accessible. | | static methods can be called from class, no need for instance, inside static methods instance variables or methods are not accessible. |
| | | | |
| − | ==== Constants ==== | + | ====Constants==== |
| | public static final | | public static final |
| | | | |
| − | ==== Enums ==== | + | ====Enums==== |
| | like: java.time.Month, java.time.DayOfWeek<syntaxhighlight lang="java"> | | like: java.time.Month, java.time.DayOfWeek<syntaxhighlight lang="java"> |
| | enum Season { | | enum Season { |
| Line 1,484: |
Line 1,484: |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | == Sort strings == | + | ==Sort strings== |
| | <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| | import java.util.ArrayList; | | import java.util.ArrayList; |
| Line 1,508: |
Line 1,508: |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| | + | == Logger == |
| | + | <syntaxhighlight lang="java"> |
| | + | import java.util.logging.Logger |
| | + | |
| | + | public class BubbleSort { |
| | + | public List<String> sort(List<String> names){ |
| | + | return names; |
| | + | } |
| | + | } |
| | + | |
| | + | public class MySortingUtil { |
| | + | public List<String> sort(List<String> names){ |
| | + | BubbleSort bubbleSort = new BubbleSort(); |
| | + | return bubbleSort.sort(names); |
| | + | } |
| | + | } |
| | + | |
| | + | public class MySortingUtilConsumer { |
| | + | private static Logger logger = Logger.getLogger(MySortingUtilConsumer.class.getName()); |
| | + | |
| | + | public static void main(String args){ |
| | + | MySortingUtil util = MySortingUtil(); |
| | + | List<String> sorted = util.sort(List.of("Elephant", "Bat", "Mosquito")); |
| | + | logger.info(sorted.toString()); |
| | + | } |
| | + | } |
| | + | </syntaxhighlight><br /> |
| | ==Eclipse shortcuts== | | ==Eclipse shortcuts== |
| | Ctrl + Space → Autocomplete.<br /> | | Ctrl + Space → Autocomplete.<br /> |
| Line 1,517: |
Line 1,544: |
| | ==Notes== | | ==Notes== |
| | Hibernate → Java ORM framework for web design | | Hibernate → Java ORM framework for web design |
| | + | |
| | + | == java cli == |
| | + | <syntaxhighlight lang="bash"> |
| | + | # Compile class |
| | + | javac someclass.java |
| | + | |
| | + | # List modules |
| | + | java --list-modules |
| | + | |
| | + | # Java shell |
| | + | jshell |
| | + | |
| | + | # Run java application |
| | + | java someclass.jar |
| | + | |
| | + | # List module dependencies |
| | + | java -d java.sql |
| | + | |
| | + | |
| | + | </syntaxhighlight> |