#include <iostream>
using namespace std;
int main()
{
string name = "";
cout << "enter your name: ";
getline(cin, name);
if (name.empty())
{
cout << "You should enter something ";
}
cout << "hello, " <<name << " you are user " <<endl;
return 0;
piątek, 13 grudnia 2013
poniedziałek, 9 grudnia 2013
change fedora keymap
$ localectl status
To list available keymaps:
$ localectl list-keymaps
To set the default console keymap:
$ localectl set-keymap [keymap]
see man localectl for further information.
if you still don't have your keys try to:
setxkbmap -print -verbose 10
┌─[marek@localhost]─[~]
└──╼ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules: evdev
model: pc104
layout: us,pl
variant: ,
Trying to build keymap using the following components:
keycodes: evdev+aliases(qwerty)
types: complete
compat: complete
symbols: pc+us+pl:2+inet(evdev)
geometry: pc(pc104)
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+pl:2+inet(evdev)" };
xkb_geometry { include "pc(pc104)" };
};
To list available keymaps:
$ localectl list-keymaps
To set the default console keymap:
$ localectl set-keymap [keymap]
see man localectl for further information.
if you still don't have your keys try to:
setxkbmap -print -verbose 10
┌─[marek@localhost]─[~]
└──╼ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules: evdev
model: pc104
layout: us,pl
variant: ,
Trying to build keymap using the following components:
keycodes: evdev+aliases(qwerty)
types: complete
compat: complete
symbols: pc+us+pl:2+inet(evdev)
geometry: pc(pc104)
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+pl:2+inet(evdev)" };
xkb_geometry { include "pc(pc104)" };
};
to change marked settings:
setxkbmap -layout xkb_layout
setxkbmap -model pc104 -layout cz,us -variant ,dvorak -option grp:alt_shift_toggle
czwartek, 5 grudnia 2013
Java scanner IO
import java.util.Scanner;
class helloworld
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter name: ");
String name = input.nextLine();
System.out.println("Hello " +name);
}
}
class helloworld
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter name: ");
String name = input.nextLine();
System.out.println("Hello " +name);
}
}
wtorek, 3 grudnia 2013
how to check db version - sql request JAVA
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class dbConnection {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/mysql";
String user = "user";
String password = "password";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(dbConnection.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(dbConnection.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
}
remember about your jdbc driver:
mariadb-java-client-1.1.5.jar
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public class dbConnection {
public static void main(String[] args) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/mysql";
String user = "user";
String password = "password";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
if (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(dbConnection.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(dbConnection.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
}
}
remember about your jdbc driver:
mariadb-java-client-1.1.5.jar
IO - Java
Read from file:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class fil{
public static void main(String[] args) throws FileNotFoundException{
File file = new File("/home/marek/workspace/java/myfile.txt");
System.out.print("Reading from file: " + file);
Scanner in = new Scanner(file);
String zdanie = in.nextLine();
System.out.println("\n: -> " + zdanie);
}
write to file:
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class save_to_file {
public static void main(String[] args) throws FileNotFoundException{
PrintWriter zapis = new PrintWriter("test.dat");
zapis.println("Marek Borkowski\n");
zapis.close();
System.out.println("success");
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class fil{
public static void main(String[] args) throws FileNotFoundException{
File file = new File("/home/marek/workspace/java/myfile.txt");
System.out.print("Reading from file: " + file);
Scanner in = new Scanner(file);
String zdanie = in.nextLine();
System.out.println("\n: -> " + zdanie);
}
write to file:
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class save_to_file {
public static void main(String[] args) throws FileNotFoundException{
PrintWriter zapis = new PrintWriter("test.dat");
zapis.println("Marek Borkowski\n");
zapis.close();
System.out.println("success");
}
}
poniedziałek, 2 grudnia 2013
how to make jar
1. create manifest file - the name of the file should end with do .mf sufix
Manifest-Version: 1.0
Main-Class: hello
2. jar cmf manifest.mf hello.jar hello.class
3. to view the content of the JAR type:
jar tf jar_file.jar jar_file.class
4. to execute app:
java -jar jar_file.jar
Manifest-Version: 1.0
Main-Class: hello
2. jar cmf manifest.mf hello.jar hello.class
3. to view the content of the JAR type:
jar tf jar_file.jar jar_file.class
4. to execute app:
java -jar jar_file.jar
Subskrybuj:
Posty (Atom)