import java.io.*;
import java.net.*;
import java.util.*;
public class Time_Server_Socket_Test_Java {
public static void main(String[] args) {
try {
Socket s = new Socket(HOST, PORT);//use your own HOST:PORT
try {
InputStream inStream = s.getInputStream();
Scanner in = new Scanner(inStream);
while (in.hasNextLine()) {
String line = in.nextLine();
System.out.println(line);
}
} finally {
s.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
java socket connect read string
How to serialize variables selectively
->Make variables as 'transient' which are not to be serialized.
maximize a JFrame window in java
JFrame myFrame = new JFrame();
myFrame.setVisible(true);
myFrame.setExtendedState(myFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
The usage of Java packages.
Java packages act as a logical folder structure for your source code—
java.lang, java.util, or a custom com.mycompany.util. They group related classes and sub-packages, making a large project modular and easy to navigate. Crucially, they provide a unique namespace that prevents naming conflicts: you can have your own Date class without clashing with java.util.Date because each sits in a different package. Java: difference between private, protected, and public?
Public: accessible to all classes
Private: accessible only to the class to which they belong
Protected: accessible to the class to which they belong and any subclasses.
Access specifiers are keywords that determines the type of access to the member of a class. These are:
* Public
* Protected
* Private
* Defaults
java show window JFrame JDialog always on top
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Always_on_Top_JFrame_JAVA{
public static void main(String[] args) {
JFrame frame = new JFrame("Title - always on top :D ");
// Set's the window to be "always on top"
frame.setAlwaysOnTop( true );
frame.setLocationByPlatform( true );
frame.add( new JLabel(" Always on TOP ") );
frame.pack();
frame.setVisible( true );
}
}
Order of catching exception in java
A. Yes, it does. The FileNotFoundException is inherited from the IOException.
wrapper classes in Java
Wrapper Classes in Java – What Every Developer Should Know
A wrapper class is a reference type that encapsulates a primitive value in an object. The Java standard library provides a dedicated wrapper for each of the eight primitive data types, as well as one for void. These classes reside in the java.lang package and are designed to bridge the gap between primitives and objects, enabling you to store primitive values in collections, work with generics, and use a wealth of utility methods for parsing, comparison, and conversion. Since Java 5, autoboxing and unboxing allow you to seamlessly convert between a primitive and its corresponding wrapper without explicit calls to valueOf() or xxxValue(), making the code cleaner while still relying on the underlying wrapper machinery.
The table below lists every primitive type alongside its immutable wrapper counterpart. Immutability means once a wrapper instance is created, its value cannot change – a critical property when using them as keys in maps or as elements in thread‑safe contexts. Common operations like conversion from a String (Integer.parseInt()), obtaining a wrapper instance (Boolean.valueOf(true)), and extracting the primitive (double d = dObj.doubleValue()) are all defined directly on these classes.
Java Class as Applet as well as Application
A. Yes. Add a main() method to the applet.
Bring JFrame JDialog Window to front java swing
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
//myFrame is object of Window or JFrame
public void run() {
myFrame.toFront();
myFrame.repaint();
}
});
