Skip to main content

Posts

Simple Java program to print "Hello World"

Let us write a simple Java program to print "Hello World". /* * HelloWorld.java - simple java program to print "Hello World" */ public class HelloWorld { public static void main(String args[]) { // print "Hello World" System.out.println("Hello World"); } } Above is the simple Java program which would print "Hello World" on execution.  While saving the Java program, please make sure that the file has .java extension and the name of the file matches with the name of the class that has main() function.  We have stored the above source code in HelloWorld.java and the file names matches exactly with the name of the class in which main() function resides. Let us compile the above Java program.  Basically, Java compiler would take Java source code as input and provide us bytecode version of the input Java program as output.  As a result of compiling HelloWorld.java, we will get a class file named HelloWorld.class which contains byte...
Recent posts

How to install JDK and setting environment variables for java

In this tutorial, we are going to see the following. How to install JDK How to run java program without setting java path How to set temporary java path in windows How to set permanent java path in windows How to install JDK? Check whether JDK is installed on your PC.  If it is not installed, please go to the below link and download JDK under Java SE(Java Standard Edition) in oracle website . Install the downloaded JDK in your PC. Once JDK is installed, you can run your java program using any method shown below. Having your java source code under jdk/bin, compile the source code and run the program from same directory Setting temporary path for java, compiling the source code and running the program from any location using command prompt Updating the java path in system or user variable(in system properties), compiling the source code and running the program anywhere using command prompt Let us see how to run java program without setting environmental variables.  Once java is ...

Introduction to Java

Here, we are going to see few key points on Java programming language and the difference between JDK, JRE and JVM. Java is a high level programming language which can be used to create standalone, web, mobile or enterprise applications. It was developed by James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan at Sun Microsystems. It was initially named as Oak.  In 1995, Oak was renamed as Java. Java programming language helps us to create applications that can be run on multiple platforms without having to port the code and recompile.  In a nutshell, Java is a portable language. Java is object oriented as it helps us to correlate real world object or examples to java programs It is known for its robustness as it avoid drawbacks in other programming languages like pointer arithmetic or memory management etc. It allows us to create multi-threaded applications where each thread can do separate task. Java was initially owned by Sun Microsystems.  In 2010, ...

Save image in Microsoft Paint without white background

Here, we are going to see how to save image in mspaint without white background 1. Create your own drawing or painting 2. Crop the needed portion of your drawing or painting or image. Here, I am going to crop the porting inside the red box. Now, we have cropped the portion that needs to be saved as an image. 5. Clear the screen and paste the image which we cropped earlier. 6. Decrease the screen size by 50% 7. Now, adjust your screen to fit to your image size. 8. Save the image to desired file format(jpeg, png, bmp etc) 9. Go to the saved location and open the file.  Below is the output image of mine Hope you liked this article!!  For any suggestions, please comment below.

LINUX cal command examples

cal utility is used to display calendar of any specific month or year.  Below are few examples for linux cal command usage. Display calendar of any specific year Display calendar of current month Display calendar of any specific month in current year Display calendar of any specific month in any specific year Display Julian calendar of current year Display Julian calendar of any specific year Display Julian calendar of any specific month Display Julian calendar of any specific month in any specific year Display calendar without high lighting current date Display previous, current and next month calendar highlighting current date Display previous, current and next month calendar without highlighting current date Display previous, current and next month in Julian calendar highlighting current date Display previous, current and next month in Julian calendar without highlighting current date Display calendar of given month in following year Display calendar of given month in previous y...

Operator precedence and associativity in C language

Below is the table for operator precedence and associativity in C programming language. [ ] ( ) . -> ++ -- Array subscript Function Call Structure reference Structure dereference Postfix increment/Postfix decrement Left to right ++ -- + - ! ~ (type) *  & sizeof Prefix increment/Prefix decrement Unary plus/Unary minus Logical negation/One's complement Typecast operator Pointer dereference/Address of Size of type/variable in bytes Right to left *  /  % Multiplication/Division/Modulo Left to Right + - Addition/Subtraction Left to Right <<   >> Bitwise left shift/ Bitwise right shift Left to Right <    > <= >= Comparison less than/Comparision greater than Comparison less than or equal to Comparison greater than or equal to Left to Right ==   != Comparison equal to/Comparison not equal to Left to Right & Bitwise AND Left to Right ^ Bitwise XOR Left to Right | Bitwise OR Left to Right && ...

#ifdef, #ifndef and #endif directives in C

#ifdef If the named macro is defined, then the code between #ifdef and #endif will be compiled. #ifndef If the named macro is not defined, then the code between #ifndef and #endif will be compiled. #ifdef, #ifndef and #endif example in C #include <stdio.h> #define NAME "Raj" int main() { #ifdef NAME printf("#ifdef: Value of NAME is %s\n", NAME); #endif #ifndef VAL printf("#ifndef: macro VAL is not defined\n"); #endif return 0; }   Output:   jp@jp-VirtualBox:~/$ ./a.out   #ifdef: Value of NAME is Raj   #ifndef: macro VAL is not defined In the above program, macro NAME is defined.  So, the code between #ifdef and #endif is executed. Similarly, the code between #ifndef and #endif is executed as the macro VAL is not defined. Previous Next