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
Now Reading
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
Java is a prominent general-purpose programming language that is used in developing mobile and desktop applications, web applications, big data processing, server-side technologies, cloud computing, etc. This advanced language is fast, secure, and reliable so it is widely used, and popular among developers. Java provides a large set of libraries that are used to create graphical user interfaces (GUI) in a platform-independent way. Java Swing is a lightweight and platform-independent class that belongs to the Java foundation class. It is used in developing the graphical user interface for Java class. It includes some improved features to enhance the look and functionality of GUI. Swing supports model/view design architecture. It offers powerful components like tables, lists, scroll panes, color chooser, tabbed-pane, etc.
Initially, a brief idea about Java and Swing is presented. After that complete information about swing is explained which covers various topics including AWT, swing, Java foundation class, the hierarchy of Java Swing Classes, commonly used methods of component, features of swing class, swing classes hierarchy, the MVC connection, etc. Different types of examples are explained to give a clear idea about Java swing, swing by association inside the constructor, swing by inheritance, etc.
1. The Abstract Window Toolkit (AWT) is an application programming interface that supports a graphical user interface (GUI) or window-based applications in Java. Swing belongs to the Java foundation class library and it is also an extension of AWT. Swing is used to develop Java-based front-end GUI applications.
2. Swing supports much more improved functionality than AWT. It supports new components, expanded component features, and exceptional event-handling features which include drag-and-drop support.
3. Components of AWT are heavily weighted whereas components of AWT are light-weighted.
4. AWT is platform-dependent and swing is platform-independent.
5. Swing has much more advanced components whereas the components of AWT are not that much advanced.
6. Execution speed of the swing is faster and the execution speed of the AWT is not much faster.
7. Swing supports a pluggable look and feel whereas AWT does not support it.
8. Swing supports MVC patterns.
9. Java Swing Components require more memory space whereas components of AWT don't require much memory space..
JFC stands for Java Foundation Classes. JFC supports a wide range of GUI components and services. This makes the development and deployment of desktop and internet applications easier. JFC supports swing, cut and paste, accessibility features, desktop color features, JAVA- 2D, etc. Java swing tutorial is a segment of JFC that is used in developing window-based applications.
The hierarchy of the Java swing w3schools begins with the component class. Different types of user interface elements such as buttons, levels, and text fields are derived from the Java swing class.
Some methods of a component class are listed below.
1. public void add(Component c): This method is used to add two components.
2. public void setSize(int width,int height): This method is used to assign the size of a component. This method sets the width and height of the component.
3. public void setLayout(LayoutManager m): This method is used to assign the layout manager.
4. public void setVisible(boolean b): This method sets the visibility of the component.
Example: A simple Java swing program
import javax.swing.*;
public class SwingExample
{
public static void main(String[] args)
{
JFrame f=new JFrame();
JButton b=new JButton("click");
b.setBounds(120,50,50, 40);
f.add(b);
f.setSize(200,300);
f.setLayout(null);
f.setVisible(true);
}
}
Explanation:
1. JFrame and JButton are created.
2. Values of all the bounds such as x-axis, y-axis, width, and height are set.
3. JButton is added in JFrame.
4. The class JButton creates a labeled button with platform-independent implementation. It is used for the implementation of a push button.
JFrame provides a frame in the specific graphics configuration of the screen
Example: A program to create three buttons with captions PAST, PRESENT, and FUTURE.
import java.awt.*;
class button
{
button()
{
Frame f = new Frame();
Button b1 = new Button("PAST");
b1.setBounds(110, 75, 75, 60);
f.add(b1);
Button b2 = new Button("PRESENT");
b2.setBounds(110, 120, 40, 80);
f.add(b2);
Button b3 = new Button("FUTURE");
b3.setBounds(110, 120, 60, 40);
f.add(b3);
f.setSize(250, 250);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String a[])
{
new button();
}
}
Example : A program to create three buttons with captions ODISHA, CHHATTISGARH, BIHAR
import java.awt.*;
class Lan {
Lan() {
Frame f = new Frame();
Label l1 = new Label("Select your state");
l1.setBounds(110, 60, 140, 100);
f.add(l1);
Checkbox c2 = new Checkbox("ODISHA");
c2.setBounds(110, 100, 80, 80);
f.add(c2);
Checkbox c3 = new Checkbox("CHHATTISGARH");
c3.setBounds(100, 120, 70, 50);
f.add(c3);
Checkbox c4 = new Checkbox("BIHAR");
c4.setBounds(120, 150, 60, 80);
f.add(c4);
f.setSize(250, 250);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String ar[]) {
new Lan();
}
}
Example: Create a program using Java constructor
import javax.swing.*;
public class Simple
{
JFrame f;
Simple()
{
f=new JFrame();
JButton b=new JButton("click");
b.setBounds(120,110,100, 50);
f.add(b);
f.setSize(300,500);//300 width and 500 height
f.setLayout(null);//using no layout managers
f.setVisible(true);//making the frame visible
}
public static void main(String[] args) {
new Simple();
}
}
Example : Create a program using inheritance
import javax.swing.*;
public class Simple2 extends JFrame
{
JFrame g;
Simple2()
{
JButton c=new JButton("click");
c.setBounds(120,100,110, 50);
add(c);
setSize(200,300);
setLayout(null);
setVisible(true);
}
public static void main(String[] args)
{
new Simple2();
}
}
1. Lightweight components: A swing component is known as a lightweight component as it is completely written in Java. It can do the high-level display work itself. It does not rely on any non java system classes or code provided by the operating system. The components have their specific view supported by Java’s look and feel classes.
2. Pluggable look and feel: Here Look means the appearance of GUI widgets and feel denotes the way the widgets perform. The pluggable look and feel feature is a mechanism that permits the change of the look and feel of the GUI at runtime. Wherever the program runs this feature allows the components’ look and feel to remain the same. This offers flexibility in choosing the look and feel of the GUI of an application.
3. Highly customizable: The visual appearance does not depend upon the internal presentation. So, the swing controls can be easily customized.
4. Rich controls: Developed controls like Tree tabbedpane, slider, colorpicker, and table controls are provided.
The MVC Connection
The model view controller (MVC) is a prominent design pattern that is used in the web development world. This method is used to organize the code. Three logical components of MVC are the model, the view, and the controller. Every component handles certain development aspects of a robust structure for web applications. MVC states that a program or application must consist of three features. The 'model' term signifies state information linked to the component including all the data and related logic, the terminology 'view' indicates the look of the component on the screen and it also handles user interaction, and the 'controller' term shows, how the component reacts to the user or, this is an interface between model and view components.
Initially, a brief description is given related to Java and Swing. Then a clear idea about the difference between AWT and swing is presented. Next Java Foundation Class is defined. After that, a figure is presented which describes the hierarchy of Java swing documentation. Some commonly used methods of components are explained which include public void add(Component c), public void setSize(int width,int height), public void setLayout(LayoutManager m), and public void setVisible(boolean b). Some basic programs related to Java Swing intellij are provided to give a clear idea about Java Swing.
1. What is Java?
Java is a prominent general-purpose programming language that is used in developing mobile and desktop applications, web applications, big data processing, server-side technologies, cloud computing, etc.
2. What is Java Swing?
Java Swing is a lightweight and platform-independent class that belongs to the Java foundation class. It is used in developing the graphical user interface for Java class. It includes some improved features to enhance the look and functionality of GUI.
3. What is AWT?
The Abstract Window Toolkit (AWT) is an application programming interface that supports a graphical user interface (GUI) or window-based applications in Java.
4. What is the difference between Java and Swing?
Swing belongs to the Java foundation class library and it is also an extension of AWT. Swing is used to develop Java-based front-end GUI applications. Swing supports much more improved functionality than AWT. It supports new components, expanded component features, and exceptional event-handling features.
5. What Is JFC?
JFC stands for Java Foundation Classes. JFC supports a wide range of GUI components and services. This makes the development and deployment of desktop and internet applications easier.
6. What are the features of the swing class?
The features of the swing class include lightweight components, a pluggable look and feel, highly customizable, rich control.
7. What is MVC?
The model view controller (MVC) is a prominent design pattern that is used in the web development world. This method is used to organize the code.
8. What is javax.swing?
javax.swing contains a set of lightweight components such as JButtons, JtextField etc.
9. What is JButton?
The class JButton creates a labeled button with platform-independent implementation. It is used for implementation of push buttons.
10. What is JFrame?
It provides a frame in the specific graphics configuration of the screen.
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...