Tutorial Playlist
191 Lessons1. Introduction to Java
2. What is Java?
3. History of Java
4. Java Tutorial for Beginners
5. How Do Java Programs Work?
6. JDK in Java
7. C++ Vs Java
8. Java vs. Python
9. Java vs. JavaScript
10. From Java Source Code to Executable
11. How to Install Java in Linux
12. How to Install Java in Windows 10
13. Java Hello World Program
14. Structure of Java Program and Java Syntax
15. Operators in Java
16. Java If-else
17. Switch Case In Java
18. Loops in Java
19. Infinite loop in Java
20. For Loop in Java
21. For Each Loop in Java
22. Constructor in Java
23. Constructor Overloading in Java
24. Copy Constructor in Java
25. Default Constructor in Java
26. Parameterized Constructors in Java
27. Constructor Chaining In Java
28. Finalize Method in Java
29. Static Method in Java
30. Equals Method in Java
31. Abstract Method in Java
32. toString() Method in Java
33. Difference between equals method in Java
34. Inheritance in Java
35. Multiple Inheritance in Java
36. Hierarchical Inheritance in Java
37. Java Classes and Objects
38. Scanner Class in java
39. All classes in java are inherited from which class
40. What is Nested Class in Java
41. POJO Class in Java
42. Anonymous Class in Java
43. Final Class in Java
44. Object Class in Java
45. Packages in Java
46. Access Modifiers in Java
47. Static Keyword In Java
48. Final Keyword in Java
49. Checked and Unchecked Exceptions in Java
50. User Defined Exception in Java
51. Error vs. Exception in Java
52. Java Collection
53. Collections in Java
54. Garbage Collection in Java
55. Generics In Java
56. Java Interfaces
57. Functional Interface in Java
58. Marker Interface in Java
59. Streams in Java
60. Byte stream in java
61. File Handling in Java
62. Thread in Java
63. Thread Lifecycle In Java
64. Daemon Thread in Java
65. Thread Priority in Java
66. Deadlock in Java
67. String Pool in Java
68. Java Database Connectivity(JDBC)
69. Design Patterns in Java
70. Functional Programming in Java
71. OOP vs Functional vs Procedural
72. Heap Memory and Stack Memory in Java
73. Applet in Java
74. Java Swing
75. Java Frameworks
76. Hibernate Framework
77. JUnit Testing
78. How to Install Eclipse IDE for Java?
79. Command line arguments in Java
80. Jar file in Java
81. Java Clean Code
82. OOPs Concepts in Java
83. Java OOPs Concepts
84. Overloading vs Overriding in Java
85. Java 8 features
86. String in Java
87. String to int in Java
88. Why String Is Immutable in Java?
89. Primitive Data Types in Java
90. Non-Primitive Data Types in Java
91. This and Super Keyword in Java
92. HashMap in Java
93. Comparable And Comparator in Java
94. Type Casting in Java
95. Arrays Sort in Java with Examples
96. Variable Hiding and Variable Shadowing in Java
97. Enum in Java
98. Substring in Java
99. Pattern Programs in Java
100. Hashcode in Java
101. What is ByteCode in Java?
102. How To Take Input From User in Java
103. GCD of Two Numbers in Java
104. Linked List in Java
105. Arithmetic Operators in Java
106. Conditional Operators in Java
107. Stack and Queue in Java
108. Array Length in Java
109. Number Pattern Program in Java
110. Split in java
111. Map In Java
112. Difference Between Throw and Throws in Java
113. Difference Between Data Hiding and Abstraction
114. HashSet in Java
115. String Length in Java
116. Factorial Using Recursion in Java
117. DateFormat in Java
118. StringBuilder Class in java
119. Instance variables in Java
120. Java List Size
121. Java APIs
122. Reverse an Array in Java
123. StringBuffer and StringBuilder Difference in Java
124. Java Program to Add Two Numbers
125. String to Array in Java
126. Regular Expressions in Java
127. Identifiers in Java
128. Data Structures in Java
129. Set in Java
130. Pass By Value and Call By Reference in Java
131. Try Catch in Java
132. Bubble Sort in Java
133. Caesar Cipher Program in Java
134. Queue in Java
135. Object Creation in Java
136. Multidimensional Array in Java
137. How to Read a File in Java
138. String Comparison in Java
139. Volatile Keyword in Java
140. Control Statements in Java
141. Jagged Array in Java
142. Two-Dimensional Array in Java
143. Java String Format
144. Replace in Java
145. charAt() in Java
146. CompareTo in Java
147. Matrix Multiplication in Java
148. Static Variable in Java
149. Event Handling in Java
150. parseInt in Java
151. Java ArrayList forEach
152. Abstraction in Java
153. String Input in Java
154. Logical Operators in Java
155. instanceof in Java
156. Math Floor in Java
157. Selection Sort Java
158. int to char in Java
159. Stringtokenizer in java
160. Implementing and Manipulating Abs in Java
161. Char array to string in java
162. Convert Double To String In Java
163. Deque in Java
164. Converting a List to an Array in Java
165. The Max function in java
166. Removing whitespace from string in java
167. String arrays in Java
168. Strings in Java Vs Strings in Cpp
169. Sum of digits of a number in Java
170. Art of Graphical User Interfaces
171. Trim in Java
172. RxJava
173. Recursion in Java
174. HashSet Java
175. Difference Between Java and Python
176. Square Root in Java
177. Reverse A String in Java
178. Even Odd Program in Java
179. Fibonacci Series in Java
180. Prime Number Program in Java
181. Java Program to Print Prime Numbers in a Given Range
182. Java Leap Year Program
183. Swapping of Two Numbers in Java
184. LCM of Two Numbers in Java
185. Math.sqrt() Function in Java
186. Area of Triangle in Java
187. Sort a String In Java
188. Factorial Program in Java
189. Javafx
190. Lambda expression in java
191. Setup Java Home and IDE on macOS
Now Reading
Java is an agile, object-oriented programming language. It helps developers write code once and run it on any platform. It provides a robust ecosystem. This includes a virtual machine (JVM), libraries, and tools. This makes it popular for building various applications, from web and mobile to enterprise systems.
This tutorial teaches how to set up Java home and IDE on macOS.
In this tutorial, we will mainly deal with areas such as setting up JAVA_HOME and the IDE on macOS, the difference between JDK, JRE, and JVM, the first Java program on a Mac, and using a terminal via homebrew, among others.
The JVM (Java Virtual Machine) is responsible for executing Java programs. It takes the compiled bytecode. This is generated by the Java compiler (JAVAC). Then the JVM converts it into machine code. This is done to understand and execute it by the underlying hardware. The JVM is integral to the JDK (Java Development Kit) and the JRE (Java Runtime Environment). It performs various functions, such as memory management and security.
The JDK is a comprehensive package. This includes all the tools necessary for developing Java applications. It encompasses the compiler (JAVAC), the JRE, debugging tools, documentation (JavaDocs), and other utilities. The JDK provides a complete development environment. It allows programmers to write, compile, and test their Java code.
The JRE is a subset of the JDK. It is solely focused on running Java applications. It comprises the JVM, class libraries, and other resources required to execute Java bytecode. The JRE does not include development tools like the compiler or debugger. Its primary purpose is to provide a runtime environment for running Java programs.
JDK is essential for both compiling and running Java programs. It includes the necessary development tools and the JRE, encompassing the JVM and libraries for executing Java bytecode. The JRE, on its own, allows the execution of Java programs but lacks the development tools required for application development.
Here is a comprehensive list of differences between JDK, JRE, and JVM:
JDK (Java Development Kit) | JRE (Java Runtime Environment) | JVM (Java Virtual Machine) | |
Definition | Comprehensive package for developing Java applications | A subset of JDK focused on running Java applications | Runtime environment responsible for executing Java bytecode |
Components | Compiler (JAVAC), debugger, JavaDocs, libraries, development tools | JVM, libraries, applet support, plugins | Interpreter and runtime system for executing Java bytecode |
Purpose | Provides tools and resources for developing Java programs | Allows running Java programs | Converts bytecode into machine code and manages program execution |
Development Tools | Yes (includes compiler, debugger and other utilities) | No (focused on the runtime environment) | No (focused on the runtime environment) |
Execution | Can compile and run Java programs | Can only run Java programs | Executes compiled bytecode on the target hardware |
Platform-Dependent | Yes, different JDK versions for different platforms | Yes, JREs specific to each platform | Yes, JVM implementation varies for different platforms |
Usage | Required for both development and execution of Java programs | Only required for executing Java programs | Only required for executing Java programs |
Example | JDK 17 | JRE 17 | JVM (HotSpot, OpenJ9, etc.) |
There are two ways to download Java for Mac:
Here are the steps to download JDK 17 from the Oracle website:
(Using javac -version)
(Java Version)
/usr/libexec/java_home -v{YOUR_VERSION}
(We must replace ‘YOUR_VERSION’ with the version number of your JDK installation. For example, if you are using JDK 17.0.7, the command would be:
/usr/libexec/java_home -v17
(Visual Studio)
We must first create a new file from VS and name it .bash_profile. Once we have opened the file, we have to use the following command:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-{YOUR_VERSION}.jdk/Contents/Home
(For example, if you have JDK 18.0.1.1, it will be …/jdk-18.0.1.1.jdk/…)
( You can also use the code ~/. Bash_profile command if you are using the terminal)
We now have to refresh our environment file by using this command:
source ~/.bash_profile
And then, we finally And echo the JAVA_HOME variable with this command:
echo $JAVA_HOME
Using Homebrew is another way we can install Java on macOS. Let us explore how to install OpenJDK on macOS using the terminal via Homebrew.
Homebrew is a popular package manager for macOS. It lets you easily install and manage software packages from the command line. To install Homebrew, open Terminal and enter the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
You will be asked for your password and then you will be asked to press return/enter to confirm the installation of the homebrew files.
The directories will start getting created and the Command Line Tools for Xcode will get installed.
The downloading and installation process will take a bit of time and thus we have to be patient. Once the installation is done, Homebrew is ready to be used.
In order to install OpenJDK, we must now use this command:
brew install openjdk@11
You will get this error message if you already have OpenJDK installed, otherwise, OpenJDK will be installed in your system and you can finally verify the installation with “java -version”.
To change the path of Java in your system, you need to open the Bash profile. The Bash profile is a script that runs every time you start a new Terminal session. Here is the command for opening the Bash profile in Terminal:
nano ~/.bash_profile
(This command will open the Bash profile in the Nano text editor.)
Then, we add the following line to set the Java path in the Nano editor:
export JAVA_HOME="/usr/local/opt/openjdk@17"
This line sets the JAVA_HOME environment variable to the path where OpenJDK is installed. Replace 17 with the appropriate Java version number if you installed a different version.
Finally, after adding the line, press Ctrl + X to exit Nano. It will prompt you to save the changes, so press Y and Enter to save the file.
Once we are done with the setup, we must refresh the bash profile. To apply the changes, run the following command in Terminal:
source ~/.bash_profile
We have now successfully set/changed the Java path on macOS.
To install IntelliJ IDEA, we can follow these steps:
To install Eclipse, we can follow these steps:
To write the first program on Mac, we must first use a text editor or a code editor to write a Java program.
Here is a simple Java program for displaying the sentence “upGrad teaches programming.”:
public class upGradTutorials {
public static void main(String[] args) {
System.out.println("upGrad teaches programming.");
}
}
We then save the file as upGradTutorials.java in our target directory.
Finally, we open the terminal and navigate to the directory where you saved the file using the cd command. We can then compile the Java program by using the command javac upGradTutorials.java. Once the compilation is successful, execute the program with the command java upGradTutorials.
You should see the output "upGrad teaches programming." displayed in the Terminal.
Setting up Java Home and IDE on macOS is fairly simple. This tutorial has very clearly elaborated on the process of installation. Mastering Java will be easier with the help of a certified course. If you want to be a software developer, you could up courses with credible learning platforms such as upGrad. The courses on upGrad are designed to make you ready for the industry. Visit upGrad to learn more.
1. Can I have more than one version of Java installed on my Mac?
Yes, you can have more than one version of Java installed on your Mac. However, you must set the desired version as the default Java version. This has to be explicitly specified in your development environment.
2. Can I set the default Java version on my Mac?
You can use the “java_home” command to set the default Java version. Open the Terminal application. Run the command: “export JAVA_HOME=$(/usr/libexec/java_home)”. This sets the default Java version to the latest installed version.
3. Can I uninstall older versions of Java from my Mac?
Yes, you can uninstall older versions of Java from your Mac if required. Go to the "Applications" folder. Look for folders or files related to older Java versions. Move them to the Trash. Additionally, you can use the "Java Preferences" utility (located in the Utilities folder) to manage and uninstall Java versions.
PAVAN VADAPALLI
Director of Engineering
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working …Read More
Popular
Talk to our experts. We’re available 24/7.
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enrolling. upGrad does not make any representations regarding the recognition or equivalence of the credits or credentials awarded, unless otherwise expressly stated. Success depends on individual qualifications, experience, and efforts in seeking employment.
upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enr...