header

For BE/B.Tech/BCA/MCA/ME/M.Tech Major/Minor Project for CS/IT branch at minimum price Text Message @ 9424820157

First Java Program

 First Java Program




After setting the path of java, we all set to write our first java program.

It's a very basic program for printing messages on the console.

public class Demo { 

 public static void main(String[] args) {
  System.out.println("Hello Himanshu");
 }
}


Output :
Hello Himanshu


before going to the description of the program, first, we will see how we execute this program and see the output in the console.

1) Make a folder "firstprogram" in any drive let it be E drive on your computer.

2) Open notepad in that folder and copy the above program in it.

3) Go to 'file', select 'Save As...' then select 'Save as type' as All Files, then give file name same that of the class name i.e., Demo.java, and save it. It will create a java file.

4) Now open command prompt and go to E drive, for this just write E: and press enter

5)Now go to the folder by writing cd<space> E:\firstprogram and press enter.

6) Now write javac<space>Demo.java and press enter, it will create Demo.class file in the same folder. It is basically the compiled file created by the java compiler.

7) Now write java<space>Demo and press enter.this will run the java interpreter for decoding and executing the .class file for JVM.

it will generate the required output:-  Hello Himanshu

Description of above program


first of all, to write any java program we need to define a class. the class can be defined by using the class keyword as prefix followed by class name. a 'public' access modifier should be used before the class keyword which defines the accessibility of the class. we will discuss access modifiers in our later tutorials.

Moving to the second line, main() is required for the execution of the program.in it, the public keyword is defined as the accessibility of this method. static is a keyword that denotes the memory will be allotted only once when class loads, basically static keyword deals with memory management. void is the return type of main().it must be void and we have to pass string arguments in the method.
in syntax, we can also write static public instead of public static but in the standard way, we should write public static.

Now moving towards the third line, System is a built-in class in java, and out is a member of System class of type PrintStream.println() is a method in PrintStream class that prints data on the console.

it accepts expressions as arguments and prints on the console.

Lets have another java program for printing numbers 1 to 5 :


public class PrintNumbers {
 public static void main(String[] args) {
  System.out.println(1);
  System.out.println(2);
  System.out.println(3);
  System.out.println(4);
  System.out.println(5);
 }
}

Output : 
1
2
3
4
5


Here is another program for printing some integer, string, and character data :

public class PrintData {


 public static void main(String[] args) {
 
  int  i =1;
  String  str ="himanshu";
  char c ='x';
 
 
  System.out.println(i);
  System.out.println(str);
  System.out.println(c);
 }

}

Output :
1
himanshu
x

Here is a program for printing special characters in the form of string :


public class PrintSpecialChar {


 public static void main(String[] args) {
  
   System.out.println("#!m@n$#u");
 }

}

Output :
#!m@n$#u

No comments:

Post a Comment



Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER