Once you write a Java program you need to compile it using the javac command, this shows you the compile time errors occurred (if any).Once you resolve them and compile your program success fully, an executable file with the same name as your class name is generated in your current folder, with the .class extension.Then you need to execute it using the java command as −java class_nameWhile executing, when JVM does not find a .class file with the specified name then a run time error occurs saying “Could not found or load main class” error as −D:\sample>java Example Error: Could ... Read More
The split() method of the String class. splits the current string around matches of the given regular expression. The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string.The replaceAll() method of the String class accepts two strings representing a regular expression and a replacement String and replaces the matched values with given String.To replace all the characters in of a file with '#' except a particular word (one way) −Read the contents of a file to a String.Create ... Read More
The java.text package provides a class named SimpleDateFormat which is used to format and parse dates in required manner (local).One of the constructors of this class accepts a String value representing the desired date format and constructors SimpleDateFormat object.The format() method of this class accepts a java.util.Date object and returns a date/time string in the format represented by the current object.Therefore, to parse a date String to another date format −Get the input date string.Convert it into java.util.Date object.Instantiate the SimpleDateFormat class by passing the desired (new) format as string to its constructor.Invoke the format() method by passing the above ... Read More
Using regular expressionYou can find whether a particular String value contains ASCII characters using the following regular expression −\A\p{ASCII}*\zThe matches() method of the String class accepts a regular expression and verifies whether the current string matches the given expression if so, it returns true, else it returns false.Therefore, Invoke the matches() method on the input/required string by passing the above specified regular expression as a parameter.Example Live Demoimport java.util.Scanner; public class OnlyASCII { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string value: "); String input ... Read More
You can initialize the array variable which is declared inside the class just like any other value, either using constructor or, using the setter method.ExampleIn the following Java example, we are declaring an instance variable of array type and initializing it from the constructor. Live Demopublic class Student { String name; int age; String subs[]; Student(String name, int age, String subs[]){ this.name = name; this.age = age; this.subs = subs; } public void display() { System.out.println("Name: "+this.name); System.out.println("Age :"+this.age); System.out.print("Subjects: "); for(int i = 0; i < subs.length; i++) { ... Read More
The IP address range 127.0.0.0 – 127.255.255.255 is reserved for loopback. Loopback IP address is managed entirely by and within the operating system. These addresses enable the Server and Client processes on a single system to communicate with each other. When a process creates a packet with destination address as loopback address, the operating system loops it back to itself without having any interference of NIC.Data sent on loopback is forwarded by the operating system to a virtual network interface within operating system. This address is mostly used for testing purposes like client-server architecture on a single machine.For example, if ... Read More
Context Switching involves storing the context or state of a process or thread so that it can be reloaded when required and execution can beresumed from the same point as earlier. This is a feature of a multitasking operating system and allows a single CPU to be shared by multiple processes.A process switch or process scheduling is to changing one process from another by saving all of the state of the currently executing process, including its register state, associated kernel state, and all of its virtual memory configuration.A thread switch means switching from one thread to another thread within a ... Read More
In Linux, Top command is utilized to monitor Linux Process which is used frequently used by many systems. It is available under many Linux, Unix like operating system. All the running and active real-time processes in ordered list is displayed and updates it regularly by this Top command. display CPU usage, Swap memory, Cache Size, Buffer Size,Process PID, User, Commands and much more. It shows high memory and CPU utilization of running processes in your machine.The following command to monitor Linux Process is typed and it should access root permission.#topThe output should be like this –
Init is the parent of all processes, executed by the kernel during the booting of a system. Its principle role is to create processes from a script stored in the file /etc/inittab. It usually has entries which cause init to spawn gettys on each line that users can log in. It controls autonomous processes required by any particular system.After reading this file, how the system should be set up in each runlevel is determined by init and also set default runlevel. Init starts all background process after setting default runlevel for the system.RunlevelsRunlevel, a software configuration of the system which allows ... Read More
Pipes were meant for communication between related processes. We Cannot use pipes for unrelated process communication. Then to achieve unrelated processes communication, the simple answer is Named Pipes. Even though this works for related processes, it gives no meaning to use the named pipes for related process communication.Unlike pipe, we can use single named pipe that can be used for two-way communication (communication between the server and the client, plus the client and the server at the same time) as Named Pipe supports bi-directional communication.Another name for named pipe is FIFO (First-In-First-Out). Let us see the system call (mknod()) to ... Read More